[cfe-dev] clang++: Handling of division by zero in array bounds

Stephan Bergmann via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 8 23:55:05 PST 2016


What I observe with various versions of Clang:

> $ cat test.cc
> #include <iostream>
> int main() {
>     char a[1/0];
>     std::cout << sizeof a << '\n';
> }
>
> $ clang++ -Weverything test.cc
> test.cc:3:11: warning: variable length arrays are a C99 feature
>       [-Wvla-extension]
>     char a[1/0];
>           ^
> test.cc:3:11: warning: variable length array used [-Wvla]
> 2 warnings generated.
>
> $ ./a.out
> 0

Is there a specific reason to not emit a warning/error about the 
undefined behavior in evaluating the constant bounds expression, 1/0?



More information about the cfe-dev mailing list