[clang] [clang] Add separate C++23 extension flag for attrs on lambda (PR #74553)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 6 01:57:35 PST 2023
https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/74553
>From 9be87da42e48895cf23d90a3ed735b7a36b1ccb3 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Wed, 6 Dec 2023 04:51:45 +0100
Subject: [PATCH 1/3] [clang] Add separate C++23 extension flag for attrs on
lambda
---
clang/include/clang/Basic/DiagnosticGroups.td | 4 +++-
clang/include/clang/Basic/DiagnosticParseKinds.td | 2 +-
clang/test/SemaCXX/coro-lifetimebound.cpp | 10 ++--------
clang/test/SemaCXX/coro-return-type-and-wrapper.cpp | 9 ++-------
4 files changed, 8 insertions(+), 17 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index ff028bbbf7426..81443fb16a1f3 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-attrs-on-lambda">;
+
// 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 21fe6066d5876..bc7bd7589ef14 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..ec8997036feb4 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-attrs-on-lambda
#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..d52d1e4cea399 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-attrs-on-lambda
#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);
};
}
>From 14532988c00fc0ce6530a05a899abbc3976bd374 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Wed, 6 Dec 2023 05:00:59 +0100
Subject: [PATCH 2/3] add release notes
---
clang/docs/ReleaseNotes.rst | 3 +++
1 file changed, 3 insertions(+)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 89ea2f0930cec..a2ccf8ad050aa 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-attrs-on-lambda``.
+
C++2c Feature Support
^^^^^^^^^^^^^^^^^^^^^
>From 4648fc5b6c80b84acf19ccb3722046c879873577 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Wed, 6 Dec 2023 10:57:21 +0100
Subject: [PATCH 3/3] rename warning to c++23-lambda-attributes
---
clang/docs/ReleaseNotes.rst | 2 +-
clang/include/clang/Basic/DiagnosticGroups.td | 2 +-
clang/test/SemaCXX/coro-lifetimebound.cpp | 2 +-
clang/test/SemaCXX/coro-return-type-and-wrapper.cpp | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a2ccf8ad050aa..ad76b85f8abf8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,7 +157,7 @@ C++23 Feature Support
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-attrs-on-lambda``.
+ 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 81443fb16a1f3..2e210532e2a57 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1126,7 +1126,7 @@ def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
CXX17Attrs,
CXX20Attrs]>;
-def CXX23AttrsOnLambda : DiagGroup<"c++23-attrs-on-lambda">;
+def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
// A warning group for warnings about using C++11 features as extensions in
// earlier C++ versions.
diff --git a/clang/test/SemaCXX/coro-lifetimebound.cpp b/clang/test/SemaCXX/coro-lifetimebound.cpp
index ec8997036feb4..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 -Wno-c++23-attrs-on-lambda
+// 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"
diff --git a/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp b/clang/test/SemaCXX/coro-return-type-and-wrapper.cpp
index d52d1e4cea399..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 -Wno-c++23-attrs-on-lambda
+// 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;
More information about the cfe-commits
mailing list