template simplifier: partial fix for instantiation of templates with type trait parameters (#1855)

This commit is contained in:
IOBYTE 2019-05-27 14:51:52 -04:00 committed by Daniel Marjamäki
parent f204ab88d6
commit e8692b012f
2 changed files with 42 additions and 19 deletions

View File

@ -364,8 +364,8 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
if (!tok) if (!tok)
return 0; return 0;
// Skip casts // Skip links
if (tok->str() == "(") { if (Token::Match(tok, "(|{")) {
tok = tok->link(); tok = tok->link();
if (tok) if (tok)
tok = tok->next(); tok = tok->next();
@ -996,9 +996,9 @@ void TemplateSimplifier::useDefaultArgumentValues(TemplateSimplifier::TokenAndNa
--indentlevel; --indentlevel;
tok->insertToken(from->str(), from->originalName()); tok->insertToken(from->str(), from->originalName());
tok = tok->next(); tok = tok->next();
if (Token::Match(tok, "(|[")) if (Token::Match(tok, "(|[|{"))
links.push(tok); links.push(tok);
else if (!links.empty() && Token::Match(tok, ")|]")) { else if (!links.empty() && Token::Match(tok, ")|]|}")) {
Token::createMutualLinks(links.top(), tok); Token::createMutualLinks(links.top(), tok);
links.pop(); links.pop();
} }

View File

@ -2545,36 +2545,59 @@ private:
"template <typename...> struct e {};\n" "template <typename...> struct e {};\n"
"static_assert(sizeof(e<>) == sizeof(e<c<int>, c<int>, int>), \"\");\n"; "static_assert(sizeof(e<>) == sizeof(e<c<int>, c<int>, int>), \"\");\n";
const char exp[] = "namespace a { " const char exp[] = "namespace a { "
"template < typename b , bool = std :: is_empty < b > { } && std :: is_final < b > { } > struct c ; " "template < typename b , bool > struct c ; "
"} " "} "
"namespace boost { " "namespace boost { "
"using a :: c ; " "using a :: c ; "
"} using boost :: c ; " "} "
"using boost :: c ; "
"struct e<> ; " "struct e<> ; "
"struct e<c<int>,c<int>,int> ; " "struct e<c<int,std::is_empty<int>{}&&std::is_final<int>{}>,c<int,std::is_empty<int>{}&&std::is_final<int>{}>,int> ; "
"static_assert ( sizeof ( e<> ) == sizeof ( e<c<int>,c<int>,int> ) , \"\" ) ; " "static_assert ( sizeof ( e<> ) == sizeof ( e<c<int,std::is_empty<int>{}&&std::is_final<int>{}>,c<int,std::is_empty<int>{}&&std::is_final<int>{}>,int> ) , \"\" ) ; "
"struct e<> { } ; " "struct e<> { } ; "
"struct e<c<int>,c<int>,int> { } ;"; "struct e<c<int,std::is_empty<int>{}&&std::is_final<int>{}>,c<int,std::is_empty<int>{}&&std::is_final<int>{}>,int> { } ;";
ASSERT_EQUALS(exp, tok(code)); const char actual[] = "namespace a { "
"template < typename b , bool > struct c ; "
"} "
"namespace boost { "
"using a :: c ; "
"} "
"using boost :: c ; "
"struct e<> ; "
"struct e<c<int,std::is_empty<b>{}&&std::is_final<b>{}>,c<int,std::is_empty<b>{}&&std::is_final<b>{}>,int> ; "
"static_assert ( sizeof ( e<> ) == sizeof ( e<c<int,std::is_empty<b>{}&&std::is_final<b>{}>,c<int,std::is_empty<b>{}&&std::is_final<b>{}>,int> ) , \"\" ) ; "
"struct e<> { } ; "
"struct e<c<int,std::is_empty<b>{}&&std::is_final<b>{}>,c<int,std::is_empty<b>{}&&std::is_final<b>{}>,int> { } ;";
TODO_ASSERT_EQUALS(exp, actual, tok(code));
} }
{ {
const char code[] = "template <typename b, bool = __is_empty(b) && __is_final(b)> struct c;\n" const char code[] = "template <typename b, bool = __is_empty(b) && __is_final(b)> struct c;\n"
"template <typename...> struct e {};\n" "template <typename...> struct e {};\n"
"static_assert(sizeof(e<>) == sizeof(e<c<int>, c<int>, int>), "");\n"; "static_assert(sizeof(e<>) == sizeof(e<c<int>, c<int>, int>), \"\");\n";
const char exp[] = "template < typename b , bool = std :: is_empty < b > { } && std :: is_final < b > { } > struct c ; " const char exp[] = "template < typename b , bool > struct c ; "
"struct e<> ; " "struct e<> ; "
"struct e<c<int>,c<int>,int> ; " "struct e<c<int,std::is_empty<int>{}&&std::is_final<int>{}>,c<int,std::is_empty<int>{}&&std::is_final<int>{}>,int> ; "
"static_assert ( sizeof ( e<> ) == sizeof ( e<c<int>,c<int>,int> ) , ) ; " "static_assert ( sizeof ( e<> ) == sizeof ( e<c<int,std::is_empty<int>{}&&std::is_final<int>{}>,c<int,std::is_empty<int>{}&&std::is_final<int>{}>,int> ) , \"\" ) ; "
"struct e<> { } ; " "struct e<> { } ; "
"struct e<c<int>,c<int>,int> { } ;"; "struct e<c<int,std::is_empty<int>{}&&std::is_final<int>{}>,c<int,std::is_empty<int>{}&&std::is_final<int>{}>,int> { } ;";
ASSERT_EQUALS(exp, tok(code)); const char actual[] = "template < typename b , bool > struct c ; "
"struct e<> ; "
"struct e<c<int,std::is_empty<b>{}&&std::is_final<b>{}>,c<int,std::is_empty<b>{}&&std::is_final<b>{}>,int> ; "
"static_assert ( sizeof ( e<> ) == sizeof ( e<c<int,std::is_empty<b>{}&&std::is_final<b>{}>,c<int,std::is_empty<b>{}&&std::is_final<b>{}>,int> ) , \"\" ) ; "
"struct e<> { } ; "
"struct e<c<int,std::is_empty<b>{}&&std::is_final<b>{}>,c<int,std::is_empty<b>{}&&std::is_final<b>{}>,int> { } ;";
TODO_ASSERT_EQUALS(exp, actual, tok(code));
} }
{ {
const char code[] = "template <typename b, bool = __is_empty(b) && __is_final(b)> struct c{};\n" const char code[] = "template <typename b, bool = __is_empty(b) && __is_final(b)> struct c{};\n"
"c<int> cc;\n"; "c<int> cc;\n";
const char exp[] = "template < typename b , bool = std :: is_empty < b > { } && std :: is_final < b > { } > struct c { } ; " const char exp[] = "struct c<int,std::is_empty<int>{}&&std::is_final<int>{}> ; "
"c < int > cc ;"; "c<int,std::is_empty<b>{}&&std::is_final<b>{}> cc ; "
ASSERT_EQUALS(exp, tok(code)); "struct c<int,std::is_empty<int>{}&&std::is_final<int>{}> { } ;";
const char actual[] = "struct c<int,std::is_empty<b>{}&&std::is_final<b>{}> ; "
"c<int,std::is_empty<b>{}&&std::is_final<b>{}> cc ; "
"struct c<int,std::is_empty<b>{}&&std::is_final<b>{}> { } ;";
TODO_ASSERT_EQUALS(exp, actual, tok(code));
} }
} }