Skip to content

[clang] Add separate C++23 extension flag for attrs on lambda #74553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 7, 2023
Merged
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
1 change: 1 addition & 0 deletions clang/docs/LanguageExtensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,7 @@ Conditional ``explicit`` __cpp_conditional_explicit C++20
``using enum`` __cpp_using_enum C++20 C++03
``if consteval`` __cpp_if_consteval C++23 C++20
``static operator()`` __cpp_static_call_operator C++23 C++03
Attributes on Lambda-Expressions C++23 C++11
-------------------------------------- -------------------------------- ------------- -------------
Designated initializers (N494) C99 C89
Array & element qualification (N2607) C23 C89
Expand Down
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ C++23 Feature Support
support for this feature is still experimental, the feature test macro ``__cpp_explicit_this_parameter``
was not set in this version.

- Added a separate warning to warn the use of attributes on lambdas as a C++23 extension
in previous language versions: ``-Wc++23-lambda-attributes``.

C++2c Feature Support
^^^^^^^^^^^^^^^^^^^^^

Expand Down
4 changes: 3 additions & 1 deletion clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,8 @@ def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
CXX17Attrs,
CXX20Attrs]>;

def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;

// A warning group for warnings about using C++11 features as extensions in
// earlier C++ versions.
def CXX11 : DiagGroup<"c++11-extensions", [CXX11ExtraSemi, CXX11InlineNamespace,
Expand All @@ -1145,7 +1147,7 @@ def CXX20 : DiagGroup<"c++20-extensions", [CXX20Designator, CXX20Attrs]>;

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

// A warning group for warnings about using C++26 features as extensions in
// earlier C++ versions.
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ def err_capture_default_first : Error<
"capture default must be first">;
def ext_decl_attrs_on_lambda : ExtWarn<
"%select{an attribute specifier sequence|%0}1 in this position "
"is a C++23 extension">, InGroup<CXX23>;
"is a C++23 extension">, InGroup<CXX23AttrsOnLambda>;
def ext_lambda_missing_parens : ExtWarn<
"lambda without a parameter clause is a C++23 extension">,
InGroup<CXX23>;
Expand Down
10 changes: 2 additions & 8 deletions clang/test/SemaCXX/coro-lifetimebound.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only -verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
// 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

#include "Inputs/std-coroutine.h"

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

#define CORO_WRAPPER \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wc++23-extensions\"") \
[[clang::coro_wrapper]] \
_Pragma("clang diagnostic pop")

void lambdas() {
auto unsafe_lambda = [] CORO_WRAPPER (int b) {
auto unsafe_lambda = [] [[clang::coro_wrapper]] (int b) {
return foo_coro(b); // expected-warning {{address of stack memory associated with parameter}}
};
auto coro_lambda = [] (const int&) -> Co<int> {
Expand Down
9 changes: 2 additions & 7 deletions clang/test/SemaCXX/coro-return-type-and-wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only -verify -Wall -Wextra
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only -verify -Wall -Wextra -Wno-c++23-lambda-attributes
#include "Inputs/std-coroutine.h"

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

namespace lambdas {
#define CORO_WRAPPER \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wc++23-extensions\"") \
[[clang::coro_wrapper]] \
_Pragma("clang diagnostic pop")

void foo() {
auto coro_lambda = []() -> Gen<int> {
Expand All @@ -59,7 +54,7 @@ void foo() {
auto not_allowed_wrapper = []() -> Gen<int> {
return foo_coro(1);
};
auto allowed_wrapper = [] CORO_WRAPPER() -> Gen<int> {
auto allowed_wrapper = [] [[clang::coro_wrapper]] () -> Gen<int> {
return foo_coro(1);
};
}
Expand Down