Issue 135142
Summary Clang accepts illegal flexible array member inside struct used in std::vector
Labels clang
Assignees
Reporter GINN-Imp
    https://godbolt.org/z/brW45GE3h
Clang -std=c++17 -pedantic accepts the following code:
```cpp
#include <vector>

struct Bad {
    struct {} i[];
};

int main() {
 std::vector<Bad> v;
}
```

Expected (GCC):
```
In file included from /opt/compiler-explorer/gcc-trunk-20250409/include/c++/15.0.1/vector:68,
 from <source>:1:
/opt/compiler-explorer/gcc-trunk-20250409/include/c++/15.0.1/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = Bad; _Alloc = std::allocator<Bad>]':
/opt/compiler-explorer/gcc-trunk-20250409/include/c++/15.0.1/bits/stl_vector.h:561:7: required from here
  561 |       vector() = default;
      | ^~~~~~
/opt/compiler-explorer/gcc-trunk-20250409/include/c++/15.0.1/bits/stl_vector.h:376:49: error: arithmetic on pointer to an empty aggregate
  376 | _M_impl._M_end_of_storage - _M_impl._M_start);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
Compiler returned: 1
```


_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to