// Test -Wctad-maybe-unsupported. // { dg-do compile { target c++17 } } // { dg-options "-Wctad-maybe-unsupported" } template struct Empty { }; template struct A { A(T); // generates 'template A(T)-> A' A(T, int); // generates 'template A(T, int)-> A' }; // These only succeed because of the implicit guide. That may be // undesired. A a1(42); // { dg-warning "may not intend to support class template argument deduction" } A a2{42}; // { dg-warning "may not intend to support class template argument deduction" } A a3 = {42}; // { dg-warning "may not intend to support class template argument deduction" } template struct B { B(T); B(T, int); }; template B(T, int) -> B>; B b1(42); B b2{42}; B b3 = {42}; // Motivating examples from Stephan Lavavej's 2018 CppCon talk. template struct Pair { T first; U second; explicit Pair(const T &t, const U &u) {} }; // deduces to Pair Pair p1(42, "hello world"); // { dg-warning "may not intend to support class template argument deduction" } Pair p1b{42, "hello world"}; // { dg-warning "may not intend to support class template argument deduction" } template struct Pair2 { T first; U second; explicit Pair2(T t, U u) {} }; // deduces to Pair2 Pair2 p2(42, "hello world"); // { dg-warning "may not intend to support class template argument deduction" } Pair2 p2b{42, "hello world"}; // { dg-warning "may not intend to support class template argument deduction" } template struct Pair3 { T first; U second; explicit Pair3(T const& t, U const& u) {} }; template Pair3(T1, T2) -> Pair3; // deduces to Pair3 Pair3 p3(42, "hello world"); static_assert(__is_same(decltype(p3), Pair3)); // Test that explicit guides suppress the warning even if they // aren't used as candidates. template struct C { C(T) { } }; template explicit C(C const&) -> C; C c{42}; C c2 = c; static_assert(__is_same(decltype(c2), C)); // Clang's suppression test. struct allow_ctad_t { allow_ctad_t() = delete; }; template struct S { S(T) {} }; S(allow_ctad_t) -> S; S s("abc"); S s2{"abc"}; static_assert(__is_same(decltype(s), S)); static_assert(__is_same(decltype(s2), S));