Fixed issue on C++11 right angle brackets (#4832)
This commit is contained in:
parent
917acea2ca
commit
876e9c0039
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue