From patchwork Fri Apr 25 15:44:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 342909 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 84F881400CB for ; Sat, 26 Apr 2014 01:45:26 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=gOl3bRFT+c0zwiGCBbVPQMwJg85A7KgzqabEr5tacnAOZl8VkE SeehET5oSzei4xOiU3XMq0BqfPF0DIQ7xLy+c+bkndJxyXYPOHMkPxMtObBDg44d oFVPqpUQNHsonXnnrjV6fYSpWfzjr0QDcpvRcXAltIr1ni9g/7V3EvxKc= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=fa4SrgdePH79sM8YXAiEiu46Q1A=; b=Dg/D7dL9cpCkQlgKhtHA vWTzjPeMBMwy8Yto6WxxYa+T6SzI7i9BwvTlPH2U3MUDzLqGiZ3sOkIvGdhs8ZPS 2uMX8tSDqEkJyC47C9JIUXOt1lhVi8fOaL34TbSLak3pIzXK3Gxkz/b1TySpyPZr gkHy21KFZuN8CjA0YnOxdRc= Received: (qmail 906 invoked by alias); 25 Apr 2014 15:45:19 -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 892 invoked by uid 89); 25 Apr 2014 15:45:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 25 Apr 2014 15:45:17 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3PFiuOw013994 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Apr 2014 11:44:57 -0400 Received: from redhat.com (ovpn-116-53.ams2.redhat.com [10.36.116.53]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3PFirmI000654 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Fri, 25 Apr 2014 11:44:55 -0400 Date: Fri, 25 Apr 2014 17:44:52 +0200 From: Marek Polacek To: GCC Patches Cc: "Joseph S. Myers" Subject: [C PATCH] Better column info for initializers (PR c/60139) Message-ID: <20140425154452.GS2103@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Another minor fix: use loc instead of input_location. Also add missing OPT_Wpedantic. After this is in, my plan is to make pedwarn_init and error_init static (I already have a patch for that) and then add location argument to error_init and pass proper location to it, and to pedwarn_init as well -- that should greatly improve initializer warnings/errors. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2014-04-25 Marek Polacek PR c/60139 * c-typeck.c (output_init_element): Pass OPT_Wpedantic to pedwarn and pedwarn_init. Use loc insted of input_location. * gcc.dg/pr60139.c: New test. Marek diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index 62c72df..a82801f 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -8255,12 +8255,12 @@ output_init_element (location_t loc, tree value, tree origtype, value = error_mark_node; } else if (require_constant_elements) - pedwarn (input_location, 0, + pedwarn (loc, OPT_Wpedantic, "initializer element is not computable at load time"); } else if (!maybe_const && (require_constant_value || require_constant_elements)) - pedwarn_init (input_location, 0, + pedwarn_init (loc, OPT_Wpedantic, "initializer element is not a constant expression"); /* Issue -Wc++-compat warnings about initializing a bitfield with diff --git gcc/testsuite/gcc.dg/pr60139.c gcc/testsuite/gcc.dg/pr60139.c index e69de29..a63d8b5 100644 --- gcc/testsuite/gcc.dg/pr60139.c +++ gcc/testsuite/gcc.dg/pr60139.c @@ -0,0 +1,14 @@ +/* PR c/60139 */ +/* { dg-do compile } */ +/* { dg-options "-Wpedantic" } */ +/* { dg-prune-output ".*near initialization for.*" } */ + +double sin (double); +void +fn (int *p) +{ + int **a[] = { &p, /* { dg-warning "17:initializer element is not computable at load time" } */ + (void *) 0, &p }; /* { dg-warning "28:initializer element is not computable at load time" } */ + double d[] = { sin (1.0), /* { dg-warning "18:initializer element is not a constant expression" } */ + 8.8, sin (1.0), 2.6 }; /* { dg-warning "23:initializer element is not a constant expression" } */ +}