Skip to content

Commit

Permalink
C++23 extend init-statement to allow alias-declaration
Browse files Browse the repository at this point in the history
- Extend init-statement (of for loop) to allow alias-declaration [P2360R0](https://wg21.link/P2360R0)
- linked SonarOpenCommunity#2536
  • Loading branch information
guwirth committed Aug 29, 2024
1 parent 696d8f3 commit dddc9db
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
5 changes: 0 additions & 5 deletions cxx-squid/dox/diff-cpp20-cpp23_grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@ postfix-expression:

**A.6 Statements [gram.stmt]**

init-statement:
expression-statement
simple-declaration
alias-declaration

label:
attribute-specifier-seqopt identifier :
attribute-specifier-seqopt case constant-expression :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,8 @@ private static void statements(LexerfulGrammarBuilder b) {
b.rule(initStatement).is(
b.firstOf(
expressionStatement, // C++
simpleDeclaration // C++
simpleDeclaration, // C++
aliasDeclaration // C++23
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,18 @@ void iterationStatement_reallife() {
// CLI extension
.matches("for each(String^% s in arr) { s = i++.ToString(); }")
// C++17 structered bindings
.matches("for (const auto&[key, val] : mymap) { std::cout << key << \": \" << val << std::endl; }");
.matches("for (const auto&[key, val] : mymap) { std::cout << key << \": \" << val << std::endl; }")
// C++23
.matches("for (using T = int; T e : v) ;");
}

@Test
void forInitStatement_reallife() {
setRootRule(CxxGrammarImpl.initStatement);

assertThatParser()
.matches("int i=1;");
.matches("int i=1;")
.matches("using T = int;"); // C++23
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
void sample() {
for (using T = int; T e : v)
/* something */;
}

0 comments on commit dddc9db

Please sign in to comment.