Skip to content
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

[Clang][NFC] Mark P2552 as implemented. #92007

Merged
merged 2 commits into from
May 14, 2024
Merged

Conversation

cor3ntin
Copy link
Contributor

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.

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.
@llvmbot llvmbot added the clang Clang issues not falling into any other category label May 13, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 13, 2024

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/92007.diff

2 Files Affected:

  • (added) clang/test/SemaCXX/cxx2c-attributes.cpp (+23)
  • (modified) clang/www/cxx_status.html (+1-1)
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>

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from a potential improvement to the test for clarity.

static_assert(__has_cpp_attribute(nodiscard));
static_assert(__has_cpp_attribute(noreturn));

#ifdef _MSC_VER
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's more clear to use -verify= instead of using #ifdef so it's clear that we expect the static assertion to fail in MSVC mode, but I don't insist.

@cor3ntin cor3ntin merged commit cff9e77 into llvm:main May 14, 2024
4 checks passed
nhasabni pushed a commit to nhasabni/llvm-project that referenced this pull request May 14, 2024
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.
mub-at-arm pushed a commit to mub-at-arm/llvm-project that referenced this pull request May 16, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants