* [C++ PATCH] get_fns cleanups
@ 2017-05-16 13:16 Nathan Sidwell
2017-05-16 14:55 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Nathan Sidwell @ 2017-05-16 13:16 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 476 bytes --]
Some random cleanups with get_fns & get_first_fn from the modules
branch. I started cleaning up these and is_overloaded_fn & friends, but
that turned into a bit of a rat hole. There's certainly more mileage to
be gotten though.
These cleanups are generally callers unnecessarily stripping bits off
the get_fns deals with itself. Or in the omp error case, unnecessarily
peeking behind the curtain of OVERLOAD abstraction.
Applied to trunk.
nathan
--
Nathan Sidwell
[-- Attachment #2: get-fns.diff --]
[-- Type: text/x-patch, Size: 4364 bytes --]
2017-05-16 Nathan Sidwell <nathan@acm.org>
* pt.c (tsubst_copy_and_build): Remove unnecessary COMPONENT_REF
peeking.
* semantics.c (finish_id_expression): Directly init local var.
(finish_omp_reduction_clause): Use really_overloaded_fn.
* tree.c (get_fns): Document. Assert we got an overload.
(get_first_fn) Document.
* typeck.c (cp_build_addr_expr_1): Pass arg directly to
really_overloaded_fn.
* typeck2.c (cxx_inomplete_type_diagnostic): Use get_first_fn directly.
Index: pt.c
===================================================================
--- pt.c (revision 248095)
+++ pt.c (working copy)
@@ -17187,10 +17187,9 @@ tsubst_copy_and_build (tree t,
if (diag)
{
tree fn = unq;
+
if (INDIRECT_REF_P (fn))
fn = TREE_OPERAND (fn, 0);
- if (TREE_CODE (fn) == COMPONENT_REF)
- fn = TREE_OPERAND (fn, 1);
if (is_overloaded_fn (fn))
fn = get_first_fn (fn);
Index: semantics.c
===================================================================
--- semantics.c (revision 248095)
+++ semantics.c (working copy)
@@ -3749,9 +3749,8 @@ finish_id_expression (tree id_expression
}
else if (is_overloaded_fn (decl))
{
- tree first_fn;
+ tree first_fn = get_first_fn (decl);
- first_fn = get_first_fn (decl);
if (TREE_CODE (first_fn) == TEMPLATE_DECL)
first_fn = DECL_TEMPLATE_RESULT (first_fn);
@@ -5615,7 +5614,6 @@ finish_omp_reduction_clause (tree c, boo
{
if (id == error_mark_node)
return true;
- id = OVL_CURRENT (id);
mark_used (id);
tree body = DECL_SAVED_TREE (id);
if (!body)
@@ -6924,13 +6922,13 @@ finish_omp_clauses (tree clauses, enum c
{
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE)
{
- if (TREE_CODE (t) == OVERLOAD && OVL_CHAIN (t))
+ if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
error_at (OMP_CLAUSE_LOCATION (c),
- "overloaded function name %qE in clause %qs", t,
+ "template %qE in clause %qs", t,
omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
- else if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
+ else if (really_overloaded_fn (t))
error_at (OMP_CLAUSE_LOCATION (c),
- "template %qE in clause %qs", t,
+ "overloaded function name %qE in clause %qs", t,
omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
else
error_at (OMP_CLAUSE_LOCATION (c),
Index: tree.c
===================================================================
--- tree.c (revision 248095)
+++ tree.c (working copy)
@@ -2146,10 +2146,11 @@ really_overloaded_fn (tree x)
return is_overloaded_fn (x) == 2;
}
+/* Get the overload set FROM refers to. */
+
tree
get_fns (tree from)
{
- gcc_assert (is_overloaded_fn (from));
/* A baselink is also considered an overloaded function. */
if (TREE_CODE (from) == OFFSET_REF
|| TREE_CODE (from) == COMPONENT_REF)
@@ -2158,9 +2159,13 @@ get_fns (tree from)
from = BASELINK_FUNCTIONS (from);
if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
from = TREE_OPERAND (from, 0);
+ gcc_assert (TREE_CODE (from) == OVERLOAD
+ || TREE_CODE (from) == FUNCTION_DECL);
return from;
}
+/* Return the first function of the overload set FROM refers to. */
+
tree
get_first_fn (tree from)
{
Index: typeck.c
===================================================================
--- typeck.c (revision 248095)
+++ typeck.c (working copy)
@@ -5603,7 +5603,7 @@ cp_build_addr_expr_1 (tree arg, bool str
gcc_assert (!identifier_p (arg) || !IDENTIFIER_OPNAME_P (arg));
if (TREE_CODE (arg) == COMPONENT_REF && type_unknown_p (arg)
- && !really_overloaded_fn (TREE_OPERAND (arg, 1)))
+ && !really_overloaded_fn (arg))
{
/* They're trying to take the address of a unique non-static
member function. This is ill-formed (except in MS-land),
Index: typeck2.c
===================================================================
--- typeck2.c (revision 248095)
+++ typeck2.c (working copy)
@@ -506,9 +506,8 @@ cxx_incomplete_type_diagnostic (location
case OFFSET_TYPE:
bad_member:
{
- tree member = TREE_OPERAND (value, 1);
- if (is_overloaded_fn (member))
- member = get_first_fn (member);
+ tree member = get_first_fn (TREE_OPERAND (value, 1));
+
if (DECL_FUNCTION_MEMBER_P (member)
&& ! flag_ms_extensions)
emit_diagnostic (diag_kind, loc, 0,
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C++ PATCH] get_fns cleanups
2017-05-16 13:16 [C++ PATCH] get_fns cleanups Nathan Sidwell
@ 2017-05-16 14:55 ` Jason Merrill
2017-05-16 14:57 ` Nathan Sidwell
2017-05-16 17:19 ` Nathan Sidwell
0 siblings, 2 replies; 4+ messages in thread
From: Jason Merrill @ 2017-05-16 14:55 UTC (permalink / raw)
To: Nathan Sidwell; +Cc: GCC Patches
The change to cxx_incomplete_type_diagnostic seems wrong; the member
might be a data member.
Jason
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C++ PATCH] get_fns cleanups
2017-05-16 14:55 ` Jason Merrill
@ 2017-05-16 14:57 ` Nathan Sidwell
2017-05-16 17:19 ` Nathan Sidwell
1 sibling, 0 replies; 4+ messages in thread
From: Nathan Sidwell @ 2017-05-16 14:57 UTC (permalink / raw)
To: gcc-patches
On 05/16/2017 10:50 AM, Jason Merrill wrote:
> The change to cxx_incomplete_type_diagnostic seems wrong; the member
> might be a data member.
I had convinced myself that at that point it couldn't be. Will take
another look though.
Anyway, thanks for the review!
nathan
--
Nathan Sidwell
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C++ PATCH] get_fns cleanups
2017-05-16 14:55 ` Jason Merrill
2017-05-16 14:57 ` Nathan Sidwell
@ 2017-05-16 17:19 ` Nathan Sidwell
1 sibling, 0 replies; 4+ messages in thread
From: Nathan Sidwell @ 2017-05-16 17:19 UTC (permalink / raw)
To: Jason Merrill; +Cc: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 310 bytes --]
On 05/16/2017 10:50 AM, Jason Merrill wrote:
> The change to cxx_incomplete_type_diagnostic seems wrong; the member
> might be a data member.
I couldn't get there with a non-overload, but then I couldn't convince
myself there was no other path. It's hardly a critical path, so reverted.
--
Nathan Sidwell
[-- Attachment #2: r.diff --]
[-- Type: text/x-patch, Size: 630 bytes --]
2017-05-16 Nathan Sidwell <nathan@acm.org>
* typeck2.c (cxx_incomplete_type_diagnostic): Revert change and
check is_overloaded_fn.
Index: typeck2.c
===================================================================
--- typeck2.c (revision 248109)
+++ typeck2.c (working copy)
@@ -506,7 +506,9 @@ cxx_incomplete_type_diagnostic (location
case OFFSET_TYPE:
bad_member:
{
- tree member = get_first_fn (TREE_OPERAND (value, 1));
+ tree member = TREE_OPERAND (value, 1);
+ if (is_overloaded_fn (member))
+ member = get_first_fn (member);
if (DECL_FUNCTION_MEMBER_P (member)
&& ! flag_ms_extensions)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-05-16 16:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-16 13:16 [C++ PATCH] get_fns cleanups Nathan Sidwell
2017-05-16 14:55 ` Jason Merrill
2017-05-16 14:57 ` Nathan Sidwell
2017-05-16 17:19 ` Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).