[clang] [Sema] Fix handling of fields with initializers in nested anonymous unions. (PR #91692)
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 3 17:44:35 PDT 2024
================
@@ -77,3 +77,38 @@ namespace use_self {
int fib(int n) { return FibTree{n}.v; }
}
+
+namespace nested_union {
+ union Test1 {
+ union {
+ int inner { 42 };
+ };
+ int outer;
+ };
+ static_assert(Test1{}.inner == 42, "");
+ struct Test2 {
+ union {
+ struct {
+ int inner : 32 { 42 }; // expected-warning {{C++20 extension}}
+ };
+ int outer;
+ };
+ };
+ static_assert(Test2{}.inner == 42, "");
----------------
zygoloid wrote:
Might be useful to also test that the rest of the union member gets initialized.
```suggestion
struct Test2 {
union {
struct {
int inner : 32 { 42 }; // expected-warning {{C++20 extension}}
int inner_no_init;
};
int outer;
};
};
static_assert(Test2{}.inner == 42, "");
static_assert(Test2{}.inner_no_init == 0, "");
```
https://github.com/llvm/llvm-project/pull/91692
More information about the cfe-commits
mailing list