[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
Tue Dec 5 19:53:10 PST 2023


https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/74553

None

>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] [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);
   };
 }



More information about the cfe-commits mailing list