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

            Bug ID: 85474
           Summary: unspecified string literal comparison accepted in
                    constexpr context
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

According to [expr.const]:

An expression e is a core constant expression unless the evaluation of e,
following the rules of the abstract machine (4.6), would evaluate one of the
following expressions:
...
--  a relational (8.9) or equality (8.10) operator where the result is
unspecified;

That means that the following program is ill-formed and needs to be rejected
with an error:

$ cat t.C && gcc -S -Wall -Wextra -Wpedantic t.C
constexpr bool b = "" == "";
t.C:1:26: warning: comparison with string literal results in unspecified
behavior [-Waddress]
 constexpr bool b = "" == "";
                          ^~


GCC accepts the program with only a warning when it should reject it with a
hard error as Clang does.

Reply via email to