Skip to content

Commit d01dca6

Browse files
Fix #14909 internalAstError with x.size() passed to template parameter (#8716)
1 parent 95a3277 commit d01dca6

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/templatesimplifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
496496
return 0;
497497

498498
// num/type ..
499-
if (!tok->isNumber() && tok->tokType() != Token::eChar && tok->tokType() != Token::eString && !tok->isName() && !tok->isOp())
499+
if (!tok->isNumber() && tok->tokType() != Token::eChar && tok->tokType() != Token::eString && !tok->isName() && !tok->isOp() && tok->str() != ".")
500500
return 0;
501501
tok = tok->next();
502502
if (!tok)

test/testtokenize.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ class TestTokenizer : public TestFixture {
241241
TEST_CASE(vardecl_stl_3);
242242
TEST_CASE(vardecl_template_1);
243243
TEST_CASE(vardecl_template_2);
244+
TEST_CASE(vardecl_template_3);
244245
TEST_CASE(vardecl_union);
245246
TEST_CASE(vardecl_par); // #2743 - set links if variable type contains parentheses
246247
TEST_CASE(vardecl_par2); // #3912 - set correct links
@@ -2394,6 +2395,19 @@ class TestTokenizer : public TestFixture {
23942395
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
23952396
}
23962397

2398+
void vardecl_template_3() {
2399+
const char code[] = "template <class T>\n" // #14909
2400+
"void f(T x) {\n"
2401+
" const auto y = h<T, x.size()>;\n"
2402+
"}";
2403+
const char expected[] = "template < class T >\n"
2404+
"void f ( T x ) {\n"
2405+
"const auto y = h < T , x . size ( ) > ;\n"
2406+
"}";
2407+
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
2408+
ASSERT_EQUALS("[test.cpp:3:11]: (debug) auto token with no type. [autoNoType]\n", errout_str());
2409+
}
2410+
23972411
void vardecl_union() {
23982412
// ticket #1976
23992413
const char code1[] = "class Fred { public: union { int a ; int b ; } ; } ;";

0 commit comments

Comments
 (0)