[clang] [Clang][NFC] Mark P2552 as implemented. (PR #92007)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 13 11:01:05 PDT 2024


https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/92007

>From 0829867e188ef47877b7feb985c77dba5f0940fb Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Mon, 13 May 2024 19:41:31 +0200
Subject: [PATCH 1/2] [Clang] Mark P2552 as implemented.

wg21.link/P2552 suggest that __has_cpp_attribute
should return a non-zero value for all attributes that the
implementation does something interesting with.

Clang does something meaninful with all attributes except for:

- no_unique_address which we do not support for msvc target
- carries_dependency which arguably does nothing interesting.
  P2552 shies away from specifying a behavior for that attribute
  (despite being the only one for which a recommandation would have been
  interesting, arguably)

As such, we have nothing to change for this paper.
This paper is a DR and clang always behaved reasonably.
---
 clang/test/SemaCXX/cxx2c-attributes.cpp | 23 +++++++++++++++++++++++
 clang/www/cxx_status.html               |  2 +-
 2 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/cxx2c-attributes.cpp

diff --git a/clang/test/SemaCXX/cxx2c-attributes.cpp b/clang/test/SemaCXX/cxx2c-attributes.cpp
new file mode 100644
index 0000000000000..f9f76efd01be0
--- /dev/null
+++ b/clang/test/SemaCXX/cxx2c-attributes.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -x c++ -std=c++11 -triple x86_64-pc-linux -fsyntax-only
+// RUN: %clang_cc1 -x c++ -std=c++11 -triple x86_64-windows-msvc -fsyntax-only
+
+// Check we return non-zero values for supported attributes as per
+// wg21.link/p2552r3.pdf
+static_assert(__has_cpp_attribute(assume));
+
+// The standard does not prescribe a behavior for [[carries_dependency]]
+
+static_assert(__has_cpp_attribute(deprecated));
+static_assert(__has_cpp_attribute(fallthrough));
+static_assert(__has_cpp_attribute(likely));
+static_assert(__has_cpp_attribute(unlikely));
+static_assert(__has_cpp_attribute(maybe_unused));
+static_assert(__has_cpp_attribute(nodiscard));
+static_assert(__has_cpp_attribute(noreturn));
+
+#ifdef _MSC_VER
+// We do not support [[no_unique_address]] in MSVC emulation mode
+static_assert(__has_cpp_attribute(no_unique_address) == 0);
+#else
+static_assert(__has_cpp_attribute(no_unique_address));
+#endif
diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 1338f544ffcb5..06777eaa6df69 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -130,7 +130,7 @@ <h2 id="cxx26">C++2c implementation status</h2>
  <tr>
   <td>On the ignorability of standard attributes</td>
   <td><a href="https://wg21.link/P2552R3">P2552R3</a> (<a href="#dr">DR</a>)</td>
-  <td class="none" align="center">No</td>
+  <td class="full" align="center">Yes</td>
  </tr>
  <tr>
   <td>Static storage for braced initializers</td>

>From da3c68333a544a1354c8870798d394fa20047f82 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Mon, 13 May 2024 20:00:49 +0200
Subject: [PATCH 2/2] Fix tests

---
 clang/test/SemaCXX/cxx2c-attributes.cpp | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/clang/test/SemaCXX/cxx2c-attributes.cpp b/clang/test/SemaCXX/cxx2c-attributes.cpp
index f9f76efd01be0..c20a1b606a0fd 100644
--- a/clang/test/SemaCXX/cxx2c-attributes.cpp
+++ b/clang/test/SemaCXX/cxx2c-attributes.cpp
@@ -1,8 +1,9 @@
-// RUN: %clang_cc1 -x c++ -std=c++11 -triple x86_64-pc-linux -fsyntax-only
-// RUN: %clang_cc1 -x c++ -std=c++11 -triple x86_64-windows-msvc -fsyntax-only
+// RUN: %clang_cc1 %s -x c++ -std=c++11 -triple x86_64-pc-linux -fsyntax-only -verify -Wno-c++17-extensions
+// RUN: %clang_cc1 %s -x c++ -std=c++11 -triple x86_64-windows-msvc -fsyntax-only -verify=msvc -Wno-c++17-extensions
+// expected-no-diagnostics
 
 // Check we return non-zero values for supported attributes as per
-// wg21.link/p2552r3.pdf
+// wg21.link/P2552
 static_assert(__has_cpp_attribute(assume));
 
 // The standard does not prescribe a behavior for [[carries_dependency]]
@@ -15,9 +16,5 @@ static_assert(__has_cpp_attribute(maybe_unused));
 static_assert(__has_cpp_attribute(nodiscard));
 static_assert(__has_cpp_attribute(noreturn));
 
-#ifdef _MSC_VER
 // We do not support [[no_unique_address]] in MSVC emulation mode
-static_assert(__has_cpp_attribute(no_unique_address) == 0);
-#else
-static_assert(__has_cpp_attribute(no_unique_address));
-#endif
+static_assert(__has_cpp_attribute(no_unique_address)); // msvc-error {{static assertion failed}}



More information about the cfe-commits mailing list