From patchwork Tue Jun 7 16:03:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 631700 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 3rPGbL17p3z9t0t for ; Wed, 8 Jun 2016 02:04:13 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=XOqXbJpG; 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:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=AcvwtSKloGmUVSclxQDa8fAuJhK7IIciXFzy+c11U3I1ipx/r9 /LgP2+3YzCok7DxmuiEjc04S/sfd/eqtwb0hg99IWnFjYNG4CFkjaWyJwbinO8iy yhRJN4YiiP+c+oKlDHKt0gmp3QxcWhTnPgbsQFYAcSg+KwmKbuifJLNu4= 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=Lgv12w6kLvIL7R7oLGOYliALHgs=; b=XOqXbJpGMF/XI86NrAS5 pCGAF/ZVxQMzX/a4y0yT9TjEGi5/nnxzQBr62q6SHSG0NiS4cygU9mOchT//BlBR P1+XpL3roObnRxFLn8CR5DuciRS7lVjfUkrN3QK8ZaR2OsE80diC04eIyRdqN/NX MNjNFse7UsCURMb/8WNdYmk= Received: (qmail 61225 invoked by alias); 7 Jun 2016 16:04:06 -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 60719 invoked by uid 89); 7 Jun 2016 16:04:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=auditing, tidy, 17, 8, tre X-HELO: aserp1040.oracle.com Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 07 Jun 2016 16:03:53 +0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u57G3oo2001367 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 7 Jun 2016 16:03:51 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u57G3oVa010434 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 7 Jun 2016 16:03:50 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id u57G3lrH010350; Tue, 7 Jun 2016 16:03:48 GMT Received: from [192.168.1.4] (/79.12.211.42) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 07 Jun 2016 09:03:46 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Fix some simple location issues Message-ID: <5756F060.3020609@oracle.com> Date: Tue, 7 Jun 2016 18:03:44 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, in parallel with other work, I'm auditing the front-end for simple location issues which can be fixed immediately. These I noticed in decl.c over the last couple of days. Slightly more interesting, for some error messages we didn't seem to have testcases, certainly not in g++.dg, thus I added some elementary ones covering the locations too. Tested x86_64-linux. Thanks, Paolo. /////////////////////////// /cp 2016-06-07 Paolo Carlini * decl.c (maybe_deduce_size_from_array_init): Use DECL_SOURCE_LOCATION in error_at. (layout_var_decl): Likewise. (check_array_initializer): Likewise. (check_initializer): Likewise. (duplicate_decls, check_elaborated_type_specifier): Tidy. /testsuite 2016-06-07 Paolo Carlini * g++.dg/init/array42.C: New. * g++.dg/init/array43.C: Likewise. * g++.dg/init/array44.C: Likewise. * g++.dg/init/array45.C: Likewise. * g++.dg/cpp0x/constexpr-ice10.C: Test column number too. * g++.dg/cpp0x/constexpr-incomplete1.C: Likewise. * g++.dg/cpp1y/auto-fn27.C: Likewise. * g++.dg/gomp/pr35751.C: Likewise. * g++.dg/init/array23.C: Likewise. * g++.dg/init/brace2.C: Likewise. * g++.dg/init/brace6.C: Likewise. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 237171) +++ cp/decl.c (working copy) @@ -1393,7 +1393,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool { if (DECL_INITIAL (olddecl)) inform (DECL_SOURCE_LOCATION (olddecl), - "previous definition of %q+D was here", olddecl); + "previous definition of %qD was here", olddecl); else inform (DECL_SOURCE_LOCATION (olddecl), "previous declaration of %qD was here", olddecl); @@ -5266,13 +5266,15 @@ maybe_deduce_size_from_array_init (tree decl, tree do_default); if (failure == 1) { - error ("initializer fails to determine size of %qD", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "initializer fails to determine size of %qD", decl); } else if (failure == 2) { if (do_default) { - error ("array size missing in %qD", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "array size missing in %qD", decl); } /* If a `static' var's size isn't known, make it extern as well as static, so it does not get allocated. If it's not @@ -5283,7 +5285,8 @@ maybe_deduce_size_from_array_init (tree decl, tree } else if (failure == 3) { - error ("zero-size array %qD", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "zero-size array %qD", decl); } } @@ -5322,7 +5325,8 @@ layout_var_decl (tree decl) /* An automatic variable with an incomplete type: that is an error. Don't talk about array types here, since we took care of that message in grokdeclarator. */ - error ("storage size of %qD isn%'t known", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "storage size of %qD isn%'t known", decl); TREE_TYPE (decl) = error_mark_node; } #if 0 @@ -5345,7 +5349,8 @@ layout_var_decl (tree decl) constant_expression_warning (DECL_SIZE (decl)); else { - error ("storage size of %qD isn%'t constant", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "storage size of %qD isn%'t constant", decl); TREE_TYPE (decl) = error_mark_node; } } @@ -5954,7 +5959,8 @@ check_array_initializer (tree decl, tree type, tre if (!COMPLETE_TYPE_P (complete_type (element_type))) { if (decl) - error ("elements of array %q#D have incomplete type", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "elements of array %q#D have incomplete type", decl); else error ("elements of array %q#T have incomplete type", type); return true; @@ -6018,7 +6024,8 @@ check_initializer (tree decl, tree init, int flags } else if (!COMPLETE_TYPE_P (type)) { - error ("%q#D has incomplete type", decl); + error_at (DECL_SOURCE_LOCATION (decl), + "%q#D has incomplete type", decl); TREE_TYPE (decl) = error_mark_node; return NULL_TREE; } @@ -6038,8 +6045,9 @@ check_initializer (tree decl, tree init, int flags } else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE) { - error ("scalar object %qD requires one element in initializer", - decl); + error_at (DECL_SOURCE_LOCATION (decl), + "scalar object %qD requires one element in " + "initializer", decl); TREE_TYPE (decl) = error_mark_node; return NULL_TREE; } @@ -6081,9 +6089,10 @@ check_initializer (tree decl, tree init, int flags { /* Don't reshape if the class has constructors. */ if (cxx_dialect == cxx98) - error ("in C++98 %qD must be initialized by constructor, " - "not by %<{...}%>", - decl); + error_at (DECL_SOURCE_LOCATION (decl), + "in C++98 %qD must be initialized by " + "constructor, not by %<{...}%>", + decl); } else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type)) { @@ -6175,8 +6184,10 @@ check_initializer (tree decl, tree init, int flags && DECL_INITIAL (decl) && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl))) - warning (0, "array %qD initialized by parenthesized string literal %qE", - decl, DECL_INITIAL (decl)); + warning_at (DECL_SOURCE_LOCATION (decl), 0, + "array %qD initialized by parenthesized " + "string literal %qE", + decl, DECL_INITIAL (decl)); init = NULL; } } @@ -12528,7 +12539,7 @@ check_elaborated_type_specifier (enum tag_types ta && tag_code != typename_type) { error ("%qT referred to as %qs", type, tag_name (tag_code)); - inform (input_location, "%q+T has a previous declaration here", type); + inform (location_of (type), "%qT has a previous declaration here", type); return error_mark_node; } else if (TREE_CODE (type) != ENUMERAL_TYPE @@ -12535,7 +12546,7 @@ check_elaborated_type_specifier (enum tag_types ta && tag_code == enum_type) { error ("%qT referred to as enum", type); - inform (input_location, "%q+T has a previous declaration here", type); + inform (location_of (type), "%qT has a previous declaration here", type); return error_mark_node; } else if (!allow_template_p Index: testsuite/g++.dg/cpp0x/constexpr-ice10.C =================================================================== --- testsuite/g++.dg/cpp0x/constexpr-ice10.C (revision 237171) +++ testsuite/g++.dg/cpp0x/constexpr-ice10.C (working copy) @@ -4,5 +4,5 @@ struct A { constexpr A() {} - static constexpr A a[2] = {}; // { dg-error "incomplete" } + static constexpr A a[2] = {}; // { dg-error "22:elements of array 'constexpr const A A::a \\\[2\\\]' have incomplete type" } }; Index: testsuite/g++.dg/cpp0x/constexpr-incomplete1.C =================================================================== --- testsuite/g++.dg/cpp0x/constexpr-incomplete1.C (revision 237171) +++ testsuite/g++.dg/cpp0x/constexpr-incomplete1.C (working copy) @@ -2,6 +2,6 @@ struct A { - static constexpr A a = 1; // { dg-error "incomplete" } + static constexpr A a = 1; // { dg-error "22:'constexpr const A A::a' has incomplete type" } constexpr A(int i) { } }; Index: testsuite/g++.dg/cpp1y/auto-fn27.C =================================================================== --- testsuite/g++.dg/cpp1y/auto-fn27.C (revision 237171) +++ testsuite/g++.dg/cpp1y/auto-fn27.C (working copy) @@ -31,7 +31,7 @@ F::bar (const G &) { auto s = I; typedef decltype (s) L; - auto u =[&](L) { auto t = foo (J::K (), 0); }; // { dg-error "" } + auto u =[&](L) { auto t = foo (J::K (), 0); }; // { dg-error "25:'void t' has incomplete type" } } struct B { typedef int G; Index: testsuite/g++.dg/gomp/pr35751.C =================================================================== --- testsuite/g++.dg/gomp/pr35751.C (revision 237171) +++ testsuite/g++.dg/gomp/pr35751.C (working copy) @@ -5,8 +5,8 @@ void foo (int i) { - extern int a[i]; // { dg-error "storage size of" } - static int b[i]; // { dg-error "storage size of" } + extern int a[i]; // { dg-error "14:storage size of" } + static int b[i]; // { dg-error "14:storage size of" } #pragma omp parallel { Index: testsuite/g++.dg/init/array23.C =================================================================== --- testsuite/g++.dg/init/array23.C (revision 237171) +++ testsuite/g++.dg/init/array23.C (working copy) @@ -3,4 +3,4 @@ // array struct A {A();int A::* t;}; -A x[]; // { dg-error "size" } +A x[]; // { dg-error "3:array size missing" } Index: testsuite/g++.dg/init/array42.C =================================================================== --- testsuite/g++.dg/init/array42.C (revision 0) +++ testsuite/g++.dg/init/array42.C (working copy) @@ -0,0 +1 @@ +char a[] = ("abc"); // { dg-warning "6:array 'a' initialized by parenthesized string literal" } Index: testsuite/g++.dg/init/array43.C =================================================================== --- testsuite/g++.dg/init/array43.C (revision 0) +++ testsuite/g++.dg/init/array43.C (working copy) @@ -0,0 +1,2 @@ +int a[] = 0; // { dg-error "5:initializer fails to determine size" } +// { dg-error "11:array must be initialized" "" { target *-*-* } 1 } Index: testsuite/g++.dg/init/array44.C =================================================================== --- testsuite/g++.dg/init/array44.C (revision 0) +++ testsuite/g++.dg/init/array44.C (working copy) @@ -0,0 +1 @@ +int a[] = { }; // { dg-error "5:zero-size array" } Index: testsuite/g++.dg/init/array45.C =================================================================== --- testsuite/g++.dg/init/array45.C (revision 0) +++ testsuite/g++.dg/init/array45.C (working copy) @@ -0,0 +1 @@ +int a[]; // { dg-error "5:storage size" } Index: testsuite/g++.dg/init/brace2.C =================================================================== --- testsuite/g++.dg/init/brace2.C (revision 237171) +++ testsuite/g++.dg/init/brace2.C (working copy) @@ -3,6 +3,6 @@ int x = { 2 }; const char * y = { "hello" }; int a = 2; -int b = { 2,3 }; // { dg-error "requires one element in initializer" } +int b = { 2,3 }; // { dg-error "5:scalar object 'b' requires one element in initializer" } int c = { { 2 } } ; // { dg-error "braces around scalar initializer" } int d = {}; // { dg-error "initializer" "" { target { ! c++11 } } } Index: testsuite/g++.dg/init/brace6.C =================================================================== --- testsuite/g++.dg/init/brace6.C (revision 237171) +++ testsuite/g++.dg/init/brace6.C (working copy) @@ -17,8 +17,8 @@ struct D { int c; }; int main() { int i = { 1 }; - int j = { 1, 2 }; /* { dg-error "requires one element" } */ - A a = { 6 }; /* { dg-error "initialize" "" { target { ! c++11 } } } */ + int j = { 1, 2 }; /* { dg-error "8:scalar object 'j' requires one element" } */ + A a = { 6 }; /* { dg-error "6:in C\\+\\+98 'a' must be initialized" "" { target { ! c++11 } } } */ B b = { 6 }; /* { dg-error "" } */ C c = { 6 }; /* { dg-error "too many initializers" } */ D d = { 6 };