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++/59937] [constexpr] bogus diagnostic "used in its own initializer"


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

Javier V. GÃmez <jota.uve at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jota.uve at hotmail dot com

--- Comment #2 from Javier V. GÃmez <jota.uve at hotmail dot com> ---
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<n> a;
    B b;
    b.foo();
}

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

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


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

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