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

            Bug ID: 120112
           Summary: -Weffc++ -Wmismatched-tags -Wrestrict -Wsystem-headers
                    leads to internal_error
           Product: gcc
           Version: 15.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: joo.peter at gmail dot com
  Target Milestone: ---

Created attachment 61312
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61312&action=edit
uncompressed size: 5MB

The minimal example is this main.cpp:


    #include <boost/test/unit_test.hpp>
    #include <boost/icl/ptime.hpp>
    #include <boost/icl/interval_map.hpp>

    using namespace std;
    using namespace boost::posix_time;
    using namespace boost::icl;

    interval_map<ptime, std::set<string>> f()
    {
        interval_map<ptime, std::set<string>> x;
        return x;
    }

The compilation command which triggers the problem:


    1) using godbolt's gcc 15.1.0:
           -Weffc++ -Wmismatched-tags -Wrestrict -Wsystem-headers
       live demo: https://godbolt.org/z/3Pxn81dT5

    2) step-by-step reproduction in my arch linux using gcc 14.2.1:
           cd $HOME
           mkdir ./gcc_bug
           cd    ./gcc_bug
           git clone 'https://github.com/boostorg/boost.git' .
           git checkout 'boost-1.87.0'
           git submodule update --init --force --recursive --jobs=8192
           g++ -I $HOME/gcc_bug -c
$HOME/gcc_bug/libs/icl/test/ex_boost_party_/ex_boost_party.cpp -o /dev/null
-Weffc++ -Wmismatched-tags -Wrestrict -Wsystem-headers -Wtautological-compare

The internal_error in gcc's output is this:


    /opt/compiler-explorer/gcc-15.1.0/include/c++/15.1.0/debug/debug.h:61:12:
warning: '__gnu_debug::_Safe_iterator<_Iterator, _Sequence, _Category>'
declared with a mismatched class-key 'struct' [-Wmismatched-tags]
       61 |     struct _Safe_iterator;
          |            ^~~~~~~~~~~~~~
    /opt/compiler-explorer/gcc-15.1.0/include/c++/15.1.0/debug/debug.h:61:12:
note: replace the class-key with 'class'
   
/opt/compiler-explorer/gcc-15.1.0/include/c++/15.1.0/bits/stl_iterator.h:2986:11:
note: '__gnu_debug::_Safe_iterator<_Iterator, _Sequence, _Category>' first
declared as 'class' here
     2986 |     class _Safe_iterator;
          |           ^~~~~~~~~~~~~~
    <source>: In substitution of 'template<class Type> struct
boost::icl::map<DomainT, CodomainT, Traits, Compare, Combine, Section,
Alloc>::on_total_absorbable<Type, true, true> [with Type =
boost::icl::map<DomainT, CodomainT, Traits, Compare, Combine, Section,
Alloc>]':
    <source>:13:1:   required from here
       13 | }
          | ^
    <source>:13:1: internal compiler error: Segmentation fault
    0x2287465 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
    0x22989b6 internal_error(char const*, ...)
        ???:0
    0x9ab902 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
    0x9b2467 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ???:0
    0x9b2701 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ???:0
    0x9ab51b tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
    0x99eb8f most_specialized_partial_spec(tree_node*, int, bool)
        ???:0
    0x92aa3c class_decl_loc_t::diag_mismatched_tags(tree_node*)
        ???:0
    0x930f63 class_decl_loc_t::diag_mismatched_tags()
        ???:0
    0x981f15 c_parse_file()
        ???:0
    0xa8b739 c_common_parse_file()
        ???:0
    Please submit a full bug report, with preprocessed source (by using
-freport-bug).
    Please include the complete backtrace with any bug report.
    See <https://gcc.gnu.org/bugs/> for instructions.


Please note that removing either warning will make the error disappear.
I repeat, if I remove either:
    -Weffc++
        OR
    -Wmismatched-tags
        OR
    -Wrestrict
        OR
    -Wsystem-headers
        OR
    -Wtautological-compare
then the bug disappears.
There can be other factors too. Se even though these reproduction steps seem
precise and exact, but maybe they could seem fragile by others. Maybe it is a
Heisenbug, I really don't know what is going on, what warning flag, code line,
or other factor is the culprit here.

I used the -freport-bug too, attached as freport-bug.txt.gz, as the text says.

Reply via email to