Fix issue 9662: AST broken, ternary operator missing operand(s) on valid C++ code (#2589)

* Fix issue 9662: AST broken, ternary operator missing operand(s) on valid C++ code

* Add test for issue 9537
This commit is contained in:
Paul Fultz II 2020-04-03 03:04:10 -05:00 committed by GitHub
parent 8968edeabd
commit 58e3f19ed8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -1520,9 +1520,15 @@ static Token * createAstAtToken(Token *tok, bool cpp)
}
if (cpp && tok->str() == "{" && iscpp11init(tok)) {
Token * const tok1 = tok;
AST_state state(cpp);
compileExpression(tok, state);
return tok;
const Token * const endToken = tok;
if (endToken == tok1 || !endToken)
return tok1;
createAstAtTokenInner(tok1->next(), endToken, cpp);
return endToken->previous();
}
return tok;

View File

@ -7887,6 +7887,9 @@ private:
testAst("a = [&]() -> std::pair<int, int> { return 0; };\n"
"b = [=]() { for (i = 0; i != 10; ++i); };"));
// #9662
ASSERT_EQUALS("b{[{ stdunique_ptr::0nullptrnullptr:?{", testAst("auto b{[] { std::unique_ptr<void *>{0 ? nullptr : nullptr}; }};"));
}
void astcase() {
@ -8237,6 +8240,14 @@ private:
"};\n"
"void e(\n"
" int, a<void()> f = [] {});\n"))
// #9537
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"
" template <typename b> a(b) {}\n"
"};\n"
"a c{[] {\n"
" if (0) {}\n"
"}};\n"))
}
void checkIfCppCast() {
ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n"