Question Details

No question body available.

Tags

c++ g++ compiler-bug

Answers (1)

Accepted Answer Available
Accepted Answer
January 23, 2026 Score: 5 Rep: 48,328 Quality: Expert Completeness: 100%

This is a confirmed regression in gcc 15.1 i.e gcc is wrong to reject a well-formed program. Note that gcc's error says 'nullptr' is not a constant expression which is also incorrect because nullptr is actually a constant expression.

This can be seen from expr.const:

  1. Certain contexts require expressions that satisfy additional requirements as detailed in this subclause; other contexts have different semantics depending on whether or not an expression satisfies these requirements. Expressions that satisfy these requirements, assuming that copy elision is not performed, are called constant expressions.

  2. A variable or temporary object o is constant-initialized if

  • either it has an initializer or its default-initialization results in some initialization being performed, and
  • the full-expression of its initialization is a constant expression when interpreted as a constant-expression, except that if o is an object, that full-expression may also invoke constexpr constructors for o and its subobjects even if those objects are of non-literal class types.
  1. A variable is potentially-constant if it is constexpr or it has reference or non-volatile const-qualified integral or enumeration type.
  2. A constant-initialized potentially-constant variable V is usable in constant expressions at a point P if V's initializing declaration D is reachable from P and
  • V is constexpr,
  • V is not initialized to a TU-local value, or
  • P is in the same translation unit as D.

This means that the variable zero is usable as a constant expression(for type std::nullptrt) at the point of the declaration/definition of other_zero.