fix #9539 (Syntax error for valid C++14 code) (#2446)

This commit is contained in:
IOBYTE 2019-12-12 14:50:20 -05:00 committed by amai2012
parent eb6203cee3
commit 0e4efea530
3 changed files with 31 additions and 9 deletions

View File

@ -824,7 +824,7 @@ void TemplateSimplifier::getTemplateInstantiations()
Token *tok2 = Token::findsimplematch(tok->tokAt(2), ";");
if (tok2)
tok = tok2;
} else if (Token::Match(tok->previous(), "(|{|}|;|=|>|<<|:|.|*|&|return|<|,|! %name% ::|<|(") ||
} else if (Token::Match(tok->previous(), "(|{|}|;|=|>|<<|:|.|*|&|return|<|,|!|[ %name% ::|<|(") ||
Token::Match(tok->previous(), "%type% %name% ::|<") ||
Token::Match(tok->tokAt(-2), "[,:] private|protected|public %name% ::|<")) {
std::string scopeName = tok->scopeInfo()->name;

View File

@ -9347,7 +9347,7 @@ void Tokenizer::findGarbageCode() const
prev = prev->previous();
if (Token::Match(prev, "%op%|%num%|%str%|%char%")) {
if (!Token::simpleMatch(tok->tokAt(-2), "operator \"\" if") &&
!Token::simpleMatch(tok->tokAt(-2), "extern \"C\"") )
!Token::simpleMatch(tok->tokAt(-2), "extern \"C\""))
syntaxError(tok, prev == tok->previous() ? (prev->str() + " " + tok->str()) : (prev->str() + " .. " + tok->str()));
}
}
@ -9448,7 +9448,7 @@ void Tokenizer::findGarbageCode() const
syntaxError(tok);
if (Token::Match(tok, ";|(|[ %comp%"))
syntaxError(tok);
if (Token::Match(tok, "%cop%|= ]") && !(isCPP() && Token::Match(tok->previous(), "[|, &|= ]")))
if (Token::Match(tok, "%cop%|= ]") && !(isCPP() && Token::Match(tok->previous(), "[|,|%num% &|=|> ]")))
syntaxError(tok);
if (Token::Match(tok, "[+-] [;,)]}]") && !(isCPP() && Token::Match(tok->previous(), "operator [+-] ;")))
syntaxError(tok);

View File

@ -192,6 +192,7 @@ private:
TEST_CASE(template152); // #9467
TEST_CASE(template153); // #9483
TEST_CASE(template154); // #9495
TEST_CASE(template155); // #9539
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
@ -2799,12 +2800,6 @@ private:
ASSERT_EQUALS(exp, tok(code));
}
void template154() { // #9495
const char code[] = "template <typename S, enable_if_t<(is_compile_string<S>::value), int>> void i(S s);";
const char exp[] = "template < typename S , enable_if_t < ( is_compile_string < S > :: value ) , int > > void i ( S s ) ;";
ASSERT_EQUALS(exp, tok(code));
}
void template116() { // #9178
{
const char code[] = "template <class, class a> auto b() -> decltype(a{}.template b<void(int, int)>);\n"
@ -3666,6 +3661,33 @@ private:
ASSERT_EQUALS(exp, tok(code));
}
void template154() { // #9495
const char code[] = "template <typename S, enable_if_t<(is_compile_string<S>::value), int>> void i(S s);";
const char exp[] = "template < typename S , enable_if_t < ( is_compile_string < S > :: value ) , int > > void i ( S s ) ;";
ASSERT_EQUALS(exp, tok(code));
}
void template155() { // #9539
const char code[] = "template <int> int a = 0;\n"
"struct b {\n"
" void operator[](int);\n"
"};\n"
"void c() {\n"
" b d;\n"
" d[a<0>];\n"
"}";
const char exp[] = "int a<0> ; "
"a<0> = 0 ; "
"struct b { "
"void operator[] ( int ) ; "
"} ; "
"void c ( ) { "
"b d ; "
"d [ a<0> ] ; "
"}";
ASSERT_EQUALS(exp, tok(code));
}
void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
const char code[] = "template <typename T> struct C {};\n"
"template <typename T> struct S {a};\n"