-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang++] Does not error with a zero length array declaration (definition) #121398
Comments
@llvm/issue-subscribers-clang-frontend Author: None (safocl)
Clang++ allows declaration (definition) of arrays of zero size (`TYPE NAME[0]`). However, this is prohibited by the c++ standard:
[c++23] ([here](https://timsong-cpp.github.io/cppwp/n4950/dcl.array#1.sentence-3))
```
In a declaration T D where D has the form
D1 [ constant-expression opt ] attribute-specifier-seq opt
[...]
The constant-expression shall be a converted constant expression of type std::size_t ([expr.const]).
Its value N specifies the array bound, i.e., the number of elements in the array; N shall be greater than zero.
```
[c++11] ([here](https://timsong-cpp.github.io/cppwp/n3337/dcl.array#1)) [c++17] ([here](https://timsong-cpp.github.io/cppwp/n4659/dcl.array#1)) Example :
Expected behavior Current behavior |
Note: If you use
|
This error is a limitation of the core language - it should work without additional compiler options (which only help to generate correct code). https://godbolt.org/z/1TfPEcr1f -- it does error for the
|
This is a GNU extension: #54705 There is some question as to why this allowed outside of a flexible array context but I am not sure how much appetite there would be to change this as we would need to coordinate with both gcc/edg. I am going to close this but perhaps in the future someone might want to consider thinking about this. |
Clang++ allows declaration (definition) of arrays of zero size (
TYPE NAME[0]
). However, this is prohibited by the c++ standard:[c++23] (here)
[c++11] (here)
[c++17] (here)
Example :
Expected behavior
COMPILETIME ERROR.
Current behavior
Compilation completed without errors.
The text was updated successfully, but these errors were encountered: