diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index f5ad39367..4875e6c01 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -951,8 +951,10 @@ static void compilePrecedence2(Token *&tok, AST_state& state) if (Token::simpleMatch(squareBracket->link(), "] (")) { Token* const roundBracket = squareBracket->link()->next(); Token* curlyBracket = roundBracket->link()->next(); - if (Token::Match(curlyBracket, "mutable|const|noexcept")) + while (Token::Match(curlyBracket, "mutable|const")) curlyBracket = curlyBracket->next(); + if (Token::simpleMatch(curlyBracket, "noexcept (")) + curlyBracket = curlyBracket->linkAt(1)->next(); if (curlyBracket && curlyBracket->originalName() == "->") curlyBracket = findTypeEnd(curlyBracket->next()); if (curlyBracket && curlyBracket->str() == "{") { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 24eadcca9..041f6e708 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5932,8 +5932,16 @@ private: ASSERT_EQUALS("x{(a&[( ai=", testAst("x([&a](int i){a=i;});")); ASSERT_EQUALS("{([(return 0return", testAst("return [](){ return 0; }();")); - // noexcept - ASSERT_EQUALS("x{([( ai=", testAst("x([](int i)noexcept{a=i;});")); + // noexcept (which if simplified to always have a condition by the time AST is created) + ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) noexcept(true) { a=i; });")); + ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) mutable noexcept(true) { a=i; });")); + ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) const noexcept(true) { a=i; });")); + + // both mutable and constexpr (which is simplified to 'const' by the time AST is created) + ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) const mutable { a=i; });")); + ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) mutable const { a=i; });")); + ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) const mutable noexcept(true) { a=i; });")); + ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) mutable const noexcept(true) { a=i; });")); // -> ASSERT_EQUALS("{([(return 0return", testAst("return []() -> int { return 0; }();")); @@ -5989,6 +5997,9 @@ private: // Lambda capture expression (C++14) ASSERT_EQUALS("a{b1=[= c2=", testAst("a = [b=1]{c=2;};")); + + // #9729 + ASSERT_NO_THROW(tokenizeAndStringify("void foo() { bar([]() noexcept { if (0) {} }); }")); } void astcase() {