Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ C++2c Feature Support
At this timem, references to constexpr and decomposition of *tuple-like* types are not supported
(only arrays and aggregates are).

- Implemented `P1306R5 <https://wg21.link/P1306R5>`_ Expansion Statements.

C++23 Feature Support
^^^^^^^^^^^^^^^^^^^^^

Expand Down
4 changes: 0 additions & 4 deletions clang/include/clang/Basic/DiagnosticCommonKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ def select_constexpr_spec_kind : TextSubstitution<
def fatal_too_many_errors
: Error<"too many errors emitted, stopping now">, DefaultFatal;

// TODO: Remove this.
def err_expansion_statements_todo : Error<
"TODO (expansion statements)">;

def warn_stack_exhausted : Warning<
"stack nearly exhausted; compilation time may suffer, and "
"crashes due to stack overflow are likely">,
Expand Down
49 changes: 49 additions & 0 deletions clang/test/AST/ast-dump-expansion-stmt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Test without serialization:
// RUN: %clang_cc1 -std=c++26 -triple x86_64-unknown-unknown -ast-dump %s
//
// Test with serialization:
// RUN: %clang_cc1 -std=c++26 -triple x86_64-unknown-unknown -emit-pch -o %t %s
// RUN: %clang_cc1 -x c++ -std=c++26 -triple x86_64-unknown-unknown -include-pch %t -ast-dump-all /dev/null \
// RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//"

template <typename T, __SIZE_TYPE__ size>
struct Array {
T data[size]{};
constexpr const T* begin() const { return data; }
constexpr const T* end() const { return data + size; }
};

void foo(int);

template <typename T>
void test(T t) {
// CHECK: CXXExpansionStmtDecl
// CHECK-NEXT: CXXEnumeratingExpansionStmtPattern
// CHECK: CXXExpansionStmtInstantiation
template for (auto x : {1, 2, 3}) {
foo(x);
}

// CHECK: CXXExpansionStmtDecl
// CHECK-NEXT: CXXIteratingExpansionStmtPattern
// CHECK: CXXExpansionStmtInstantiation
static constexpr Array<int, 3> a;
template for (auto x : a) {
foo(x);
}

// CHECK: CXXExpansionStmtDecl
// CHECK-NEXT: CXXDestructuringExpansionStmtPattern
// CHECK: CXXExpansionStmtInstantiation
int arr[3]{1, 2, 3};
template for (auto x : arr) {
foo(x);
}

// CHECK: CXXExpansionStmtDecl
// CHECK-NEXT: CXXDependentExpansionStmtPattern
// CHECK-NOT: CXXExpansionStmtInstantiation
template for (auto x : t) {
foo(x);
}
}
104 changes: 104 additions & 0 deletions clang/test/AST/ast-print-expansion-stmts.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Without serialization:
// RUN: %clang_cc1 -std=c++26 -ast-print %s | FileCheck %s
//
// With serialization:
// RUN: %clang_cc1 -std=c++26 -emit-pch -o %t %s
// RUN: %clang_cc1 -x c++ -std=c++26 -include-pch %t -ast-print /dev/null | FileCheck %s

template <typename T, __SIZE_TYPE__ size>
struct Array {
T data[size]{};
constexpr const T* begin() const { return data; }
constexpr const T* end() const { return data + size; }
};

// CHECK: void foo(int);
void foo(int);

// CHECK: template <typename T> void test(T t) {
template <typename T>
void test(T t) {
// Enumerating expansion statement.
//
// CHECK: template for (auto x : { 1, 2, 3 }) {
// CHECK-NEXT: foo(x);
// CHECK-NEXT: }
template for (auto x : {1, 2, 3}) {
foo(x);
}

// Iterating expansion statement.
//
// CHECK: static constexpr Array<int, 3> a;
// CHECK-NEXT: template for (auto x : a) {
// CHECK-NEXT: foo(x);
// CHECK-NEXT: }
static constexpr Array<int, 3> a;
template for (auto x : a) {
foo(x);
}

// Destructuring expansion statement.
//
// CHECK: int arr[3]{1, 2, 3};
// CHECK-NEXT: template for (auto x : arr) {
// CHECK-NEXT: foo(x);
// CHECK-NEXT: }
int arr[3]{1, 2, 3};
template for (auto x : arr) {
foo(x);
}

// Dependent expansion statement.
//
// CHECK: template for (auto x : t) {
// CHECK-NEXT: foo(x);
// CHECK-NEXT: }
template for (auto x : t) {
foo(x);
}
}

// CHECK: template <typename T> void test2(T t) {
template <typename T>
void test2(T t) {
// Enumerating expansion statement.
//
// CHECK: template for (int x : { 1, 2, 3 }) {
// CHECK-NEXT: foo(x);
// CHECK-NEXT: }
template for (int x : {1, 2, 3}) {
foo(x);
}

// Iterating expansion statement.
//
// CHECK: static constexpr Array<int, 3> a;
// CHECK-NEXT: template for (int x : a) {
// CHECK-NEXT: foo(x);
// CHECK-NEXT: }
static constexpr Array<int, 3> a;
template for (int x : a) {
foo(x);
}

// Destructuring expansion statement.
//
// CHECK: int arr[3]{1, 2, 3};
// CHECK-NEXT: template for (int x : arr) {
// CHECK-NEXT: foo(x);
// CHECK-NEXT: }
int arr[3]{1, 2, 3};
template for (int x : arr) {
foo(x);
}

// Dependent expansion statement.
//
// CHECK: template for (int x : t) {
// CHECK-NEXT: foo(x);
// CHECK-NEXT: }
template for (int x : t) {
foo(x);
}
}
2 changes: 1 addition & 1 deletion clang/www/cxx_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ <h2 id="cxx26">C++2c implementation status</h2>
<tr>
<td>Expansion Statements</td>
<td><a href="https://wg21.link/P1306">P1306R5</a></td>
<td class="none" align="center">No</td>
<td class="unreleased" align="center">Clang 22</td>
</tr>
<tr>
<td>constexpr virtual inheritance</td>
Expand Down
Loading