Question Details

No question body available.

Tags

c++ language-lawyer c++20 constexpr

Answers (1)

June 15, 2026 Score: 4 Rep: 50,964 Quality: Medium Completeness: 100%

The operands of != goes through lvalue to rvalue conversion as per expr.compound:

The == (equal to) and the != (not equal to) operators group left-to-right. The lvalue-to-rvalue ([conv.lval]), array-to-pointer ([conv.array]), and function-to-pointer ([conv.func]) standard conversions are performed on the operands. The comparison is deprecated if both operands were of array type prior to these conversions ([depr.array.comp]).

Moreover, none of the lvalue to rvalue exceptions or any other exceptions from the list given in expr.const are satisfied:

An expression E is a core constant expression unless the evaluation of E, following the rules of the abstract machine ([intro.execution]), would evaluate one of the following:

  • an lvalue-to-rvalue conversion unless it is applied to
    • a non-volatile glvalue that refers to an object that is usable in constant expressions, or
    • a non-volatile glvalue of literal type that refers to a non-volatile object whose lifetime began within the evaluation of E;
  • an lvalue-to-rvalue conversion that is applied to a glvalue that refers to a non-active member of a union or a subobject thereof;
  • an lvalue-to-rvalue conversion that is applied to an object with an indeterminate value;

Thus, there is there is nothing here that bars the use of != here in staticassert. So the program is well-formed.


Here is the newly submitted gcc bug:

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