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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2016-06-14
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |msebor at gcc dot gnu.org
             Blocks|                            |55004
     Ever confirmed|0                           |1
      Known to fail|                            |4.9.3, 5.3.0, 6.1.0, 7.0

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed, though only the xxx initialization is rejected with GCC 5 and later,
the array case works (4.9.3 rejects both xx and xxx).  It looks like the
fold_comparison function that handles these operations for arrays isn't
prepared to do the same for a string literal.  Below is the test with the
failing case simplified to converting a POINTER_PLUS expression directly to
bool.  (The -Waddress warning should probably get its own bug.)

I CC Jakub who has been making improvements in this area lately (bug 71448 and
bug 67376 before it).

$ cat t.C && /home/msebor/build/gcc-trunk-svn/gcc/xgcc -B
/home/msebor/build/gcc-trunk-svn/gcc -Wall -Wextra -Wpedantic t.C
constexpr int n[42] = {1};
constexpr int x = n ? 1 : 0;           // Accepted
constexpr int xx = n + 1 ? 1 : 0;      // Accepted 
constexpr int xxx = "abc" + 1 ? 1 : 0; // Rejected

constexpr bool b = "abc" + 1;          // Rejected (#2)
t.C:2:27: warning: the address of ‘n’ will always evaluate as ‘true’
[-Waddress]
 constexpr int x = n ? 1 : 0; // Accepted.
                           ^
t.C:4:37: error: ‘((((const char*)"abc") + 1u) != 0u)’ is not a constant
expression
 constexpr int xxx = "abc" + 1 ? 1 : 0; // Rejected
                                     ^
t.C:6:28: error: ‘((((const char*)"abc") + 1u) != 0u)’ is not a constant
expression
 constexpr bool b = "abc" + 1;          // Rejected (#2)
                            ^


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55004
[Bug 55004] [meta-bug] constexpr issues

Reply via email to