[Bug c++/86228] ordered comparison between pointer and zero
eracpp at eml dot cc
gcc-bugzilla@gcc.gnu.org
Sat Dec 8 13:56:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86228
eracpp <eracpp at eml dot cc> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |eracpp at eml dot cc
--- Comment #2 from eracpp <eracpp at eml dot cc> ---
This bug was observed in the following example:
https://gcc.godbolt.org/z/p1VreP
#include <algorithm>
#include <array>
int main()
{
std::array<int, 3> arr;
// Mistake: meant to use std::generate.
std::generate_n(arr.begin(), arr.end(), []{ return 0; });
}
This code successfully compiles (unexpectedly) with GCC due to `size > 0` being
treated as well-formed in the case where the type of second parameter `size` is
deduced to be a pointer type such as `int*`. The contrary behavior is observed
with Clang, as seen in the provided Compiler Explorer link above.
The mistake manifests as an unexpected segmentation fault at runtime, rather
thana compile-time error:
http://coliru.stacked-crooked.com/a/2dc4ae877233c9b2
More information about the Gcc-bugs
mailing list