Fix #11090 Infinite recursion in findTypeInBase() (#4178)

This commit is contained in:
chrchr-github 2022-06-08 09:20:16 +02:00 committed by GitHub
parent 9367be804e
commit bb3f490edd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 4 deletions

View File

@ -2041,11 +2041,16 @@ namespace {
base += ' ';
base += tok->str();
tok = tok->next();
// skip template parameters
// add template parameters
if (tok && tok->str() == "<") {
tok = tok->findClosingBracket();
if (tok)
tok = tok->next();
const Token* endTok = tok->findClosingBracket();
if (endTok) {
endTok = endTok->next();
while (tok != endTok) {
base += tok->str();
tok = tok->next();
}
}
}
}
baseTypes.insert(base);

View File

@ -72,6 +72,7 @@ private:
TEST_CASE(simplifyUsing23);
TEST_CASE(simplifyUsing24);
TEST_CASE(simplifyUsing25);
TEST_CASE(simplifyUsing26); // #11090
TEST_CASE(simplifyUsing8970);
TEST_CASE(simplifyUsing8971);
@ -617,6 +618,34 @@ private:
ASSERT_EQUALS(expected, tok(code));
}
void simplifyUsing26() { // #11090
const char code[] = "namespace M {\n"
" struct A;\n"
" struct B;\n"
" struct C;\n"
" template<typename T>\n"
" struct F {};\n"
" template<>\n"
" struct F<B> : F<A> {};\n"
" template<>\n"
" struct F<C> : F<A> {};\n"
"}\n"
"namespace N {\n"
" using namespace M;\n"
" using A = void;\n"
"}\n";
const char expected[] = "namespace M { "
"struct A ; struct B ; struct C ; "
"struct F<C> ; struct F<B> ; struct F<A> ; "
"struct F<B> : F<A> { } ; struct F<C> : F<A> { } ; "
"} "
"namespace N { "
"using namespace M ; "
"} "
"struct M :: F<A> { } ;";
ASSERT_EQUALS(expected, tok(code));
}
void simplifyUsing8970() {
const char code[] = "using V = std::vector<int>;\n"
"struct A {\n"