Issue 146879
Summary [clang++] Error when inspect the common initial sequence of standard-layout structs of the union
Labels clang
Assignees
Reporter safocl
    Code
```cpp
consteval void foo(){
    union { struct {int i1; int i2; int i3; int i4;} s;
 struct {int i1; int i2; int i3; int i4;} s2;
            int i[4];
 } u{};
                
    auto sum = u.s2.i1+u.s2.i1+u.s2.i1+u.s2.i1;
}

int main(){
 foo();
}
```

produces error with 
```
note: read of member 's2' of union with active member 's' is not allowed in a constant _expression_
    7 | auto sum = u.s2.i1+u.s2.i1+u.s2.i1+u.s2.i1;
      | ^
```

https://godbolt.org/z/dcPWW8ncx
(this tested from clang-x86_64 10.0.0 to clang-x86_64 20.1.0 and trunk version on godbolt)

but:
https://eel.is/c++draft/class.union#general-note-1
https://eel.is/c++draft/class.mem#general-27
https://eel.is/c++draft/class.prop#10
https://eel.is/c++draft/class.mem#def:layout-compatible,class

the `s` and `s2` union members are two standard-layout struct types and have common initial sequence (and what's more: they are layout-compatible).

in my opinion the error behavior here is a bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to