From 0d2af9a5b7121901658652e1350e78d4bdb8b040 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 23 Mar 2022 18:10:33 +0100 Subject: [PATCH] Fix #10880 FP constStatement with init list in function call (#3929) --- lib/tokenlist.cpp | 2 ++ test/testincompletestatement.cpp | 8 +++++++- test/testtokenize.cpp | 6 +++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index b3b0885a5..1a9485261 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -632,6 +632,8 @@ static bool iscpp11init_impl(const Token * const tok) return false; if (nameToken->str() == ")" && Token::simpleMatch(nameToken->link()->previous(), "decltype (")) return true; + if (Token::simpleMatch(nameToken, ", {")) + return true; if (nameToken->str() == ">" && nameToken->link()) nameToken = nameToken->link()->previous(); diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 99d0d6838..52b64053e 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -498,11 +498,17 @@ private: "[test.cpp:15]: (warning) Redundant code: Found unused member access.\n", errout.str()); - check("struct S { void* p; };\n" + check("struct S { void* p; };\n" // #10875 "void f(S s) {\n" " delete (int*)s.p;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void f(int i, std::vector v);\n" // #10880 + "void g() {\n" + " f(1, { static_cast(nullptr) });\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void vardecl() { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 8f2d8f889..e24301c61 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6134,8 +6134,8 @@ private: ASSERT_EQUALS("xab,c,{=", testAst("x={a,b,(c)};")); ASSERT_EQUALS("x0fSa.1=b.2=,c.\"\"=,{(||=", testAst("x = 0 || f(S{.a = 1, .b = 2, .c = \"\" });")); ASSERT_EQUALS("x0fSa.1{=b.2{,c.\"\"=,{(||=", testAst("x = 0 || f(S{.a = { 1 }, .b { 2 }, .c = \"\" });")); - ASSERT_EQUALS("a0{,( \"\"abc12:?,", testAst("a(0, {{\"\", (abc) ? 1 : 2}});")); - ASSERT_EQUALS("a0{,( \'\'abc12:?,", testAst("a(0, {{\'\', (abc) ? 1 : 2}});")); + ASSERT_EQUALS("a0\"\"abc12:?,{{,(", testAst("a(0, {{\"\", (abc) ? 1 : 2}});")); + ASSERT_EQUALS("a0\'\'abc12:?,{{,(", testAst("a(0, {{\'\', (abc) ? 1 : 2}});")); ASSERT_EQUALS("x12,{34,{,{56,{78,{,{,{=", testAst("x = { { {1,2}, {3,4} }, { {5,6}, {7,8} } };")); ASSERT_EQUALS("Sa.stdmove::s(=b.1=,{(", testAst("S({.a = std::move(s), .b = 1})")); @@ -6168,7 +6168,7 @@ private: ASSERT_EQUALS("a1{ b2{", testAst("auto a{1}; auto b{2};")); ASSERT_EQUALS("var1ab::23,{,4ab::56,{,{,{{", testAst("auto var{{1,a::b{2,3}}, {4,a::b{5,6}}};")); ASSERT_EQUALS("var{{,{,{{", testAst("auto var{ {{},{}}, {} };")); - ASSERT_EQUALS("fX{,{( abcfalse==CD:?", testAst("f({X, {Y, abc == false ? C : D}});")); + ASSERT_EQUALS("fXYabcfalse==CD:?,{,{(", testAst("f({X, {Y, abc == false ? C : D}});")); // Initialization with decltype(expr) instead of a type ASSERT_EQUALS("decltypex((", testAst("decltype(x)();"));