aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/call.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2017-05-16 19:52:26 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2017-05-16 19:52:26 +0000
commit10791753c191d1f9d886e8977ff331b28d48398d (patch)
tree7300ba80786b3a4015ecd026d0743b85a9c3b7cd /gcc/cp/call.c
parent727577c2300f8a1c4cf757e784267e11034f6b4a (diff)
downloadgcc-10791753c191d1f9d886e8977ff331b28d48398d.zip
gcc-10791753c191d1f9d886e8977ff331b28d48398d.tar.gz
gcc-10791753c191d1f9d886e8977ff331b28d48398d.tar.bz2
C++: fix-it hints suggesting accessors for private fields
gcc/cp/ChangeLog: * call.c (enforce_access): Add access_failure_info * param and use it to record access failures. * cp-tree.h (class access_failure_info): New class. (enforce_access): Add access_failure_info * param, defaulting to NULL. (lookup_member): Likewise. (locate_field_accessor): New function decl. (perform_or_defer_access_check): Add access_failure_info * param, defaulting to NULL. * search.c (lookup_member): Add access_failure_info * param and pass it on to call to perform_or_defer_access_check. (matches_code_and_type_p): New function. (field_access_p): New function. (direct_accessor_p): New function. (reference_accessor_p): New function. (field_accessor_p): New function. (struct locate_field_data): New struct. (dfs_locate_field_accessor_pre): New function. (locate_field_accessor): New function. * semantics.c (perform_or_defer_access_check): Add access_failure_info * param, and pass it on to call to enforce_access. * typeck.c (access_failure_info::record_access_failure): New method. (access_failure_info::maybe_suggest_accessor): New method. (finish_class_member_access_expr): Pass an access_failure_info instance to the lookup_member call, and call its maybe_suggest_accessor method afterwards. gcc/testsuite/ChangeLog: * g++.dg/other/accessor-fixits-1.C: New test case. * g++.dg/other/accessor-fixits-2.C: New test case. * g++.dg/other/accessor-fixits-3.C: New test case. * g++.dg/other/accessor-fixits-4.C: New test case. From-SVN: r248128
Diffstat (limited to 'gcc/cp/call.c')
-rw-r--r--gcc/cp/call.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 1367344..cc64202 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -6396,7 +6396,7 @@ build_op_delete_call (enum tree_code code, tree addr, tree size,
bool
enforce_access (tree basetype_path, tree decl, tree diag_decl,
- tsubst_flags_t complain)
+ tsubst_flags_t complain, access_failure_info *afi)
{
gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
@@ -6422,17 +6422,23 @@ enforce_access (tree basetype_path, tree decl, tree diag_decl,
error ("%q#D is private within this context", diag_decl);
inform (DECL_SOURCE_LOCATION (diag_decl),
"declared private here");
+ if (afi)
+ afi->record_access_failure (basetype_path, diag_decl);
}
else if (TREE_PROTECTED (decl))
{
error ("%q#D is protected within this context", diag_decl);
inform (DECL_SOURCE_LOCATION (diag_decl),
"declared protected here");
+ if (afi)
+ afi->record_access_failure (basetype_path, diag_decl);
}
else
{
error ("%q#D is inaccessible within this context", diag_decl);
inform (DECL_SOURCE_LOCATION (diag_decl), "declared here");
+ if (afi)
+ afi->record_access_failure (basetype_path, diag_decl);
}
}
return false;