From 6d65f868711bc9c53cf100f17aa9c8b0f6deda8c Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 14 Aug 2021 15:50:58 -0500 Subject: [PATCH] Fix 9245: Synax error on valid C++14 code: AST broken, binary operator '=' doesn't have two operands. (#3400) --- lib/tokenize.cpp | 4 +--- test/testgarbage.cpp | 13 +++++++------ test/testtokenize.cpp | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index aa712a588..872d2c10e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4525,9 +4525,7 @@ void Tokenizer::createLinks2() if (!top2 || top2->str() != "<") { if (token->str() == ">>") continue; - if (token->next() && - !Token::Match(token->next(), "%name%|%comp%|&|&&|*|::|,|(|)|{|}|;|[|:|.|=") && - !Token::simpleMatch(token->next(), "...") && + if (!Token::Match(token->next(), "%name%|%cop%|::|,|(|)|{|}|;|[|:|.|=|...") && !Token::Match(token->next(), "&& %name% =")) continue; } diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 0be286b19..fcb03e0a2 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -1738,12 +1738,13 @@ private: void cliCode() { // #8913 - ASSERT_THROW(checkCode("public ref class LibCecSharp : public CecCallbackMethods {\n" - "array ^ FindAdapters(String ^ path) {}\n" - "bool GetDeviceInformation(String ^ port, LibCECConfiguration ^configuration, uint32_t timeoutMs) {\n" - "bool bReturn(false);\n" - "}\n" - "};"), InternalError); + ASSERT_NO_THROW(checkCode( + "public ref class LibCecSharp : public CecCallbackMethods {\n" + "array ^ FindAdapters(String ^ path) {}\n" + "bool GetDeviceInformation(String ^ port, LibCECConfiguration ^configuration, uint32_t timeoutMs) {\n" + "bool bReturn(false);\n" + "}\n" + "};")); } void enumTrailingComma() { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 5c6392797..ebce76707 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6586,6 +6586,15 @@ private: "template struct F;\n" "int main() { using T = void (*)(a>); }\n")); + // #9245 + ASSERT_NO_THROW(tokenizeAndStringify("struct a {\n" + " typedef int b;\n" + " operator b();\n" + "};\n" + "template using c = a;\n" + "template c e;\n" + "auto f = ((e<4> | 0));\n")); + // #9340 ASSERT_NO_THROW(tokenizeAndStringify( "struct a {\n" @@ -6608,6 +6617,13 @@ private: " ;\n" "}\n")); + // #10015 + ASSERT_NO_THROW(tokenizeAndStringify( + "void func() {\n" + " if (std::is_same_v || 1)\n" + " ;\n" + "}\n")); + // #10309 ASSERT_NO_THROW(tokenizeAndStringify( "using a = void *;\n"