[Bug c++/59937] [constexpr] bogus diagnostic "used in its own initializer"

2015-01-14 Thread jota.uve at hotmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59937

Javier V. Gómez  changed:

   What|Removed |Added

 CC||jota.uve at hotmail dot com

--- Comment #2 from Javier V. Gómez  ---
I found another case that worked in G++ 4.8.3 but fails in 4.9:

-
main.cpp: 
-
int main ()
{
constexpr int n = 2;
A a;
B b;
b.foo();
}

-
a.hpp: 
-
template  class A
{
static constexpr size_t getN() {return n;}
};

-
b.hpp: 
-
class B 
{
void foo ()
{
//has access to a A object
constexpr int n = a.getN();
A a2;
}
};


Compiler output:
B.hpp: error: the value of ‘n’ is not usable in a constant expression
 A a2;
   ^
B.hpp: note: ‘ndims’ used in its own initializer
 constexpr int n = a.getN();
   ^

[Bug c++/59937] [constexpr] bogus diagnostic "used in its own initializer"

2015-01-14 Thread jota.uve at hotmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59937

--- Comment #4 from Javier V. Gómez  ---
(In reply to Jonathan Wakely from comment #3)
> (In reply to Javier V. Gómez from comment #2)
> > I found another case that worked in G++ 4.8.3 but fails in 4.9:
> 
> This example is complete nonsense. Why is it split across three files? Why
> doesn't main.cpp include anything? Why is everything private? Why is 'a'
> undeclared in B::foo()? Why does the diagnostic talk about 'ndims' which
> isn't declared anywhere?
> 
> It's useless as a test or an example of the error.

I tried to simplify as much as possible the issue, since I detected the error
in a big piece of code. I didn't pretend to create a compilable example. ndims
is what I called n (copy and paste...).

The important point of my example is that constexpr int n = a.getN(); fails
when A::getN() just returns a template parameter value previously set by a
constexpr anywhere else.