Skip to content

Commit

Permalink
Merge pull request #2734 from guwirth/cpp23-init-statement
Browse files Browse the repository at this point in the history
C++23 extend init-statement to allow alias-declaration
  • Loading branch information
guwirth authored Aug 29, 2024
2 parents dc0e8d1 + dddc9db commit 203facf
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 @@ -166,11 +166,6 @@ requirement-seq:

**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 203facf

Please sign in to comment.