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:
// 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)).
The generated implicit deduction guide is invalid for nested (inner) class template where:
Sample:
For more sophisticated deduction the invalid CTAD / generated deduction guide can cause compiler crash (SIGSEGV on Linux, Access Violation on Windows (
clang-cl)).