[llvm-bugs] [Bug 45109] New: Variable template inside the class causes compiler crash

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 5 00:16:41 PST 2020


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

            Bug ID: 45109
           Summary: Variable template inside the class causes compiler
                    crash
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: unixod 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

Created attachment 23204
  --> https://bugs.llvm.org/attachment.cgi?id=23204&action=edit
Clang's stderr + -save-temps

An issue I'm going to describe I've encountered both in Clang 9 and Clang thunk
(https://godbolt.org/z/jffEf_) but not in GCC.

The following code causes compiler crash:

-------snippet(A) begin---------
template<auto>
struct X {};

template<typename T>
class Foo {
private:
    template<auto v>
    static constexpr auto copy = v;   // (1)

public:
    template<auto v>
    Foo(X<v>)
    {
        auto val = copy<v>;
    };
};

int main()
{
    Foo<int> b{X<3>{}};
}
-------snippet(A) end---------

If the variable template (1) is moved out from the class (put above Foo), code
is compiled successfully.

The similar issue happens in a little bit different code (in this case,
compiler isn't crashed, but compilation results in error):

-------snippet(B) begin---------
template<auto>
struct X {};

template<typename T>
class Foo {
private:
    template<auto v>
    static constexpr auto copy = v;   // (1)

public:
    template<auto v>
    Foo(X<v>)
        : val{copy<v>} 
    {};

    T val;
};

int main()
{
    Foo<int> b{X<3>{}};
}
-------snippet(B) end---------

This is again can be worked around by defining a variable template (1) outside
the class.

-- 
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/20200305/6407828f/attachment-0001.html>


More information about the llvm-bugs mailing list