diff options
author | Patrick Palka <ppalka@redhat.com> | 2022-05-03 15:21:26 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2022-05-03 15:21:26 -0400 |
commit | a16fc9f1c96c7361d0b7a83a06f3649ace6c440d (patch) | |
tree | 01f249f3cd129ae610347d2ac1d0d4d9cd195a61 /gcc/cp | |
parent | 5609bcd620132c290820cccd871a6d7cbf39b785 (diff) | |
download | gcc-a16fc9f1c96c7361d0b7a83a06f3649ace6c440d.zip gcc-a16fc9f1c96c7361d0b7a83a06f3649ace6c440d.tar.gz gcc-a16fc9f1c96c7361d0b7a83a06f3649ace6c440d.tar.bz2 |
c++: make finish_non_static_data_member SFINAE enabled [PR105351]
Here since finish_non_static_data_member isn't SFINAE enabled, we
incorrectly emit an error when considering the first overload rather
than silently discarding it:
sfinae33.C: In substitution of ‘template<class T> A<T::value> f() [with T = B]’:
sfinae33.C:11:7: required from here
sfinae33.C:5:31: error: invalid use of non-static data member ‘B::value’
5 | template<class T> A<T::value> f();
| ^
This patch makes the function SFINAE enabled in the usual way: give it a
complain parameter, check it before emitting an error, and pass it through
appropriately.
PR c++/105351
gcc/cp/ChangeLog:
* cp-tree.h (finish_non_static_data_member): Add defaulted
complain parameter.
* pt.cc (tsubst_copy_and_build): Pass complain to
finish_non_static_data_member.
* semantics.cc (finish_non_static_data_member): Respect complain
parameter.
(finish_qualified_id_expr): Pass complain to
finish_non_static_data_member.
gcc/testsuite/ChangeLog:
* g++.dg/template/sfinae33.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/cp-tree.h | 3 | ||||
-rw-r--r-- | gcc/cp/pt.cc | 3 | ||||
-rw-r--r-- | gcc/cp/semantics.cc | 27 |
3 files changed, 20 insertions, 13 deletions
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 6de29c0..8d7cf24 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7615,7 +7615,8 @@ inline tree force_paren_expr_uneval (tree t) { return force_paren_expr (t, true); } extern tree maybe_undo_parenthesized_ref (tree); extern tree maybe_strip_ref_conversion (tree); -extern tree finish_non_static_data_member (tree, tree, tree); +extern tree finish_non_static_data_member (tree, tree, tree, + tsubst_flags_t = tf_warning_or_error); extern tree begin_stmt_expr (void); extern tree finish_stmt_expr_expr (tree, tree); extern tree finish_stmt_expr (tree, bool); diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 3edee50..ac00290 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -21054,7 +21054,8 @@ tsubst_copy_and_build (tree t, } else if (TREE_CODE (member) == FIELD_DECL) { - r = finish_non_static_data_member (member, object, NULL_TREE); + r = finish_non_static_data_member (member, object, NULL_TREE, + complain); if (TREE_CODE (r) == COMPONENT_REF) REF_PARENTHESIZED_P (r) = REF_PARENTHESIZED_P (t); RETURN (r); diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 377f611..bfb737f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -2141,7 +2141,8 @@ finish_parenthesized_expr (cp_expr expr) preceded by `.' or `->'. */ tree -finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) +finish_non_static_data_member (tree decl, tree object, tree qualifying_scope, + tsubst_flags_t complain /* = tf_warning_or_error */) { gcc_assert (TREE_CODE (decl) == FIELD_DECL); bool try_omp_private = !object && omp_private_member_map; @@ -2172,12 +2173,15 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) if (is_dummy_object (object) && cp_unevaluated_operand == 0 && (!processing_template_decl || !current_class_ref)) { - if (current_function_decl - && DECL_STATIC_FUNCTION_P (current_function_decl)) - error ("invalid use of member %qD in static member function", decl); - else - error ("invalid use of non-static data member %qD", decl); - inform (DECL_SOURCE_LOCATION (decl), "declared here"); + if (complain & tf_error) + { + if (current_function_decl + && DECL_STATIC_FUNCTION_P (current_function_decl)) + error ("invalid use of member %qD in static member function", decl); + else + error ("invalid use of non-static data member %qD", decl); + inform (DECL_SOURCE_LOCATION (decl), "declared here"); + } return error_mark_node; } @@ -2219,8 +2223,9 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) { tree access_type = TREE_TYPE (object); - perform_or_defer_access_check (TYPE_BINFO (access_type), decl, - decl, tf_warning_or_error); + if (!perform_or_defer_access_check (TYPE_BINFO (access_type), decl, + decl, complain)) + return error_mark_node; /* If the data member was named `C::M', convert `*this' to `C' first. */ @@ -2234,7 +2239,7 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) ret = build_class_member_access_expr (object, decl, /*access_path=*/NULL_TREE, /*preserve_reference=*/false, - tf_warning_or_error); + complain); } if (try_omp_private) { @@ -2396,7 +2401,7 @@ finish_qualified_id_expr (tree qualifying_class, { push_deferring_access_checks (dk_no_check); expr = finish_non_static_data_member (expr, NULL_TREE, - qualifying_class); + qualifying_class, complain); pop_deferring_access_checks (); } else if (BASELINK_P (expr)) |