[Bug c++/69103] New: Misleading diagnostic for invalid constexpr initialization
rs2740 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Dec 31 21:00:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69103
Bug ID: 69103
Summary: Misleading diagnostic for invalid constexpr
initialization
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rs2740 at gmail dot com
Target Milestone: ---
Consider:
static int i;
static int* temp = &i;
static constexpr int *&&r = static_cast<int*&&>(temp) + 1;
This correctly doesn't compile, but produces the misleading error message
prog.cc:3:57: error: modification of '_ZGRL1r0' is not a constant-expression
static constexpr int *&&r = static_cast<int*&&>(temp) + 1;
^
We aren't modifying anything in the initializer.
In contrast, Clang produces:
prog.cc:3:25: error: constexpr variable 'r' must be initialized by a constant
expression
static constexpr int *&&r = static_cast<int*&&>(temp) + 1;
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cc:3:29: note: read of non-constexpr variable 'temp' is not allowed in a
constant expression
static constexpr int *&&r = static_cast<int*&&>(temp) + 1;
^
prog.cc:2:13: note: declared here
static int* temp = &i;
More information about the Gcc-bugs
mailing list