https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106029
Bug ID: 106029 Summary: gcc doesn't report full stack trace for static_assert() Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: realazthat at gmail dot com Target Milestone: --- Created attachment 53165 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53165&action=edit symbol.cxx When triggering a static_assert within the standard library, clang prints a stack-trace of the instantiation that triggered the assert, but every file/line it lists in the trace is not in user code (rather, it is within stdlib), which makes it extraordinarily difficult to debug ( kinds of traces are very famously difficult to read in the first place, there is no reason to make it nearly impossible!). In the code below, const std::optional<std::vector<std::optional<Thing>>> &d = c; is invalid instantiation because Thing is not copy constructible, and this forces the optional not to be copy constructible, yet the only possible thing to do here is to make a copy, so it asserts. However, the error does not point to this line, and in a large amount of code I required creduce to pinpoint this. ### Code symbol.cxx: ``` #include <vector> #include <optional> struct Thing { Thing() = delete; Thing(const Thing&) = delete; Thing& operator=(const Thing&) = delete; Thing& operator=( Thing&&); Thing(Thing&&); }; void b() { std::vector<std::optional<Thing>> c; // The following line instantiates the static_assert failure, // but it is not listed in the error. const std::optional<std::vector<std::optional<Thing>>> &d = c; } ``` ### Compile command ``` $g++-11 symbol.cxx -std=c++20 ``` ### Output In file included from /usr/include/c++/11/vector:66, from symbol.cxx:2: /usr/include/c++/11/bits/stl_uninitialized.h: In instantiation of ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::optional<Thing>*, std::vector<std::optional<Thing> > >; _ForwardIterator = std::optional<Thing>*]’: /usr/include/c++/11/bits/stl_uninitialized.h:333:37: required from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::optional<Thing>*, std::vector<std::optional<Thing> > >; _ForwardIterator = std::optional<Thing>*; _Tp = std::optional<Thing>]’ /usr/include/c++/11/bits/stl_vector.h:558:31: required from ‘std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::optional<Thing>; _Alloc = std::allocator<std::optional<Thing> >]’ /usr/include/c++/11/optional:225:8: required from ‘constexpr std::_Optional_payload_base<_Tp>::_Storage<_Up, false>::_Storage(std::in_place_t, _Args&& ...) [with _Args = {std::vector<std::optional<Thing>, std::allocator<std::optional<Thing> > >&}; _Up = std::vector<std::optional<Thing> >; _Tp = std::vector<std::optional<Thing> >]’ /usr/include/c++/11/optional:116:4: required from ‘constexpr std::_Optional_payload_base<_Tp>::_Optional_payload_base(std::in_place_t, _Args&& ...) [with _Args = {std::vector<std::optional<Thing>, std::allocator<std::optional<Thing> > >&}; _Tp = std::vector<std::optional<Thing> >]’ /usr/include/c++/11/optional:358:42: required from here /usr/include/c++/11/bits/stl_uninitialized.h:138:72: error: static assertion failed: result type must be constructible from value type of input range 138 | static_assert(is_constructible<_ValueType2, decltype(*__first)>::value, | ^~~~~ /usr/include/c++/11/bits/stl_uninitialized.h:138:72: note: ‘std::integral_constant<bool, false>::value’ evaluates to false ``` ### Expected output An additional line like this: ``` /path/to/symbol.cxx:16:2: required from here ``` ### GCC Version ``` $g++-11 --v Using built-in specs. COLLECT_GCC=g++-11 COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.1.0-1ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --disable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-2V7zgg/gcc-11-11.1.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-2V7zgg/gcc-11-11.1.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.1.0 (Ubuntu 11.1.0-1ubuntu1~20.04) ``` ```$ apt show g++-11 Package: g++-11 Version: 11.1.0-1ubuntu1~20.04 Priority: optional Section: devel Source: gcc-11 Maintainer: Ubuntu Core developers <ubuntu-devel-disc...@lists.ubuntu.com> Original-Maintainer: Debian GCC Maintainers <debian-...@lists.debian.org> Installed-Size: 29.4 MB Provides: c++-compiler, c++abi2-dev Depends: gcc-11-base (= 11.1.0-1ubuntu1~20.04), gcc-11 (= 11.1.0-1ubuntu1~20.04), libstdc++-11-dev (= 11.1.0-1ubuntu1~20.04), libc6 (>= 2.14), libgmp10 (>= 2:5.0.1~), libisl22 (>= 0.15), libmpc3, libmpfr6 (>= 3.1.3), libzstd1 (>= 1.3.2), zlib1g (>= 1:1.1.4) Suggests: g++-11-multilib, gcc-11-doc (>= 11) Download-Size: 10.5 MB APT-Manual-Installed: yes APT-Sources: http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 Packages Description: GNU C++ compiler This is the GNU C++ compiler, a fairly portable optimizing compiler for C++. ``` ### **OS:** Ubuntu over WSL (Windows Subsystem for Linux) **lsb_release -a** ``` $lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.4 LTS Release: 20.04 Codename: focal ```