[llvm-bugs] [Bug 49410] New: constexpr static data member template cause an error: static data member 'v' already has an initializer

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 3 07:05:09 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=49410

            Bug ID: 49410
           Summary: constexpr static data member template cause an error:
                    static data member 'v' already has an initializer
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: danny321974345 at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

When compile the constexpr variable template below with option -std=c++14

struct A {
    template <typename T>
    static constexpr T v{};
};
template <typename T>
constexpr T A::v;

int main()
{
    auto ptr1 = &A::v<int>;
    auto ptr2 = &A::v<int>;  // no error if remove this line
}


generates the error below:

clang_cxx14.cpp:3:25: error: static data member 'v' already has an initializer
    static constexpr T v{};
                        ^
clang_cxx14.cpp:10:21: note: in instantiation of static data member 'A::v<int>'
requested here
    auto ptr1 = &A::v<int>;
                    ^
clang_cxx14.cpp:3:25: note: previous initialization is here
    static constexpr T v{};
                        ^
1 error generated.

No error in -std=c++17 or above

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210303/d9a07955/attachment.html>


More information about the llvm-bugs mailing list