[LLVMbugs] [Bug 13517] New: Static constexpr definitions used inside template

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 2 09:49:40 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13517

             Bug #: 13517
           Summary: Static constexpr definitions used inside template
           Product: clang
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: pfultz2 at yahoo.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


When I define a static member using auto and constepxr like this:

struct L
{
    void operator()() const
    {}
};

struct A
{
    static constexpr auto F = L();
};

constexpr decltype(A::F) A::F;

int main()
{
    A::F();
    return 0;
}

This compiles fine, but when I make the class A, a template like this:

struct L
{
    void operator()() const
    {}
};

template<class X>
struct A
{
    static constexpr auto F = L();
};

template<class X>
constexpr decltype(A<X>::F) A<X>::F;

int main()
{
    A<void>::F();
    return 0;
}

Clang crashes, if I change the definition line for F to this:

template<class X>
constexpr typename std::remove_const<decltype(A<X>::F)>::type A<X>::F;

Then clang produces this error:

error: redefinition of 'F' with a different type
constexpr typename std::remove_const<decltype(A<X>::F)>::type A<X>::F;
                                                                    ^
note: previous definition is here
    static constexpr auto F = L();
                          ^

It seems that clang thinks that this is a declaration instead of a definition.

Also, does C++ require the definition outside of the class? It would be nicer
when using constexpr and auto, just to have the the static member defined at
the point of declaration.(like it is for integers), but perhaps that is not
conformant with C++11.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list