[clang] e825cc4 - [clang] Add separate C++23 extension flag for attrs on lambda (#74553)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 7 05:52:15 PST 2023
Author: Utkarsh Saxena
Date: 2023-12-07T14:52:10+01:00
New Revision: e825cc4eba5fee546fd90032cfbdc6ac1c57a50e
URL: https://github.com/llvm/llvm-project/commit/e825cc4eba5fee546fd90032cfbdc6ac1c57a50e
DIFF: https://github.com/llvm/llvm-project/commit/e825cc4eba5fee546fd90032cfbdc6ac1c57a50e.diff
LOG: [clang] Add separate C++23 extension flag for attrs on lambda (#74553)
Added:
Modified:
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/test/SemaCXX/coro-lifetimebound.cpp
clang/test/SemaCXX/coro-return-type-and-wrapper.cpp
Removed:
################################################################################
diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst
index 286405850900a..4b1cc1d500c84 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -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
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1fbd332f74057..5c04465819713 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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
^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 12b11527b3057..caee2dc6daadb 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -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,
@@ -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.
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index e0e199e0d7300..6150fc36430ab 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -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>;
diff --git a/clang/test/SemaCXX/coro-lifetimebound.cpp b/clang/test/SemaCXX/coro-lifetimebound.cpp
index d3e2d673ebb3c..b4dc029a13984 100644
--- a/clang/test/SemaCXX/coro-lifetimebound.cpp
+++ b/clang/test/SemaCXX/coro-lifetimebound.cpp
@@ -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"
@@ -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> {
diff --git a/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp b/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp
index 5f8076f1c782a..ac49e03ba9d90 100644
--- a/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp
+++ b/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp
@@ -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;
@@ -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> {
@@ -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);
};
}
More information about the cfe-commits
mailing list