[clang] [Clang][RFC] Introduce a trait to determine the structure binding size (PR #131515)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 18 08:03:44 PDT 2025


================
@@ -0,0 +1,182 @@
+// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify
+// RUN: %clang_cc1 %s -std=c++2c -fsyntax-only -verify -fexperimental-new-constant-interpreter
+
+
+struct S0 {};
+struct S1 {int a;};
+struct S2 {int a; int b;};
+struct S3 {double a; int b; int c;};
----------------
AaronBallman wrote:

Test with bit-fields? Test with unnamed bit-field? Test with an anonymous union member? Test with a flexible array member? Test where the structure being decomposed as a `static_assert` declaration in it (which wouldn't be a member as far as decomposition is concerned)?

What about a monstrosity like:
```
struct S {
  int x;
  int y;

  static_assert(__builtin_structured_binding_size(S) == 2); // ?

  int z;
  static_assert(__builtin_structured_binding_size(S) == 3);
};
```

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


More information about the cfe-commits mailing list