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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to