Merge pull request #1010 from simartin/ticket_8175
Ticket #8175: Fix bug in TemplateSimplifier::instantiateMatch with template parameters involving sizeof or namespace.
This commit is contained in:
commit
0d4744c317
|
@ -695,7 +695,7 @@ bool TemplateSimplifier::instantiateMatch(const Token *instance, const std::stri
|
|||
const Token *tok = instance;
|
||||
unsigned int indentlevel = 0;
|
||||
for (tok = instance; tok && (tok->str() != ">" || indentlevel > 0); tok = tok->next()) {
|
||||
if (Token::Match(tok, "[<,] %name% <") && templateParameters(tok->tokAt(2)) > 0)
|
||||
if (Token::Match(tok, "<|,|(|:: %name% <") && templateParameters(tok->tokAt(2)) > 0)
|
||||
++indentlevel;
|
||||
if (indentlevel > 0 && tok->str() == ">")
|
||||
--indentlevel;
|
||||
|
|
|
@ -113,6 +113,9 @@ private:
|
|||
TEST_CASE(templateNamePosition);
|
||||
|
||||
TEST_CASE(expandSpecialized);
|
||||
|
||||
// Test TemplateSimplifier::instantiateMatch
|
||||
TEST_CASE(instantiateMatch);
|
||||
}
|
||||
|
||||
std::string tok(const char code[], bool simplify = true, bool debugwarnings = false, Settings::PlatformType type = Settings::Native) {
|
||||
|
@ -1473,6 +1476,31 @@ private:
|
|||
ASSERT_EQUALS("class A < int > { } ;", tok("template<> class A<int> {};"));
|
||||
ASSERT_EQUALS("class A < int > : public B { } ;", tok("template<> class A<int> : public B {};"));
|
||||
}
|
||||
|
||||
unsigned int instantiateMatch(const char code[], const std::string& name, const std::size_t numberOfArguments, const char patternAfter[]) {
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp", "");
|
||||
|
||||
return TemplateSimplifier::instantiateMatch(tokenizer.tokens(), name, numberOfArguments, patternAfter);
|
||||
}
|
||||
|
||||
void instantiateMatch() {
|
||||
// Ticket #8175
|
||||
ASSERT_EQUALS(false,
|
||||
instantiateMatch("ConvertHelper < From, To > c ;",
|
||||
"ConvertHelper", 2, ":: %name% ("));
|
||||
ASSERT_EQUALS(true,
|
||||
instantiateMatch("ConvertHelper < From, To > :: Create ( ) ;",
|
||||
"ConvertHelper", 2, ":: %name% ("));
|
||||
ASSERT_EQUALS(false,
|
||||
instantiateMatch("integral_constant < bool, sizeof ( ConvertHelper < From, To > :: Create ( ) ) > ;",
|
||||
"integral_constant", 2, ":: %name% ("));
|
||||
ASSERT_EQUALS(false,
|
||||
instantiateMatch("integral_constant < bool, sizeof ( ns :: ConvertHelper < From, To > :: Create ( ) ) > ;",
|
||||
"integral_constant", 2, ":: %name% ("));
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestSimplifyTemplate)
|
||||
|
|
Loading…
Reference in New Issue