From patchwork Tue May 16 13:14:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 763001 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wRyb92zzpz9s0m for ; Tue, 16 May 2017 23:14:29 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wYzMs4UX"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=h4VcDpquda6t2nVdOaQOrLbdU0yDPckAop+Qc6SkSXU7E+4ON3 v5LoUqcdXI6htYkXRuidcndhfTjhi04jbWojx2fJibyrzo8DPUWEotruPMqLRpjq HvMElo+II3FwHgpZGWPfrO6wtgRMysIMlyJPfGlec+JuUIy08WO1vfPY4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=ivWJGVcZBd/vnNq4ZcXqGoFqo7k=; b=wYzMs4UXpiJfkZ4w3OU/ Dm9YdA/RQ1uqzoKjGbge0SjvArBHiq6V3Vjtg5XRsrOJP02F2bwCs0WInc/m7CUN fU3/XB22GeCFEGDtkE15PybNzWs/bssPC9IUqEQ77NCcYk1Ekz6Wa21MxYH11Vuu 7SVJ+cs81PP3pXHXyXO7tYk= Received: (qmail 53578 invoked by alias); 16 May 2017 13:14:17 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 51210 invoked by uid 89); 16 May 2017 13:14:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=mileage, rat X-HELO: mail-yw0-f173.google.com Received: from mail-yw0-f173.google.com (HELO mail-yw0-f173.google.com) (209.85.161.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 May 2017 13:14:14 +0000 Received: by mail-yw0-f173.google.com with SMTP id l14so52589350ywk.1 for ; Tue, 16 May 2017 06:14:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=v1buTLQnp5qMO3XkJ9BPRnM3349vLlXQGmCgLm+EyAw=; b=D4rU6PqQO5WUmeHj2xhguh5zuLZWaX9Jbz4jrtxuyeQ8yDCvfWIhGiGV+g09fHWSP7 IYmM70qVFarQLx4613DRCwBqCWc1QiaUngm7vEv9ImSAKWThoZlLUQSyUJ9DKkbVIUoJ QQlHErM7ERu5QDCraXTSGjwIwqoWYN1wXE7bUQ6f/5RYahWy/YPc4ehe5mD+/JEAAqtP J6CVrXGDzg9c8XmikY0awMCPc9m90FPAS2lDK/zWkJsycrBBz+6H5bSn+PYBJfx+hExQ yJaQ2/g/QfFMbwY/DKa0TxZWOnqje81nFbUCok9IU+broaPAJ5mtdn9CGouIsewKvouS sgvg== X-Gm-Message-State: AODbwcBgA6666fLgREc/17q7dB9qVspkimURoCs+w0ubzrwuc0ATeFGE sZgdHn32M090rA== X-Received: by 10.129.172.65 with SMTP id z1mr9176202ywj.237.1494940455977; Tue, 16 May 2017 06:14:15 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::7:4a1a]) by smtp.googlemail.com with ESMTPSA id b12sm6209132ywe.8.2017.05.16.06.14.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 May 2017 06:14:15 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] get_fns cleanups Message-ID: Date: Tue, 16 May 2017 09:14:13 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 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 2017-05-16 Nathan Sidwell * 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,