Issue 204017
Summary [CTAD] Generated implicit deduction guides fails
Labels
Assignees
Reporter 666kod666
    The generated implicit deduction guide is invalid for nested (inner) class template where:
* C++20+ standard is used.
* outer class is also class template.
* constructor matching invocation contains reference to outer class as parameter (in short form).

Sample:
```cpp
// clang/gcc: -std=c++20 -Wall -O2 -pedantic
// msvc:      -std:c++20 -W4 -O2

#include <functional>

template <typename T>
struct A
{
    template <typename U>
    struct B
    {
        B(A& a, U& b)
            : m_a(std::ref(a)), m_b(std::ref(b))
        {}

 std::reference_wrapper<A> m_a;
        std::reference_wrapper<U> m_b;
 };

    // Generated implicit deduction is invalid and in more
    // complicated scenarios causes compiler to crash.
    // The implicit guide is correctly generated on
    // msvc and gcc.
    //
    // If you uncomment this explicit guide it will work:
    // template <typename U> B(A&, U&) -> B<U>;

    void fun()
    {
        int a = 1;

        B b1{*this, a};
    }
};

int main()
{
    A<long> a;
 a.fun();
}

```

For more sophisticated deduction the invalid CTAD / generated deduction guide can cause compiler crash (SIGSEGV on Linux, Access Violation on Windows (`clang-cl`)).

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to