diff options
author | Jason Merrill <jason@redhat.com> | 2022-03-26 22:05:53 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-04-12 16:11:44 -0400 |
commit | 3a17a1842350e7a9a6e81931e8ad66184b33efb2 (patch) | |
tree | de799a8e69fea7652ced41e3bb38a89db8846c1a | |
parent | eea5641912b914f3589ec1ec576a596451180baa (diff) | |
download | gcc-3a17a1842350e7a9a6e81931e8ad66184b33efb2.zip gcc-3a17a1842350e7a9a6e81931e8ad66184b33efb2.tar.gz gcc-3a17a1842350e7a9a6e81931e8ad66184b33efb2.tar.bz2 |
c++: CTAD and member function references [PR103943]
More quirks of rewriting member references to dependent references for
CTAD. A reference to a member of dependent scope is definitely dependent.
And since r11-7044, tsubst_baselink builds a SCOPE_REF, so
tsubst_qualified_id should just use it.
PR c++/103943
gcc/cp/ChangeLog:
* pt.c (tsubst_qualified_id): Handle getting SCOPE_REF from
tsubst_baselink.
(instantiation_dependent_scope_ref_p): Check dependent_scope_p.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1z/class-deduction109.C: New test.
-rw-r--r-- | gcc/cp/pt.c | 21 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/class-deduction109.C | 64 |
2 files changed, 79 insertions, 6 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index aa68dd4..9a999dd 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -16478,12 +16478,20 @@ tsubst_qualified_id (tree qualified_id, tree args, if (dependent_scope_p (scope)) { - if (is_template) - expr = build_min_nt_loc (loc, TEMPLATE_ID_EXPR, expr, template_args); - tree r = build_qualified_name (NULL_TREE, scope, expr, - QUALIFIED_NAME_IS_TEMPLATE (qualified_id)); - REF_PARENTHESIZED_P (r) = REF_PARENTHESIZED_P (qualified_id); - return r; + if (TREE_CODE (expr) == SCOPE_REF) + /* We built one in tsubst_baselink. */ + gcc_checking_assert (same_type_p (scope, TREE_OPERAND (expr, 0))); + else + { + if (is_template) + expr = build_min_nt_loc (loc, TEMPLATE_ID_EXPR, expr, + template_args); + expr = build_qualified_name (NULL_TREE, scope, expr, + QUALIFIED_NAME_IS_TEMPLATE + (qualified_id)); + } + REF_PARENTHESIZED_P (expr) = REF_PARENTHESIZED_P (qualified_id); + return expr; } if (!BASELINK_P (name) && !DECL_P (expr)) @@ -26914,6 +26922,7 @@ instantiation_dependent_scope_ref_p (tree t) { if (DECL_P (TREE_OPERAND (t, 1)) && CLASS_TYPE_P (TREE_OPERAND (t, 0)) + && !dependent_scope_p (TREE_OPERAND (t, 0)) && !unknown_base_ref_p (t) && accessible_in_template_p (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1))) diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction109.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction109.C new file mode 100644 index 0000000..e621eba --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction109.C @@ -0,0 +1,64 @@ +// PR c++/103943 +// { dg-do compile { target c++17 } } + +template<typename R, typename...AA> struct F0 { //OK + R(*fun_ptr)(AA...); +}; +template<typename R, typename...AA> struct F1 { //OK + R(*fun_ptr)(AA...); + F1(R(*fun_ptr)(AA...)) : fun_ptr(fun_ptr) {} +}; +template<typename R, typename...AA> struct F2 { //OK + R(*fun_ptr)(AA...); + using fun_ptr_t = decltype(fun_ptr); + F2(fun_ptr_t fun_ptr) : fun_ptr(fun_ptr) {} +}; +template<typename R, typename...AA> struct F3 { + R(*fun_ptr)(AA...); +// using fun_ptr_t = decltype(fun_ptr); //OK as in F2 + using fun_ptr_t = decltype(F3::fun_ptr); //ICE: Segmentation fault +// using fun_ptr_t = decltype(F3<R, AA...>::fun_ptr); //ICE: Segmentation fault + F3(fun_ptr_t fun_ptr) : fun_ptr(fun_ptr) {} +}; +template<typename R, typename...AA> struct F4 { + static R fun_not_implemented(AA...); +// using fun_ptr_t = decltype(&fun_not_implemented); //OK + using fun_ptr_t = decltype(&F4::fun_not_implemented); //OK with aggregate initialization (no ctor) +// using fun_ptr_t = decltype(&F4<R, AA...>::fun_not_implemented); //OK with aggregate initialization (no ctor) + fun_ptr_t fun_ptr; +}; +template<typename R, typename...AA> struct F5 { //OK + static R fun_not_implemented(AA...); + using fun_ptr_t = decltype(&fun_not_implemented); + fun_ptr_t fun_ptr; + F5(fun_ptr_t fun_ptr) : fun_ptr(fun_ptr) {} +}; +template<typename R, typename...AA> struct F6 { + static R fun_not_implemented(AA...); +// using fun_ptr_t = decltype(&fun_not_implemented); //OK as in F5 + using fun_ptr_t = decltype(&F6::fun_not_implemented); //ICE: in build_qualified_name, at cp/tree.c:2238 +// using fun_ptr_t = decltype(&F6<R, AA...>::fun_not_implemented); //ICE: in build_qualified_name, at cp/tree.c:2238 + fun_ptr_t fun_ptr; + F6(fun_ptr_t fun_ptr) : fun_ptr(fun_ptr) {} +}; +template<typename R, typename...AA> F0(R(*fun_ptr)(AA...)) -> F0<R, AA...>; +template<typename R, typename...AA> F1(R(*fun_ptr)(AA...)) -> F1<R, AA...>; +template<typename R, typename...AA> F2(R(*fun_ptr)(AA...)) -> F2<R, AA...>; +template<typename R, typename...AA> F3(R(*fun_ptr)(AA...)) -> F3<R, AA...>; +template<typename R, typename...AA> F4(R(*fun_ptr)(AA...)) -> F4<R, AA...>; +template<typename R, typename...AA> F5(R(*fun_ptr)(AA...)) -> F5<R, AA...>; +template<typename R, typename...AA> F6(R(*fun_ptr)(AA...)) -> F6<R, AA...>; + +int fun(int a) { + return a + 1; +} +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +void test() { + auto f0 = F0{&fun}; //OK + auto f1 = F1{&fun}; //OK + auto f2 = F2{&fun}; //OK + auto f3 = F3{&fun}; //ICE: Segmentation fault + auto f4 = F4{&fun}; //OK + auto f5 = F5{&fun}; //OK + auto f6 = F6{&fun}; //ICE: in build_qualified_name, at cp/tree.c:2238 +} |