TemplateSimplifier: Fix crash seen in Travis
This commit is contained in:
parent
2d7fedbb49
commit
d237d36d46
|
@ -1431,11 +1431,9 @@ void TemplateSimplifier::replaceTemplateUsage(Token * const instantiationToken,
|
|||
if (!Token::simpleMatch(nameTok->next(), templateParametersMatchPattern.c_str()))
|
||||
continue;
|
||||
|
||||
std::string fullName(nameTok->str());
|
||||
for (const Token *tok = nameTok->tokAt(-2); Token::Match(tok, "%name% ::"); tok = tok->tokAt(-2))
|
||||
fullName = tok->str() + "::" + fullName;
|
||||
fullName = getFullName(scopeInfo, fullName);
|
||||
if (fullName != templateName)
|
||||
// FIXME Proper name matching
|
||||
const std::string lastName(templateName.find(" ") == std::string::npos ? templateName : templateName.substr(templateName.rfind(" ") + 1));
|
||||
if (lastName != nameTok->str())
|
||||
continue;
|
||||
|
||||
// match parameters
|
||||
|
|
|
@ -108,6 +108,7 @@ private:
|
|||
TEST_CASE(template_namespace_1);
|
||||
TEST_CASE(template_namespace_2);
|
||||
TEST_CASE(template_namespace_3);
|
||||
TEST_CASE(template_namespace_4);
|
||||
|
||||
// Test TemplateSimplifier::templateParameters
|
||||
TEST_CASE(templateParameters);
|
||||
|
@ -1410,7 +1411,7 @@ private:
|
|||
"}";
|
||||
ASSERT_EQUALS("namespace test16 {"
|
||||
" void * test ( ) {"
|
||||
" return foo < int > :: bar ( ) ;"
|
||||
" return test16 :: foo < int > :: bar ( ) ;"
|
||||
" } "
|
||||
"} "
|
||||
"struct test16 :: foo < int > {"
|
||||
|
@ -1418,6 +1419,25 @@ private:
|
|||
"} ;", tok(code));
|
||||
}
|
||||
|
||||
void template_namespace_4() {
|
||||
const char code[] = "namespace foo {\n"
|
||||
" template<class T> class A { void dostuff() {} };\n"
|
||||
" struct S : public A<int> {\n"
|
||||
" void f() {\n"
|
||||
" A<int>::dostuff();\n"
|
||||
" }\n"
|
||||
" };\n"
|
||||
"}";
|
||||
ASSERT_EQUALS("namespace foo {"
|
||||
" struct S : public foo :: A < int > {"
|
||||
" void f ( ) {"
|
||||
" foo :: A < int > :: dostuff ( ) ;"
|
||||
" }"
|
||||
" } ; "
|
||||
"} "
|
||||
"class foo :: A < int > { void dostuff ( ) { } } ;", tok(code));
|
||||
}
|
||||
|
||||
unsigned int templateParameters(const char code[]) {
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
|
||||
|
|
Loading…
Reference in New Issue