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

            Bug ID: 121876
           Summary: [16 Regression] recursive ICE in ICE handling with
                    nested diagnostics, in set_diagnostic_buffer, at
                    buffering.cc:49
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: diagnostic, error-recovery, ice-on-invalid-code,
                    needs-bisection, needs-reduction
          Severity: normal
          Priority: P3
         Component: diagnostics
          Assignee: dmalcolm at redhat dot com
          Reporter: dmalcolm at gcc dot gnu.org
                CC: dmalcolm at gcc dot gnu.org, hewillk at gmail dot com,
                    unassigned at gcc dot gnu.org, webrown.cpp at gmail dot com
  Target Milestone: ---

+++ This bug was initially created as a clone of Bug #121859 +++

#include <functional>

struct S {
  static int f();
};

int main() {
  S* s = nullptr;
  std::function_ref<int()> r(std::nontype<&S::f>, s);
}

https://godbolt.org/z/hrjE4e81E

There are two things going on here:

(1) an ICE due to a read-through null in the C++ frontend here: 

VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
at ../../src/gcc/cp/constraint.cc:3363
3363      if (TREE_CODE (expr) == TRAIT_EXPR)

(gdb) list
3363      if (TREE_CODE (expr) == TRAIT_EXPR)
3364        {
3365          diagnose_trait_expr (loc, expr, args);
3366          return true;
3367        }

(gdb) p expr
$1 = <tree 0x0>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

(2) during handling of the above ICE, the diagnostics subsystem attempts to
emit the ICE, but it's already midway through handling a nested diagnostic, and
so during the emission of the internal error, we hit an assertion.

This bug is to track (2) above: the ICE handler needs to gracefully handle the
case of an ICE occurring within a nested diagnostic.

Reply via email to