[clang] [Clang] Implement C++26 Attributes for Structured Bindings (P0609R3) (PR #89906)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 25 07:08:56 PDT 2024


================
@@ -102,11 +102,21 @@ namespace PR33839 {
     for (auto [x] : a) { // expected-warning {{unused variable '[x]'}}
     }
   }
-  void use() { 
+  void use() {
     f<int>(); // expected-note {{instantiation of}}
     g<true>();
     g<false>();
     h<int>(); // expected-note {{instantiation of}}
   }
 }
+
+namespace maybe_unused_binding {
+
+void test() {
+  struct X { int a, b; } x;
+  auto [a [[maybe_unused]], b] = x; // expected-warning {{an attribute specifier sequence attached to a structured binding declaration is a C++2c extension}}
----------------
erichkeane wrote:

Are there any standard attributes other than this that make sense on SB's?  If not, I'd like all of the standards ones tested to show what the behavior is (and 'not valid here' type errors are totally acceptable).

`[[indeterminate]]` seems useful, but  the rest should likely result in a rejection.

Additionally, we should do an audit of ALL our "C++" spelling attributes to see which make sense here and to make sure they are treated reasonably.  I'm not asking to do that HERE, but a bug in our bug tracker (perhaps with a 'good starter bug' tag, particularly if we list ALL our attributes that need auditing) would be acceptable.

https://github.com/llvm/llvm-project/pull/89906


More information about the cfe-commits mailing list