[llvm-bugs] [Bug 47555] New: Inherited constructor unusable for constexpr static member of class template

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 16 15:01:28 PDT 2020


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

            Bug ID: 47555
           Summary: Inherited constructor unusable for constexpr static
                    member of class template
           Product: clang
           Version: 10.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: feodor.alexeev 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

Given the code (godbolt link https://godbolt.org/z/dc1G1W):


struct Storage {
    explicit constexpr Storage(int) {}
};

struct Derived : Storage {
    using Storage::Storage;
};

// static Derived kInstance{1};

template<typename>
struct Template {
    static constexpr Derived kDerived{0};
};


Both clang 10.0.1 and current clang trunk (reported as 12.0.0) on Compiler
Explorer emit the following error:


<source>:13:30: error: constexpr variable 'kDerived' must be initialized by a
constant expression
    static constexpr Derived kDerived{0};
                             ^~~~~~~~~~~
<source>:13:30: note: constructor inherited from base class 'Storage' cannot be
used in a constant expression; derived class cannot be implicitly initialized
<source>:6:20: note: declared here
    using Storage::Storage;
                   ^


Worth noting, uncommenting the line "static Derived kInstant{1};" or commenting
out "template<typename>" makes code compile.

-- 
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/20200916/9b97868d/attachment.html>


More information about the llvm-bugs mailing list