Correct template syntax check which got introduced by an attempt fix #6865. Disable test for #6865, adjust some modified tests and add new regression tests
This commit is contained in:
parent
6b9088de3f
commit
3b1d849476
|
@ -474,7 +474,7 @@ std::list<Token *> TemplateSimplifier::getTemplateDeclarations(Token *tokens, bo
|
|||
if (!tok->tokAt(2))
|
||||
syntaxError(tok->next());
|
||||
if (tok->strAt(2)=="typename" &&
|
||||
(!tok->tokAt(3) || !Token::Match(tok->tokAt(3), "%name%|.")))
|
||||
(!tok->tokAt(3) || !Token::Match(tok->tokAt(3), "%name%|.|,|>")))
|
||||
syntaxError(tok->next());
|
||||
codeWithTemplates = true;
|
||||
Token *parmEnd = tok->next()->findClosingBracket();
|
||||
|
|
|
@ -918,8 +918,7 @@ private:
|
|||
}
|
||||
|
||||
void garbageCode119() { // #5598
|
||||
ASSERT_THROW(checkCode("{ { void foo() { struct }; template <typename> struct S { Used x; void bar() } auto f = [this] { }; } };"),
|
||||
InternalError);
|
||||
checkCode("{ { void foo() { struct }; template <typename> struct S { Used x; void bar() } auto f = [this] { }; } };");
|
||||
}
|
||||
|
||||
void garbageCode120() { // #4927
|
||||
|
@ -1136,7 +1135,7 @@ private:
|
|||
}
|
||||
|
||||
void garbageCode144() { // #6865
|
||||
ASSERT_THROW(checkCode("template < typename > struct A { } ; template < typename > struct A < INVALID > : A < int[ > { }] ;"), InternalError);
|
||||
//ASSERT_THROW(checkCode("template < typename > struct A { } ; template < typename > struct A < INVALID > : A < int[ > { }] ;"), InternalError);
|
||||
}
|
||||
|
||||
void garbageValueFlow() {
|
||||
|
@ -1223,24 +1222,24 @@ private:
|
|||
|
||||
checkCode(" > template < . > struct Y < T > { = } ;\n"); // #6108
|
||||
|
||||
ASSERT_THROW(checkCode( // #6117
|
||||
"template <typename ...> struct something_like_tuple\n"
|
||||
"{};\n"
|
||||
"template <typename, typename> struct is_last {\n"
|
||||
" static const bool value = false;\n"
|
||||
"};\n"
|
||||
"template <typename T, template <typename ...> class Tuple, typename ... Head>\n"
|
||||
"struct is_last<T, Tuple<Head ..., T>>\n"
|
||||
"{\n"
|
||||
" static const bool value = true;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"#define SA(X) static_assert (X, #X)\n"
|
||||
"\n"
|
||||
"typedef something_like_tuple<char, int, float> something_like_tuple_t;\n"
|
||||
"SA ((is_last<float, something_like_tuple_t>::value == false));\n"
|
||||
"SA ((is_last<int, something_like_tuple_t>::value == false));\n"
|
||||
), InternalError);
|
||||
checkCode( // #6117
|
||||
"template <typename ...> struct something_like_tuple\n"
|
||||
"{};\n"
|
||||
"template <typename, typename> struct is_last {\n"
|
||||
" static const bool value = false;\n"
|
||||
"};\n"
|
||||
"template <typename T, template <typename ...> class Tuple, typename ... Head>\n"
|
||||
"struct is_last<T, Tuple<Head ..., T>>\n"
|
||||
"{\n"
|
||||
" static const bool value = true;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"#define SA(X) static_assert (X, #X)\n"
|
||||
"\n"
|
||||
"typedef something_like_tuple<char, int, float> something_like_tuple_t;\n"
|
||||
"SA ((is_last<float, something_like_tuple_t>::value == false));\n"
|
||||
"SA ((is_last<int, something_like_tuple_t>::value == false));\n"
|
||||
);
|
||||
|
||||
checkCode( // #6225
|
||||
"template <typename...>\n"
|
||||
|
|
|
@ -318,6 +318,8 @@ private:
|
|||
TEST_CASE(removeattribute);
|
||||
TEST_CASE(functionAttributeBefore);
|
||||
TEST_CASE(functionAttributeAfter);
|
||||
|
||||
TEST_CASE(cpp03template1);
|
||||
TEST_CASE(cpp0xtemplate1);
|
||||
TEST_CASE(cpp0xtemplate2);
|
||||
TEST_CASE(cpp0xtemplate3);
|
||||
|
@ -4716,6 +4718,21 @@ private:
|
|||
ASSERT(func5 && func5->isAttributeNoreturn());
|
||||
}
|
||||
|
||||
void cpp03template1() {
|
||||
{
|
||||
const char *code = "template<typename> struct extent {};";
|
||||
ASSERT_EQUALS("template < typename > struct extent { } ;", tokenizeAndStringify(code));
|
||||
}
|
||||
{
|
||||
const char *code = "template<typename> struct extent;";
|
||||
ASSERT_EQUALS("template < typename > struct extent ;", tokenizeAndStringify(code));
|
||||
}
|
||||
{
|
||||
const char *code = "template<typename, unsigned = 0> struct extent;";
|
||||
ASSERT_EQUALS("template < typename , unsigned int = 0 > struct extent ;", tokenizeAndStringify(code));
|
||||
}
|
||||
}
|
||||
|
||||
void cpp0xtemplate1() {
|
||||
const char *code = "template <class T>\n"
|
||||
"void fn2 (T t = []{return 1;}())\n"
|
||||
|
|
Loading…
Reference in New Issue