Skip to content

Commit

Permalink
Fixed #254: Show MemberExpr template parameters as comment.
Browse files Browse the repository at this point in the history
Due to another issue (#255) the result of this issue does not compile.
This will be fixed with #255.
  • Loading branch information
andreasfertig committed Nov 12, 2019
1 parent a322252 commit 4eca8c3
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 16 deletions.
5 changes: 4 additions & 1 deletion CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ void CodeGenerator::InsertArg(const MemberExpr* stmt)

if(!skipTemplateArgs) {
if(const auto cxxMethod = dyn_cast_or_null<CXXMethodDecl>(meDecl)) {
if(const auto* tmplArgs = cxxMethod->getAsFunction()->getTemplateSpecializationArgs()) {
if(const auto* tmplArgs = cxxMethod->getTemplateSpecializationArgs()) {
OutputFormatHelper ofm{};

ofm.Append('<');
Expand All @@ -543,6 +543,9 @@ void CodeGenerator::InsertArg(const MemberExpr* stmt)

if(haveArg) {
mOutputFormatHelper.Append(ofm.GetString(), ">");

} else if(cxxMethod->getAsFunction()->isFunctionTemplateSpecialization()) {
InsertTemplateArgs(tmplArgs->asArray());
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/CXXFoldExprTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class CXXFoldExprTest
int main()
{
CXXFoldExprTest cxxFoldExprTest = {};
cxxFoldExprTest.UnaryRightFold(2, 3, 4, 5);
cxxFoldExprTest.UnaryLeftFold(2, 3, 4, 5);
cxxFoldExprTest.BinaryRightFold(2, 3, 4, 5);
cxxFoldExprTest.BinaryLeftFold(2, 3, 4, 5);
cxxFoldExprTest.UnaryRightFold<int, int, int, int>(2, 3, 4, 5);
cxxFoldExprTest.UnaryLeftFold<int, int, int, int>(2, 3, 4, 5);
cxxFoldExprTest.BinaryRightFold<int, int, int, int>(2, 3, 4, 5);
cxxFoldExprTest.BinaryLeftFold<int, int, int, int>(2, 3, 4, 5);
}


6 changes: 3 additions & 3 deletions tests/Issue184.expect
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ int main()
std::unordered_set<Customer, CustomerHash, CustomerEq> set1 = std::unordered_set<Customer, CustomerHash, CustomerEq, std::allocator<Customer> >();
std::unordered_set<Customer, ManyParentsWithOperator<CustomerHash, CustomerEq>, ManyParentsWithOperator<CustomerHash, CustomerEq> > set2 = std::unordered_set<Customer, ManyParentsWithOperator<CustomerHash, CustomerEq>, ManyParentsWithOperator<CustomerHash, CustomerEq>, std::allocator<Customer> >();
std::unordered_set<Customer, ManyParentsWithOperator<CustomerEq, CustomerHash>, ManyParentsWithOperator<CustomerEq, CustomerHash> > set3 = std::unordered_set<Customer, ManyParentsWithOperator<CustomerEq, CustomerHash>, ManyParentsWithOperator<CustomerEq, CustomerHash>, std::allocator<Customer> >();
set1.emplace("Test");
set2.emplace("Test");
set3.emplace("Test");
set1.emplace<char const (&)[5]>("Test");
set2.emplace<char const (&)[5]>("Test");
set3.emplace<char const (&)[5]>("Test");
return 0;
}

15 changes: 15 additions & 0 deletions tests/Issue254.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
struct demonstrator{
template <typename return_type = double>
return_type templated_function() {
return return_type{};
}
};

int demonstrate() {
demonstrator D;
D.template templated_function<bool>();
D.template templated_function<float>();
D.template templated_function();
return 42;
}

52 changes: 52 additions & 0 deletions tests/Issue254.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
struct demonstrator
{
template<typename return_type = double>
inline return_type templated_function()
{
return return_type{{}};
}

/* First instantiated from: Issue254.cpp:10 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
inline bool templated_function<bool>()
{
return bool{};
}
#endif


/* First instantiated from: Issue254.cpp:11 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
inline float templated_function<float>()
{
return float{};
}
#endif


/* First instantiated from: Issue254.cpp:12 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
inline double templated_function<double>()
{
return double{};
}
#endif

// inline constexpr demonstrator() noexcept = default;
};



int demonstrate()
{
demonstrator D = demonstrator();
D.templated_function<bool>();
D.templated_function<float>();
D.templated_function<double>();
return 42;
}


7 changes: 7 additions & 0 deletions tests/LambdaInMemberCallExprTest.cerr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.tmp.cpp:37:5: error: no matching member function for call to 'foo'
t.foo<__lambda_13_12>(__lambda_13_12);
~~^~~~~~~~~~~~~~~~~~~
.tmp.cpp:6:15: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'T'
inline void foo(T &&)
^
1 error generated.
2 changes: 1 addition & 1 deletion tests/LambdaInMemberCallExprTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ int main()

} __lambda_13_12{};

t.foo(__lambda_13_12);
t.foo<__lambda_13_12>(__lambda_13_12);
}

4 changes: 2 additions & 2 deletions tests/MemberExprTemplateTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
public:
inline /*constexpr */ void operator()() const
{
x.f(17);
x.ff(17, 2, 55.5);
x.f<int>(17);
x.ff<int, int, double>(17, 2, 55.5);
}

private:
Expand Down
6 changes: 3 additions & 3 deletions tests/NonTypeTemplateParameterPackTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Test
inline int summ<int, int, int>(int && i, int && __rest1, int && __rest2)
{
if constexpr(2 > 0) {
return i + this->summ(__rest1, __rest2);
return i + this->summ<int &, int &>(__rest1, __rest2);
}

}
Expand All @@ -82,7 +82,7 @@ class Test
inline int summ<int &, int &>(int & i, int & rest)
{
if constexpr(1 > 0) {
return i + this->summ(rest);
return i + this->summ<int &>(rest);
}

}
Expand Down Expand Up @@ -145,7 +145,7 @@ class Test
int main()
{
Test t = Test();
t.summ(1, 2, 3);
t.summ<int, int, int>(1, 2, 3);
Test::Map<int, int> a = Map<int, int, my_array>();
return t.sum<1>();
}
Expand Down
7 changes: 7 additions & 0 deletions tests/TemplateMemberFunctionTest.cerr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.tmp.cpp:84:5: error: no matching member function for call to 'Do'
f.Do<__lambda_33_10>(__lambda_33_10);
~~^~~~~~~~~~~~~~~~~~
.tmp.cpp:9:15: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'T'
inline void Do(T && t)
^
1 error generated.
2 changes: 1 addition & 1 deletion tests/TemplateMemberFunctionTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int main()

} __lambda_33_10{};

f.Do(__lambda_33_10);
f.Do<__lambda_33_10>(__lambda_33_10);

class __lambda_35_18
{
Expand Down
2 changes: 1 addition & 1 deletion tests/TupeInRangeBasedForTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void fillTuples(std::vector<Tuple_t> tuples) {
template<>
void fillTuples<std::tuple<std::basic_string<char>, int> >(std::vector<std::tuple<std::basic_string<char>, int>, std::allocator<std::tuple<std::basic_string<char>, int> > > tuples)
{
tuples.emplace_back("hello", 1);
tuples.emplace_back<char const (&)[6], int>("hello", 1);
}
#endif

Expand Down

0 comments on commit 4eca8c3

Please sign in to comment.