From patchwork Wed Dec 4 16:44:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1204276 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515144-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="TbHbnUtu"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="AhGDaFxa"; dkim-atps=neutral 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 47Sl7T6R7Xz9sP6 for ; Thu, 5 Dec 2019 03:44:37 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=khG2ZXFc4EK2Rwq27sau0aojlqmDBEu9apzMdqXbBhjHRq+hjL 1NfqLIkRWIdBmVEwOZQTAxHQ87AVoDCP2MWFiuhnasUK3FnPY5d+xVYi24Ty3lfg j0N6Di+q31g+LL5ugrfbtOwAapRBlApRBWFqph1Nq8YL5gs39WkPyhPMs= 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:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=gyVFTIwD9qZayM/lyqYP3S3l6dg=; b=TbHbnUtu2F+Q1l/hWVvV lwo/An8tvyKBER2RhLnUVZuT5tDmszGx+/ZArwxzGgYmiWIraASbLaxVP80QvGs+ kID+3/dUD+buOmjeX6kQKtVXuyos1fU6qhw2s1vzTNUJ4HmGjKgczPnrCOo6Kglh 7WXTp+vQpny/EjRLtFJVyyI= Received: (qmail 45130 invoked by alias); 4 Dec 2019 16:44:30 -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 44994 invoked by uid 89); 4 Dec 2019 16:44:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=65, 6, 5, 85, old-deja X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Dec 2019 16:44:26 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xB4GTO4A164050; Wed, 4 Dec 2019 16:44:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : from : subject : message-id : date : mime-version : content-type; s=corp-2019-08-05; bh=hxzVUwR5sXEmL2S4t/yJpmeqYa6DowFCQAJbGyPvKL8=; b=AhGDaFxa9UaY0WiWnPn3bq1A63V8iLAIJ91dglytucGlK4VWXMXKiuAMBgjIQTfh2R5j 4NM7z7Nr3JaQKdmbSGMN5tnb8kZt/lKp41bcay9blthrJqzDSLDPz0BZMda5JJ7kGnUQ m0AqYhar5D9PveyDVYfkA6S9dbfIg2MS8rEgP8OZpPIQUmfkWG61J0ZAl7rWurF0wwXJ V1d33OX0IyYrr9fN8152g1RFo7EmQuo/X6C/ycWsfUztR4AllIv/WuBraJRlNzyoLvno YqbBqj3MOe28sxrFl2KjETT5ZZRLsv8t8Q3vsosJzzSiDBFKxVb21YAGl+HQMeUWW4fY ag== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2wkh2rffvb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 04 Dec 2019 16:44:24 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xB4GY3gM040203; Wed, 4 Dec 2019 16:44:24 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2wp17e9vdx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 04 Dec 2019 16:44:23 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id xB4GiMAX022412; Wed, 4 Dec 2019 16:44:22 GMT Received: from [192.168.1.4] (/79.26.212.60) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 04 Dec 2019 08:44:21 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Improve build_functional_cast locations Message-ID: <54566c67-c294-9ae1-8972-fa909862a480@oracle.com> Date: Wed, 4 Dec 2019 17:44:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi, this exemplifies in a compact way the kind of change we can implement for the other casts too: near the end of cp_parser_functional_cast instead of using the combined_loc only for the returned cp_expr we can also pass it to build_functional_cast. Tested x86_64-linux. Thanks, Paolo. /////////////////////////// /gcc/cp 2019-12-04 Paolo Carlini * typeck2.c (build_functional_cast): Add location_t parameter and use it. * cp-tree.h: Update declaration. * parser.c (cp_parser_functional_cast): Adjust call. * call.c (build_op_delete_call): Likewise. (build_new_method_call_1): Likewise. * decl.c (check_initializer): Likewise. * pt.c (tsubst_copy_and_build): Likewise. * semantics.c (finish_compound_literal): Likewise. /libcc1 2019-12-04 Paolo Carlini * libcp1plugin.cc (plugin_build_expression_list_expr): Adjust build_functional_cast call. /testsuite 2019-12-04 Paolo Carlini * g++.dg/diagnostic/functional-cast-to-array-type-1.C: New. * g++.dg/cpp0x/auto25.C: Check location(s) too. * g++.dg/cpp0x/auto28.C: Likewise. * g++.dg/init/reference2.C: Likewise. * g++.dg/parse/template2.C: Likewise. * g++.dg/template/error8.C: Likewise. * g++.old-deja/g++.ns/crash3.C: Likewise. * g++.old-deja/g++.ns/template7.C: Likewise. * g++.old-deja/g++.pt/crash8.C: Likewise. Index: gcc/cp/call.c =================================================================== --- gcc/cp/call.c (revision 278959) +++ gcc/cp/call.c (working copy) @@ -6933,7 +6933,8 @@ build_op_delete_call (enum tree_code code, tree ad rtype = cv_unqualified (rtype); rtype = TYPE_POINTER_TO (rtype); addr = cp_convert (rtype, oaddr, complain); - destroying = build_functional_cast (destroying, NULL_TREE, + destroying = build_functional_cast (input_location, + destroying, NULL_TREE, complain); } @@ -9997,7 +9998,8 @@ build_new_method_call_1 (tree instance, tree fns, basetype, name)) inform (input_location, "for a function-style cast, remove the " "redundant %<::%D%>", name); - call = build_functional_cast (basetype, build_tree_list_vec (user_args), + call = build_functional_cast (input_location, basetype, + build_tree_list_vec (user_args), complain); return call; } Index: gcc/cp/cp-tree.h =================================================================== --- gcc/cp/cp-tree.h (revision 278959) +++ gcc/cp/cp-tree.h (working copy) @@ -7681,7 +7681,8 @@ extern tree build_scoped_ref (tree, tree, tree * extern tree build_x_arrow (location_t, tree, tsubst_flags_t); extern tree build_m_component_ref (tree, tree, tsubst_flags_t); -extern tree build_functional_cast (tree, tree, tsubst_flags_t); +extern tree build_functional_cast (location_t, tree, tree, + tsubst_flags_t); extern tree add_exception_specifier (tree, tree, tsubst_flags_t); extern tree merge_exception_specifiers (tree, tree); Index: gcc/cp/decl.c =================================================================== --- gcc/cp/decl.c (revision 278959) +++ gcc/cp/decl.c (working copy) @@ -6764,7 +6764,8 @@ check_initializer (tree decl, tree init, int flags if (CLASS_TYPE_P (type) && (!init || TREE_CODE (init) == TREE_LIST)) { - init = build_functional_cast (type, init, tf_none); + init = build_functional_cast (input_location, type, + init, tf_none); if (TREE_CODE (init) == TARGET_EXPR) TARGET_EXPR_DIRECT_INIT_P (init) = true; } Index: gcc/cp/parser.c =================================================================== --- gcc/cp/parser.c (revision 278959) +++ gcc/cp/parser.c (working copy) @@ -29268,8 +29268,17 @@ cp_parser_functional_cast (cp_parser* parser, tree release_tree_vector (vec); } - cast = build_functional_cast (type, expression_list, + /* Create a location of the form: + float(i) + ^~~~~~~~ + with caret == start at the start of the type name, + finishing at the closing paren. */ + location_t combined_loc = make_location (start_loc, start_loc, + parser->lexer); + cast = build_functional_cast (combined_loc, type, expression_list, tf_warning_or_error); + cast.set_location (combined_loc); + /* [expr.const]/1: In an integral constant expression "only type conversions to integral or enumeration type can be used". */ if (TREE_CODE (type) == TYPE_DECL) @@ -29280,13 +29289,6 @@ cp_parser_functional_cast (cp_parser* parser, tree NIC_CONSTRUCTOR)) return error_mark_node; - /* Create a location of the form: - float(i) - ^~~~~~~~ - with caret == start at the start of the type name, - finishing at the closing paren. */ - location_t combined_loc = make_location (start_loc, start_loc, parser->lexer); - cast.set_location (combined_loc); return cast; } Index: gcc/cp/pt.c =================================================================== --- gcc/cp/pt.c (revision 278959) +++ gcc/cp/pt.c (working copy) @@ -19017,7 +19017,7 @@ tsubst_copy_and_build (tree t, switch (TREE_CODE (t)) { case CAST_EXPR: - r = build_functional_cast (type, op, complain); + r = build_functional_cast (input_location, type, op, complain); break; case REINTERPRET_CAST_EXPR: r = build_reinterpret_cast (type, op, complain); Index: gcc/cp/semantics.c =================================================================== --- gcc/cp/semantics.c (revision 278959) +++ gcc/cp/semantics.c (working copy) @@ -2929,7 +2929,8 @@ finish_compound_literal (tree type, tree compound_ that it came from T{} rather than T({}). */ CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1; compound_literal = build_tree_list (NULL_TREE, compound_literal); - return build_functional_cast (type, compound_literal, complain); + return build_functional_cast (input_location, type, + compound_literal, complain); } if (TREE_CODE (type) == ARRAY_TYPE Index: gcc/cp/typeck2.c =================================================================== --- gcc/cp/typeck2.c (revision 278959) +++ gcc/cp/typeck2.c (working copy) @@ -2228,7 +2228,8 @@ build_m_component_ref (tree datum, tree component, /* Return a tree node for the expression TYPENAME '(' PARMS ')'. */ tree -build_functional_cast (tree exp, tree parms, tsubst_flags_t complain) +build_functional_cast (location_t loc, tree exp, tree parms, + tsubst_flags_t complain) { /* This is either a call to a constructor, or a C cast in C++'s `functional' notation. */ @@ -2254,7 +2255,7 @@ tree if (TREE_CODE (type) == ARRAY_TYPE) { if (complain & tf_error) - error ("functional cast to array type %qT", type); + error_at (loc, "functional cast to array type %qT", type); return error_mark_node; } @@ -2263,7 +2264,7 @@ tree if (!CLASS_PLACEHOLDER_TEMPLATE (anode)) { if (complain & tf_error) - error ("invalid use of %qT", anode); + error_at (loc, "invalid use of %qT", anode); return error_mark_node; } else if (!parms) @@ -2276,8 +2277,8 @@ tree if (type == error_mark_node) { if (complain & tf_error) - error ("cannot deduce template arguments for %qT from %<()%>", - anode); + error_at (loc, "cannot deduce template arguments " + "for %qT from %<()%>", anode); return error_mark_node; } } @@ -2296,7 +2297,7 @@ tree if (TYPE_REF_P (type) && !parms) { if (complain & tf_error) - error ("invalid value-initialization of reference type"); + error_at (loc, "invalid value-initialization of reference type"); return error_mark_node; } Index: gcc/testsuite/g++.dg/cpp0x/auto25.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/auto25.C (revision 278959) +++ gcc/testsuite/g++.dg/cpp0x/auto25.C (working copy) @@ -3,10 +3,10 @@ template struct A { - int a[auto(1)]; // { dg-error "invalid use of" } + int a[auto(1)]; // { dg-error "9:invalid use of" } }; template void foo() { - int a[auto(1)]; // { dg-error "invalid use of" } + int a[auto(1)]; // { dg-error "9:invalid use of" } } Index: gcc/testsuite/g++.dg/cpp0x/auto28.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/auto28.C (revision 278959) +++ gcc/testsuite/g++.dg/cpp0x/auto28.C (working copy) @@ -1,4 +1,4 @@ // PR c++/51404 // { dg-do compile { target c++11 } } -int i = auto().x; // { dg-error "invalid use of" } +int i = auto().x; // { dg-error "9:invalid use of" } Index: gcc/testsuite/g++.dg/diagnostic/functional-cast-to-array-type-1.C =================================================================== --- gcc/testsuite/g++.dg/diagnostic/functional-cast-to-array-type-1.C (nonexistent) +++ gcc/testsuite/g++.dg/diagnostic/functional-cast-to-array-type-1.C (working copy) @@ -0,0 +1,2 @@ +typedef int A [1]; +A a = A(1); // { dg-error "7:functional cast to array type" } Index: gcc/testsuite/g++.dg/init/reference2.C =================================================================== --- gcc/testsuite/g++.dg/init/reference2.C (revision 278959) +++ gcc/testsuite/g++.dg/init/reference2.C (working copy) @@ -8,6 +8,6 @@ template void f() { typedef int& T; - T a = T(); // { dg-error "value-initialization of reference" } + T a = T(); // { dg-error "9:invalid value-initialization of reference" } } Index: gcc/testsuite/g++.dg/parse/template2.C =================================================================== --- gcc/testsuite/g++.dg/parse/template2.C (revision 278959) +++ gcc/testsuite/g++.dg/parse/template2.C (working copy) @@ -3,5 +3,6 @@ namespace N { } int main() { - N::C(); // { dg-error "template|deduction" } + N::C(); // { dg-error "6:cannot deduce template arguments" "" { target c++17 } } + // { dg-error "7:missing template arguments" "" { target c++14_down } .-1 } } Index: gcc/testsuite/g++.dg/template/error8.C =================================================================== --- gcc/testsuite/g++.dg/template/error8.C (revision 278959) +++ gcc/testsuite/g++.dg/template/error8.C (working copy) @@ -3,5 +3,6 @@ template struct S {}; void f() { - throw S (); // { dg-error "template" } + throw S (); // { dg-error "9:cannot deduce template arguments" "" { target c++17 } } + // { dg-error "11:missing template arguments" "" { target c++14_down } .-1 } } Index: gcc/testsuite/g++.old-deja/g++.ns/crash3.C =================================================================== --- gcc/testsuite/g++.old-deja/g++.ns/crash3.C (revision 278959) +++ gcc/testsuite/g++.old-deja/g++.ns/crash3.C (working copy) @@ -6,5 +6,6 @@ namespace N { void f() { - N::S(); // { dg-error "" } invalid use of template + N::S(); // { dg-error "6:cannot deduce template arguments" "" { target c++17 } } invalid use of template + // { dg-error "7:missing template arguments" "" { target c++14_down } .-1 } } Index: gcc/testsuite/g++.old-deja/g++.ns/template7.C =================================================================== --- gcc/testsuite/g++.old-deja/g++.ns/template7.C (revision 278959) +++ gcc/testsuite/g++.old-deja/g++.ns/template7.C (working copy) @@ -8,5 +8,6 @@ namespace foo { } void baz() { - foo::bar(); // { dg-error "" } template used as expression + foo::bar(); // { dg-error "8:cannot deduce template arguments" "" { target c++17 } } template used as expression + // { dg-error "11:missing template arguments" "" { target c++14_down } .-1 } } Index: gcc/testsuite/g++.old-deja/g++.pt/crash8.C =================================================================== --- gcc/testsuite/g++.old-deja/g++.pt/crash8.C (revision 278959) +++ gcc/testsuite/g++.old-deja/g++.pt/crash8.C (working copy) @@ -21,10 +21,12 @@ void doit(T x) { q2 = TestClass2(); TestClass1 p1; - p1 = TestClass1(); // { dg-error "" } template used as expression + p1 = TestClass1(); // { dg-error "8:cannot deduce template arguments" "" { target c++17 } } template used as expression + // { dg-error "18:missing template arguments" "" { target c++14_down } .-1 } TestClass2 p2; - p2 = TestClass2(); // { dg-error "" } template used as expression + p2 = TestClass2(); // { dg-error "8:cannot deduce template arguments" "" { target c++17 } } template used as expression + // { dg-error "18:missing template arguments" "" { target c++14_down } .-1 } } int main() { Index: libcc1/libcp1plugin.cc =================================================================== --- libcc1/libcp1plugin.cc (revision 278959) +++ libcc1/libcp1plugin.cc (working copy) @@ -3155,7 +3155,7 @@ plugin_build_expression_list_expr (cc1_plugin::con case CHARS2 ('c', 'v'): // conversion with parenthesized expression list gcc_assert (TYPE_P (type)); args = args_to_tree_list (values_in); - result = build_functional_cast (type, args, tf_error); + result = build_functional_cast (input_location, type, args, tf_error); break; case CHARS2 ('t', 'l'): // conversion with braced expression list