Fixed #2648 (Tokenizer::simplifyTemplates: Segmentation fault (gcc-testsuite))
This commit is contained in:
parent
7e04ea0859
commit
dab09aedee
|
@ -2911,6 +2911,7 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
|
||||||
if (Token::Match(tok, "%var% ,|>"))
|
if (Token::Match(tok, "%var% ,|>"))
|
||||||
type.push_back(tok);
|
type.push_back(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bail out if the end of the file was reached
|
// bail out if the end of the file was reached
|
||||||
if (!tok)
|
if (!tok)
|
||||||
return;
|
return;
|
||||||
|
@ -3006,6 +3007,12 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
|
||||||
std::string s1(name + " < ");
|
std::string s1(name + " < ");
|
||||||
for (const Token *tok3 = tok2->tokAt(2); tok3 && tok3->str() != ">"; tok3 = tok3->next())
|
for (const Token *tok3 = tok2->tokAt(2); tok3 && tok3->str() != ">"; tok3 = tok3->next())
|
||||||
{
|
{
|
||||||
|
// #2648 - unhandled paranthesis => bail out
|
||||||
|
if (tok3->str() == "(")
|
||||||
|
{
|
||||||
|
s.clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (!tok3->next())
|
if (!tok3->next())
|
||||||
{
|
{
|
||||||
s.clear();
|
s.clear();
|
||||||
|
|
|
@ -115,6 +115,7 @@ private:
|
||||||
TEST_CASE(template22);
|
TEST_CASE(template22);
|
||||||
TEST_CASE(template23);
|
TEST_CASE(template23);
|
||||||
TEST_CASE(template24); // #2648 - using sizeof in template parameter
|
TEST_CASE(template24); // #2648 - using sizeof in template parameter
|
||||||
|
TEST_CASE(template25); // #2648 - another test for sizeof template parameter
|
||||||
TEST_CASE(template_unhandled);
|
TEST_CASE(template_unhandled);
|
||||||
TEST_CASE(template_default_parameter);
|
TEST_CASE(template_default_parameter);
|
||||||
TEST_CASE(template_default_type);
|
TEST_CASE(template_default_type);
|
||||||
|
@ -2060,6 +2061,30 @@ private:
|
||||||
ASSERT_EQUALS(expected, sizeof_(code));
|
ASSERT_EQUALS(expected, sizeof_(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void template25()
|
||||||
|
{
|
||||||
|
const char code[] = "template<int n> struct B\n"
|
||||||
|
"{\n"
|
||||||
|
" int a[n];\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"template<int x> class bitset: B<((sizeof(int)) ? : 1)>\n"
|
||||||
|
"{};\n"
|
||||||
|
"\n"
|
||||||
|
"bitset<1> z;";
|
||||||
|
|
||||||
|
const char actual[] = "; bitset<1> z ; "
|
||||||
|
"class bitset<1> : B < ( ) > { }";
|
||||||
|
|
||||||
|
const char expected[] = "; "
|
||||||
|
"bitset<1> z ; "
|
||||||
|
"class bitset<1> : B<4> { } "
|
||||||
|
"struct B<4> { int a [ 4 ] ; }";
|
||||||
|
|
||||||
|
TODO_ASSERT_EQUALS(expected, actual, sizeof_(code));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void template_unhandled()
|
void template_unhandled()
|
||||||
{
|
{
|
||||||
// An unhandled template usage should be simplified..
|
// An unhandled template usage should be simplified..
|
||||||
|
|
Loading…
Reference in New Issue