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

            Bug ID: 104016
           Summary: constexpr folding of std::type_info depends on
                    -fdelete-null-ptr-checks
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

// { dg-options "-std=gnu++23 -fno-delete-null-pointer-checks" }
// { dg-do compile { target c++23 } }
#include <typeinfo>
static_assert( typeid(int) != typeid(long) );

This compiles with the default flags, but -fno-delete-null-pointer-checks
causes it to fail:


ti.C:4:28: error: non-constant condition for static assertion
    4 | static_assert( typeid(int) != typeid(long) );
      |                ~~~~~~~~~~~~^~~~~~~~~~~~~~~
In file included from ti.C:3:
/home/jwakely/gcc/12/include/c++/12.0.0/typeinfo:196:19: error: '(((const
std::type_info*)(& _ZTIi)) == ((const std::type_info*)(& _ZTIl)))' is not a
constant expression
  196 |       return this == &__arg;
      |              ~~~~~^~~~~~~~~


Not a regression, because this code was rejected as ill-formed until very
recently.

Maybe related to PR c++/97913

Reply via email to