https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125732

            Bug ID: 125732
           Summary: ICE when using typeid after a custom, invalid
                    definition of std::type_info is provided and
                    bits/exception_ptr.h is included
           Product: gcc
           Version: 16.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: programmer00001h at gmail dot com
  Target Milestone: ---

Created attachment 64706
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64706&action=edit
output of -freport-bug

GCC crashes for this code (preprocessed version attached):

#define _TYPEINFO
#include<bits/exception_ptr.h>
namespace std{
    struct type_info{};
}
int main(){
    typeid(0);
    return 0;
}

compiling just as `g++ ice.cpp` will trigger the bug.

Note that including bits/exception_ptr.h is necessary to get the crash. Of
course, including other stdlib headers that indirectly include this also causes
the crash.

Backtrace:

ce.cpp: In function ‘int main()’:
ice.cpp:7:12: internal compiler error: in typeid_ok_p, at cp/rtti.cc:338
    7 |     typeid(0);
      |            ^
0x27e6438 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x27e8a47 internal_error(char const*, ...)
        ???:0
0x737816 fancy_abort(char const*, int, char const*)
        ???:0
0x9c3e8f build_typeid(tree_node*, int)
        ???:0
0xaaa200 c_common_parse_file()
        ???:0


Output of gcc -v:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/16.1.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust,cobol
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --enable-cet=auto --enable-checking=release
--enable-clocale=gnu --enable-default-pie --enable-default-ssp
--enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-werror --disable-fixincludes
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.1.1 20260430 (GCC)

Reply via email to