Fix 10336: AST cyclic dependency on valid C++ code (#3331)

This commit is contained in:
Paul Fultz II 2021-07-09 00:22:24 -05:00 committed by GitHub
parent 7e2ba803f4
commit 2300a773e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -19,6 +19,7 @@
//---------------------------------------------------------------------------
#include "tokenlist.h"
#include "astutils.h"
#include "errorlogger.h"
#include "library.h"
#include "path.h"
@ -1351,7 +1352,7 @@ static Token * createAstAtToken(Token *tok, bool cpp);
// Compile inner expressions inside inner ({..}) and lambda bodies
static void createAstAtTokenInner(Token * const tok1, const Token *endToken, bool cpp)
{
for (Token *tok = tok1; tok && tok != endToken; tok = tok ? tok->next() : nullptr) {
for (Token* tok = tok1; precedes(tok, endToken); tok = tok ? tok->next() : nullptr) {
if (tok->str() == "{" && !iscpp11init(tok)) {
const Token * const endToken2 = tok->link();
bool hasAst = false;

View File

@ -6620,6 +6620,19 @@ private:
"}\n"));
ASSERT_NO_THROW(tokenizeAndStringify("a<b?0:1>()==3;"));
// #10336
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
" template <class b> a(b);\n"
"};\n"
"struct c;\n"
"void fn1(int, a);\n"
"void f() { fn1(0, {a{0}}); }\n"
"template <class> std::vector<c> g() {\n"
" int d;\n"
" for (size_t e = 0; e < d; e++)\n"
" ;\n"
"}\n"));
}
void checkNamespaces() {