This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/58969] bogus error: the value of 'kName' is not usable in a constant expression
- From: "ktietz at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 11 Dec 2014 10:36:46 +0000
- Subject: [Bug c++/58969] bogus error: the value of 'kName' is not usable in a constant expression
- Auto-submitted: auto-generated
- References: <bug-58969-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58969
--- Comment #3 from Kai Tietz <ktietz at gcc dot gnu.org> ---
(In reply to Richard Smith from comment #2)
> (In reply to Kai Tietz from comment #1)
> > Hmm, issue seems to be in too restrictive decl_maybe_constant_var_p function.
>
> I don't know how the GCC code is structured, but I don't think that's right;
> that function appears to be checking whether the value of the variable can
> be used in a constant expression. The relevant condition here is whether the
> address of the variable can be used.
hmm, this function has nothing to do with its value. AFAIU the comment (and
its use) it just checks that a VAR-decl might be a constant.
In general it checks for const and volatile attributes, and assumes for
integral/enumeral typed variables that variable is constant.
So a 'const char *' isn't constant - as just the destination the variable is
pointing to is constant, but not the variable itself. For a constant array
with trivial destructor, and non-vla size this is different. The array's name
is indeed a constant address, and its content is constant too. Of course the a
variable pointing to into an array isn't constant, but the array itself is.
Anyway I might be wrong here