Fixed #2721 (Tokenizer::simplifyTemplates: fail when using template argument 'char[2]')

This commit is contained in:
Daniel Marjamaki 2011-05-01 19:05:18 +02:00
parent 8ec570837a
commit 297ca63868
2 changed files with 17 additions and 1 deletions

View File

@ -3093,7 +3093,8 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
for (const Token *tok3 = tok2->tokAt(2); tok3 && tok3->str() != ">"; tok3 = tok3->next())
{
// #2648 - unhandled parenthesis => bail out
if (tok3->str() == "(")
// #2721 - unhandled [ => bail out
if (tok3->str() == "(" || tok3->str() == "[")
{
s.clear();
break;

View File

@ -116,6 +116,7 @@ private:
TEST_CASE(template23);
TEST_CASE(template24); // #2648 - using sizeof in template parameter
TEST_CASE(template25); // #2648 - another test for sizeof template parameter
TEST_CASE(template26); // #2721 - passing 'char[2]' as template parameter
TEST_CASE(template_unhandled);
TEST_CASE(template_default_parameter);
TEST_CASE(template_default_type);
@ -2094,6 +2095,20 @@ private:
}
void template26()
{
// #2721
const char code[] = "template<class T>\n"
"class A { public: T x; };\n"
"\n"
"template<class M>\n"
"class C: public A<char[M]> {};\n"
"\n"
"C<2> a;\n";
// TODO: expand A also
ASSERT_EQUALS("; C<2> a ; class C<2> : public A < char [ 2 ] > { }", sizeof_(code));
}
void template_unhandled()
{
// An unhandled template usage should be simplified..