https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66323
Bug ID: 66323 Summary: runtime error with zero sized std::array using begin and end methods Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: tnozicka at gmail dot com CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org Target Milestone: --- Hi, there is a bug either in undefined behaviour sanitizer or STL. Following code should be valid according to N3797 draft saying: 1. array shall provide support for the special case N == 0. 2. In the case that N == 0, begin() == end() == unique value. But compiling and running following code results in sanitizer error: /opt/szn/include/c++/5.1/array:222:32: runtime error: reference binding to null pointer of type 'int' Compiled and run with gcc 5.1 as: /opt/szn/bin/g++ -std=c++14 -Wall -Wextra -fsanitize=undefined -Wl,-rpath=/opt/szn/lib/gcc/x86_64-linux-gnu/current -o program main.cpp && ./program // === TEST === #include <array> int main() { std::array<int, 0> array{}; array.begin(); array.end(); return 0; } // === END OF TEST === Compiler info: $ /szn/bin/g++ -v Using built-in specs. COLLECT_GCC=/opt/szn/bin/g++ COLLECT_LTO_WRAPPER=/opt/szn/lib/gcc/x86_64-linux-gnu/5.1.0/lto-wrapper Target: x86_64-linux-gnu Configured with: /home/tnozicka/generic/gcc/gcc-5.1.0/configure --prefix=/opt/szn --program-suffix=-5.1 --enable-languages=c++ --disable-multilib --with-default-libstdcxx-abi=c++98 --enable-shared --enable-threads=posix --enable-checking=release --enable-__cxa_atexit --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --with-tune=generic --enable-libstdcxx-time=yes --enable-libstdcxx-debug --enable-version-specific-runtime-libs --enable-objc-gc --enable-clocale=gnu --disable-install-libiberty --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --libdir=/opt/szn/lib --libexecdir=/opt/szn/lib --infodir=/opt/szn/share/info-gcc-5.1 --localedir=/opt/szn/share/locale-gcc-5.1 --mandir=/opt/szn/share/man-gcc-5.1 --with-gxx-include-dir=/opt/szn/include/c++/5.1 Thread model: posix gcc version 5.1.0 (GCC)