Fixed issue on C++11 right angle brackets (#4832)

This commit is contained in:
PKEuS 2013-06-12 13:43:29 -07:00
parent 917acea2ca
commit 876e9c0039
2 changed files with 21 additions and 3 deletions

View File

@ -663,14 +663,17 @@ void TemplateSimplifier::expandTemplate(
if (itype < typeParametersInDeclaration.size()) {
unsigned int typeindentlevel = 0;
for (const Token *typetok = typesUsedInTemplateInstantiation[itype];
typetok && (typeindentlevel>0 || !Token::Match(typetok, "[,>]"));
typetok && (typeindentlevel>0 || !Token::Match(typetok, ",|>|>>"));
typetok = typetok->next()) {
if (Token::Match(typetok, "%var% <") && templateParameters(typetok->next()) > 0)
++typeindentlevel;
else if (typeindentlevel > 0 && typetok->str() == ">")
--typeindentlevel;
else if (typeindentlevel > 0 && typetok->str() == ">>")
typeindentlevel -= (typeindentlevel > 1) ? 2 : 1;
else if (typeindentlevel > 0 && typetok->str() == ">>") {
if (typeindentlevel == 1)
break;
typeindentlevel -= 2;
}
tokenlist.addtoken(typetok, tok3->linenr(), tok3->fileIndex());
}
continue;

View File

@ -129,6 +129,7 @@ private:
TEST_CASE(template35); // #4074 - A<'x'> a;
TEST_CASE(template36); // #4310 - passing unknown template instantiation as template argument
TEST_CASE(template37); // #4544 - A<class B> a;
TEST_CASE(template38); // #4832 - crash on C++11 right angle brackets
TEST_CASE(template_unhandled);
TEST_CASE(template_default_parameter);
TEST_CASE(template_default_type);
@ -2287,6 +2288,20 @@ private:
ASSERT_EQUALS("x<int> ( ) ;", tok("x<int>();"));
}
void template38() { // #4832 - Crash on C++11 right angle brackets
const char code[] = "template <class T> class A {\n"
" T mT;\n"
"public:\n"
" void foo() {}\n"
"};\n"
"\n"
"int main() {\n"
" A<A<BLA>> gna1;\n"
" A<BLA> gna2;\n"
"}\n";
tok(code); // Don't crash or freeze
}
void template_default_parameter() {
{
const char code[] = "template <class T, int n=3>\n"