Skip to content

Commit e825cc4

Browse files
authored
[clang] Add separate C++23 extension flag for attrs on lambda (#74553)
1 parent 5295b12 commit e825cc4

File tree

6 files changed

+12
-17
lines changed

6 files changed

+12
-17
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,7 @@ Conditional ``explicit`` __cpp_conditional_explicit C++20
14831483
``using enum`` __cpp_using_enum C++20 C++03
14841484
``if consteval`` __cpp_if_consteval C++23 C++20
14851485
``static operator()`` __cpp_static_call_operator C++23 C++03
1486+
Attributes on Lambda-Expressions C++23 C++11
14861487
-------------------------------------- -------------------------------- ------------- -------------
14871488
Designated initializers (N494) C99 C89
14881489
Array & element qualification (N2607) C23 C89

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ C++23 Feature Support
156156
support for this feature is still experimental, the feature test macro ``__cpp_explicit_this_parameter``
157157
was not set in this version.
158158

159+
- Added a separate warning to warn the use of attributes on lambdas as a C++23 extension
160+
in previous language versions: ``-Wc++23-lambda-attributes``.
161+
159162
C++2c Feature Support
160163
^^^^^^^^^^^^^^^^^^^^^
161164

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,8 @@ def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
11261126
CXX17Attrs,
11271127
CXX20Attrs]>;
11281128

1129+
def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
1130+
11291131
// A warning group for warnings about using C++11 features as extensions in
11301132
// earlier C++ versions.
11311133
def CXX11 : DiagGroup<"c++11-extensions", [CXX11ExtraSemi, CXX11InlineNamespace,
@@ -1145,7 +1147,7 @@ def CXX20 : DiagGroup<"c++20-extensions", [CXX20Designator, CXX20Attrs]>;
11451147

11461148
// A warning group for warnings about using C++23 features as extensions in
11471149
// earlier C++ versions.
1148-
def CXX23 : DiagGroup<"c++23-extensions">;
1150+
def CXX23 : DiagGroup<"c++23-extensions", [CXX23AttrsOnLambda]>;
11491151

11501152
// A warning group for warnings about using C++26 features as extensions in
11511153
// earlier C++ versions.

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ def err_capture_default_first : Error<
10351035
"capture default must be first">;
10361036
def ext_decl_attrs_on_lambda : ExtWarn<
10371037
"%select{an attribute specifier sequence|%0}1 in this position "
1038-
"is a C++23 extension">, InGroup<CXX23>;
1038+
"is a C++23 extension">, InGroup<CXX23AttrsOnLambda>;
10391039
def ext_lambda_missing_parens : ExtWarn<
10401040
"lambda without a parameter clause is a C++23 extension">,
10411041
InGroup<CXX23>;

clang/test/SemaCXX/coro-lifetimebound.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only -verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
1+
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only -verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused -Wno-c++23-lambda-attributes
22

33
#include "Inputs/std-coroutine.h"
44

@@ -64,14 +64,8 @@ Co<int> bar_coro(const int &b, int c) {
6464
: bar_coro(0, 1); // expected-warning {{returning address of local temporary object}}
6565
}
6666

67-
#define CORO_WRAPPER \
68-
_Pragma("clang diagnostic push") \
69-
_Pragma("clang diagnostic ignored \"-Wc++23-extensions\"") \
70-
[[clang::coro_wrapper]] \
71-
_Pragma("clang diagnostic pop")
72-
7367
void lambdas() {
74-
auto unsafe_lambda = [] CORO_WRAPPER (int b) {
68+
auto unsafe_lambda = [] [[clang::coro_wrapper]] (int b) {
7569
return foo_coro(b); // expected-warning {{address of stack memory associated with parameter}}
7670
};
7771
auto coro_lambda = [] (const int&) -> Co<int> {

clang/test/SemaCXX/coro-return-type-and-wrapper.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only -verify -Wall -Wextra
1+
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only -verify -Wall -Wextra -Wno-c++23-lambda-attributes
22
#include "Inputs/std-coroutine.h"
33

44
using std::suspend_always;
@@ -45,11 +45,6 @@ Co<int> non_marked_wrapper(int b) { return foo_coro(b); }
4545
} // namespace using_decl
4646

4747
namespace lambdas {
48-
#define CORO_WRAPPER \
49-
_Pragma("clang diagnostic push") \
50-
_Pragma("clang diagnostic ignored \"-Wc++23-extensions\"") \
51-
[[clang::coro_wrapper]] \
52-
_Pragma("clang diagnostic pop")
5348

5449
void foo() {
5550
auto coro_lambda = []() -> Gen<int> {
@@ -59,7 +54,7 @@ void foo() {
5954
auto not_allowed_wrapper = []() -> Gen<int> {
6055
return foo_coro(1);
6156
};
62-
auto allowed_wrapper = [] CORO_WRAPPER() -> Gen<int> {
57+
auto allowed_wrapper = [] [[clang::coro_wrapper]] () -> Gen<int> {
6358
return foo_coro(1);
6459
};
6560
}

0 commit comments

Comments
 (0)