From patchwork Mon May 29 12:56: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: 768176 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 3wbxZS2wtyz9s5L for ; Mon, 29 May 2017 22:56:31 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Xu0HPIWv"; 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=mdxMISvsX7ngoxzeLBsggjDIi4KLvZjvXsa9GAS14GGD+qRxkm IXi/pOm4Mx+eqOG3hOZJsYBJjFKgRc2m0l/1aS4hWjUmaW7oseYwx+sLD+ejzerd S/SumaI2XCbFsvCbi/AA/BNEOkzKwgLD+L9yvOpMESj+VgnPKIJca6qXg= 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=cMfhvPwIz74D+56/i0LuZCkkb1E=; b=Xu0HPIWvdAgOBKUGql96 ln1IDonMsFiOtm6URHssbFAvFsU9Qj3nrBvpie1hHAOUXmd8iejEVaoYH6j0370C OMsbyoEetEJmXAAkyoHHcGAgwSICXQb1tvREUk3Vx61NwUgyI15ZqiXF32kMuiH2 LJOMA+jI0KpIW/uH+IYrZYY= Received: (qmail 100656 invoked by alias); 29 May 2017 12:56: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 100643 invoked by uid 89); 29 May 2017 12:56:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-yw0-f177.google.com Received: from mail-yw0-f177.google.com (HELO mail-yw0-f177.google.com) (209.85.161.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 May 2017 12:56:14 +0000 Received: by mail-yw0-f177.google.com with SMTP id p73so28212378ywp.0 for ; Mon, 29 May 2017 05:56: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=eePxyXEQd/UKhW9m3rHyVDyB3e6TZSwY66/Sb5TVonA=; b=Jmg8p5KElb+TIEZHXmMTsP8rBUyf4T1TMaulEvDDXHt6c8N0xcFSR9CuI++auhb9Vd glyXJNSX3/0qWAJXb3yGpkL639HgBrdarvG9yFSvRIE+QllHcLmmboYXR+/VNzelXW/V I2DfdwUNMrVhZXyyPgtEm/qsJS/SmrFFm1yIJ+sXAnCyt4VLyKFHrxUnEkxZVBpkJ681 QN2x2YFgvEruDHdENvPxU2uJDu/L7wTl+kdVAmF1E1Ix6+zqC5AfcBPC7e1S9Gk/IpQ6 Kou2WM1NNF+6QuAaz+uiwOeDDracM3u7PUIxQrzY3Mg8g8Z8WuSD0LK3NMatkWzZIGZX +YlA== X-Gm-Message-State: AODbwcDLqt6tBQakAujq7HnhKQsaVEF0qOzLsMTOPPY+T9PDSXV7qcmH TmtWJcLTnHhT1A== X-Received: by 10.13.208.3 with SMTP id s3mr12601493ywd.315.1496062576219; Mon, 29 May 2017 05:56:16 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a1:1102:b9b0:1beb:d21c:b3f4? ([2620:10d:c091:180::d0e1]) by smtp.googlemail.com with ESMTPSA id n1sm4703867ywd.33.2017.05.29.05.56.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 May 2017 05:56:15 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] PR c++/80891 #3 Message-ID: Date: Mon, 29 May 2017 08:56:13 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 This patch fixes the 3rd testcase in 80891. Here we were squirelling away overload lookup results in template definitions, but failing to mark them as used. tsubst rightly asserted. Fixed by adding calls to lookup_mark in the relevant expr build functions. build_nt_call_vec is in the common core, but only ever called from the c++ FE. This patch replaces those calls with a C++-specific builder, that does the marking. I left the common one in gcc/tree.c alone, but perhaps it should be removed as unneeded? nathan 2017-05-29 Nathan Sidwell PR c++/80891 (#3) * cp-tree.h (build_min_nt_call_vec): Declare. * decl.c (build_offset_ref_call_from_tree): Call it. * parser.c (cp_parser_postfix_expression): Likewise. * pt.c (tsubst_copy_and_build): Likewise. * semantics.c (finish_call_expr): Likewise. * tree.c (build_min_nt_loc): Keep unresolved lookups. (build_min): Likewise. (build_min_non_dep): Likewise. (build_min_non_dep_call_vec): Likewise. (build_min_nt_call_vec): New. PR c++/80891 (#3) * g++.dg/lookup/pr80891-3.C: New. Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 248569) +++ cp/cp-tree.h (working copy) @@ -6891,6 +6891,7 @@ extern tree build_min_nt_loc (location ...); extern tree build_min_non_dep (enum tree_code, tree, ...); extern tree build_min_non_dep_op_overload (enum tree_code, tree, tree, ...); +extern tree build_min_nt_call_vec (tree, vec *); extern tree build_min_non_dep_call_vec (tree, tree, vec *); extern vec* vec_copy_and_insert (vec*, tree, unsigned); extern tree build_cplus_new (tree, tree, tsubst_flags_t); Index: cp/decl2.c =================================================================== --- cp/decl2.c (revision 248569) +++ cp/decl2.c (working copy) @@ -4891,7 +4891,7 @@ build_offset_ref_call_from_tree (tree fn || TREE_CODE (fn) == MEMBER_REF); if (type_dependent_expression_p (fn) || any_type_dependent_arguments_p (*args)) - return build_nt_call_vec (fn, *args); + return build_min_nt_call_vec (fn, *args); orig_args = make_tree_vector_copy (*args); Index: cp/parser.c =================================================================== --- cp/parser.c (revision 248569) +++ cp/parser.c (working copy) @@ -6952,7 +6952,7 @@ cp_parser_postfix_expression (cp_parser { maybe_generic_this_capture (instance, fn); postfix_expression - = build_nt_call_vec (postfix_expression, args); + = build_min_nt_call_vec (postfix_expression, args); release_tree_vector (args); break; } Index: cp/pt.c =================================================================== --- cp/pt.c (revision 248569) +++ cp/pt.c (working copy) @@ -17389,7 +17389,7 @@ tsubst_copy_and_build (tree t, && TREE_CODE (fn) != FIELD_DECL) || type_dependent_expression_p (fn) || any_type_dependent_arguments_p (call_args))) - ret = build_nt_call_vec (function, call_args); + ret = build_min_nt_call_vec (function, call_args); else if (!BASELINK_P (fn)) ret = finish_call_expr (function, &call_args, /*disallow_virtual=*/false, Index: cp/semantics.c =================================================================== --- cp/semantics.c (revision 248569) +++ cp/semantics.c (working copy) @@ -2322,7 +2322,7 @@ finish_call_expr (tree fn, vec *args) +{ + tree ret, t; + unsigned int ix; + + ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3); + CALL_EXPR_FN (ret) = fn; + CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE; + FOR_EACH_VEC_SAFE_ELT (args, ix, t) + { + CALL_EXPR_ARG (ret, ix) = t; + if (TREE_CODE (t) == OVERLOAD) + lookup_keep (t, true); + } + return ret; +} + +/* Similar to `build_min_nt_call_vec', but for template definitions of non-dependent expressions. NON_DEP is the non-dependent expression that has been built. */ tree build_min_non_dep_call_vec (tree non_dep, tree fn, vec *argvec) { - tree t = build_nt_call_vec (fn, argvec); + tree t = build_min_nt_call_vec (fn, argvec); if (REFERENCE_REF_P (non_dep)) non_dep = TREE_OPERAND (non_dep, 0); TREE_TYPE (t) = TREE_TYPE (non_dep); Index: testsuite/g++.dg/lookup/pr80891-3.C =================================================================== --- testsuite/g++.dg/lookup/pr80891-3.C (revision 0) +++ testsuite/g++.dg/lookup/pr80891-3.C (working copy) @@ -0,0 +1,26 @@ +// PR c++/80891 part 3 +// We were failing to mark OVERLOADS held in template definitions as +// immutable in non-call contexts. + +namespace std { + int endl(); +} + +using std::endl; + +template void test_spots(RealType) +{ + using namespace std; + RealType a; + a << endl; +} + +template +void operator<< (T, int (&)()); + +struct Q {}; +void test_maintest_method() +{ + Q q; + test_spots(q); +}