From b854ce130ebbfdf2f882ef08538746030513b44b Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sat, 26 Mar 2022 23:54:22 -0400 Subject: [PATCH] c++: CTAD and member alias template [PR102123] When building a deduction guide from the Test constructor, we need to rewrite the use of _dummy into a dependent reference, i.e. Test::template _dummy. We were using SCOPE_REF for both type and non-type templates; we need to use UNBOUND_CLASS_TEMPLATE for type templates. PR c++/102123 gcc/cp/ChangeLog: * pt.cc (tsubst_copy): Use make_unbound_class_template for rewriting a type template reference. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/class-deduction110.C: New test. --- gcc/cp/pt.cc | 3 ++ .../g++.dg/cpp1z/class-deduction110.C | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction110.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 41f1ef1f64d9..678063f6e4cc 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -17021,6 +17021,9 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) /* When rewriting a constructor into a deduction guide, a non-dependent name can become dependent, so memtmpl becomes context::template memtmpl. */ + if (DECL_TYPE_TEMPLATE_P (t)) + return make_unbound_class_template (context, DECL_NAME (t), + NULL_TREE, complain); tree type = tsubst (TREE_TYPE (t), args, complain, in_decl); return build_qualified_name (type, context, DECL_NAME (t), /*template*/true); diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction110.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction110.C new file mode 100644 index 000000000000..8eb56478fe94 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction110.C @@ -0,0 +1,28 @@ +// PR c++/102123 +// { dg-do compile { target c++17 } } + +template typename Template, typename... Args> +struct _dummy_forwarder { + using type = Template; +}; + +template typename Template, typename... Args> +using dummy_forwarder = typename _dummy_forwarder::type; + +template +struct Test { + template using _dummy = U; + + using Element = dummy_forwarder<_dummy, T>; + + Element _elem; + + constexpr Test(const Element elem) : _elem(elem) { } +}; + +template +Test(T) -> Test; + +void test() { + const auto t = Test(1); +} -- 2.47.2