This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/71504] New: bogus error: accessing value through a glvalue in a constant expression


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

            Bug ID: 71504
           Summary: bogus error: accessing value through a glvalue in a
                    constant expression
           Product: gcc
           Version: 7.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: ---

All recent versions of G++ fail to compile the following well-formed program
with the error below.  Clang compiles it fine, as does EDG eccp 4.11 (though
eccp issues a bogus "subscript out of range" warning).

$ cat zzz.c && /home/msebor/build/gcc-trunk-svn/gcc/xgcc -B
/home/msebor/build/gcc-trunk-svn/gcc -Wall -Wextra -Wpedantic -fpermissive
-fdump-tree-gimple=/dev/stdout -xc++ zzz.c
typedef const char A4 [10];

constexpr A4 a [] = { "123", "123456", "123456789" };

constexpr int len (const char *s)
{
  return *s ? 1 + len (s + 1) : 0;
}

constexpr const char *s = a [0];
constexpr const char *t = (a + 2)[-2];

constexpr int n0 = len (s);
constexpr int n1 = len (t);

constexpr int n2 = len (a [0]);
constexpr int n3 = len ((a + 2)[-2]);

#define A(e) static_assert ((e), #e)

A (n0 == 3);
A (n0 == n1);
A (n0 == n2);
A (n0 == n3);

zzz.c:14:24:   in constexpr expansion of âlen(((const char*)(& a)))â
zzz.c:14:26: error: accessing value of âaâ through a âconst charâ glvalue in a
constant expression
 constexpr int n1 = len (t);
                          ^
zzz.c:17:24:   in constexpr expansion of âlen(((const char*)((const char
(*)[10])(& a))))â
zzz.c:17:36: error: accessing value of âaâ through a âconst charâ glvalue in a
constant expression
 constexpr int n3 = len ((a + 2)[-2]);
                                    ^

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]