diff --git a/cxx-squid/dox/2023-03-19_cpp23_grammar.txt b/cxx-squid/dox/2023-03-19_cpp23_grammar.txt index aa0ca0b75..193c851f4 100644 --- a/cxx-squid/dox/2023-03-19_cpp23_grammar.txt +++ b/cxx-squid/dox/2023-03-19_cpp23_grammar.txt @@ -436,8 +436,7 @@ nested-name-specifier: lambda-expression: lambda-introducer attribute-specifier-seqopt lambda-declarator compound-statement - lambda-introducer < template-parameter-list > requires-clauseopt attribute-specifier-seqopt - lambda-declarator compound-statement + lambda-introducer < template-parameter-list > requires-clauseopt attribute-specifier-seqopt lambda-declarator compound-statement lambda-introducer: [ lambda-captureopt ] @@ -446,8 +445,7 @@ lambda-declarator: lambda-specifier-seq noexcept-specifieropt attribute-specifier-seqopt trailing-return-typeopt noexcept-specifier attribute-specifier-seqopt trailing-return-typeopt trailing-return-typeopt - ( parameter-declaration-clause ) lambda-specifier-seqopt noexcept-specifieropt attribute-specifier-seqopt - trailing-return-typeopt requires-clauseopt + ( parameter-declaration-clause ) lambda-specifier-seqopt noexcept-specifieropt attribute-specifier-seqopt trailing-return-typeopt requires-clauseopt lambda-specifier: consteval diff --git a/cxx-squid/dox/diff-cpp20-cpp23_grammar.txt b/cxx-squid/dox/diff-cpp20-cpp23_grammar.txt index ae20df630..906c12e57 100644 --- a/cxx-squid/dox/diff-cpp20-cpp23_grammar.txt +++ b/cxx-squid/dox/diff-cpp20-cpp23_grammar.txt @@ -136,15 +136,16 @@ d-char: lambda-expression: lambda-introducer attribute-specifier-seqopt lambda-declarator compound-statement - lambda-introducer < template-parameter-list > requires-clauseopt attribute-specifier-seqopt - lambda-declarator compound-statement + lambda-introducer < template-parameter-list > requires-clauseopt attribute-specifier-seqopt lambda-declarator compound-statement + +lambda-introducer: + [ lambda-captureopt ] lambda-declarator: lambda-specifier-seq noexcept-specifieropt attribute-specifier-seqopt trailing-return-typeopt noexcept-specifier attribute-specifier-seqopt trailing-return-typeopt trailing-return-typeopt - ( parameter-declaration-clause ) lambda-specifier-seqopt noexcept-specifieropt attribute-specifier-seqopt - trailing-return-typeopt requires-clauseopt + ( parameter-declaration-clause ) lambda-specifier-seqopt noexcept-specifieropt attribute-specifier-seqopt trailing-return-typeopt requires-clauseopt lambda-specifier: consteval @@ -163,25 +164,6 @@ requirement-seq: requirement requirement requirement-seq -postfix-expression: - primary-expression - postfix-expression [ expression-listopt ] - postfix-expression ( expression-listopt ) - simple-type-specifier ( expression-listopt ) - typename-specifier ( expression-listopt ) - simple-type-specifier braced-init-list - typename-specifier braced-init-list - postfix-expression . templateopt id-expression - postfix-expression -> templateopt id-expression - postfix-expression ++ - postfix-expression -- - dynamic_cast < type-id > ( expression ) - static_cast < type-id > ( expression ) - reinterpret_cast < type-id > ( expression ) - const_cast < type-id > ( expression ) - typeid ( expression ) - typeid ( type-id ) - **A.6 Statements [gram.stmt]** init-statement: diff --git a/cxx-squid/src/main/java/org/sonar/cxx/parser/CxxGrammarImpl.java b/cxx-squid/src/main/java/org/sonar/cxx/parser/CxxGrammarImpl.java index 6ba2fc746..17acdd75e 100644 --- a/cxx-squid/src/main/java/org/sonar/cxx/parser/CxxGrammarImpl.java +++ b/cxx-squid/src/main/java/org/sonar/cxx/parser/CxxGrammarImpl.java @@ -697,7 +697,7 @@ private static void expressions(LexerfulGrammarBuilder b) { ), b.zeroOrMore( b.firstOf( - b.sequence("[", exprOrBracedInitList, "]"), // C++ + b.sequence("[", b.optional(expressionList), "]"), // C++23 b.sequence("(", b.optional(expressionList), ")"), // C++ b.sequence( b.firstOf( diff --git a/cxx-squid/src/test/java/org/sonar/cxx/parser/ExpressionTest.java b/cxx-squid/src/test/java/org/sonar/cxx/parser/ExpressionTest.java index 5a823cef2..5d9a00d22 100644 --- a/cxx-squid/src/test/java/org/sonar/cxx/parser/ExpressionTest.java +++ b/cxx-squid/src/test/java/org/sonar/cxx/parser/ExpressionTest.java @@ -296,7 +296,6 @@ void postfixExpression() { mockRule(CxxGrammarImpl.expression); mockRule(CxxGrammarImpl.idExpression); mockRule(CxxGrammarImpl.typeId); - mockRule(CxxGrammarImpl.exprOrBracedInitList); mockRule(CxxGrammarImpl.cudaKernel); assertThatParser() @@ -313,7 +312,8 @@ void postfixExpression() { .matches("const_cast < typeId > ( expression )") .matches("typeid ( expression )") .matches("typeid ( typeId )") - .matches("primaryExpression [ exprOrBracedInitList ]") + .matches("primaryExpression [ ]") // C++23 + .matches("primaryExpression [ expressionList ]") // C++23 .matches("primaryExpression ( )") .matches("primaryExpression ( expressionList )") .matches("primaryExpression . idExpression") @@ -342,7 +342,9 @@ void postfixExpression_reallife() { .matches("G::typeid") .matches("int::typeid") // CUDA - .matches("kernel<<>>(d_data, height, width)"); + .matches("kernel<<>>(d_data, height, width)") + // C++23 + .matches("array[a, b]"); } @Test diff --git a/cxx-squid/src/test/resources/parser/own/C++23/multidimensional-subscript-operator.cc b/cxx-squid/src/test/resources/parser/own/C++23/multidimensional-subscript-operator.cc new file mode 100644 index 000000000..c2c12d80d --- /dev/null +++ b/cxx-squid/src/test/resources/parser/own/C++23/multidimensional-subscript-operator.cc @@ -0,0 +1,25 @@ +template +struct Matrix { + + static inline std::array mat{}; // (2) + + static T& operator[](std::size_t x, std::size_t y) { // (1) + return mat[y * X + x]; + } +}; + +int main() { + + std::cout << '\n'; + + Matrix mat; + for (auto i : {0, 1, 2}) { + for (auto j : {0, 1, 2}) mat[i, j] = (i * 3) + j; + } + for (auto i : {0, 1, 2}) { + for (auto j : {0, 1, 2}) std::cout << mat[i, j] << " "; + } + + std::cout << '\n'; + +}