From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13955 invoked by alias); 17 Oct 2014 11:25:55 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 13945 invoked by uid 89); 17 Oct 2014 11:25:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 17 Oct 2014 11:25:53 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9HBPnov014924 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 17 Oct 2014 07:25:49 -0400 Received: from redhat.com (ovpn-116-16.ams2.redhat.com [10.36.116.16]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s9HBPj1X019105 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Fri, 17 Oct 2014 07:25:48 -0400 Date: Fri, 17 Oct 2014 11:46:00 -0000 From: Marek Polacek To: GCC Patches , "Joseph S. Myers" Subject: [C PATCH] Enable initializing statics with COMPOUND_LITERAL_EXPR in C99 (PR c/63567) Message-ID: <20141017112544.GR10501@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2014-10/txt/msg01698.txt.bz2 Building Linux kernel failed with 'error: initializer element is not constant', because they're initializing objects with static storage duration with (T){ ...} - and that isn't permitted in gnu99/gnu11. I think the Right Thing is to allow some latitude here and enable it even in gnu99/gnu11 unless -pedantic. In gnu89, this will work as before even with -pedantic. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2014-10-17 Marek Polacek PR c/63567 * c-typeck.c (digest_init): Allow initializing objects with static storage duration with compound literals in non-pedantic mode. * gcc.dg/pr63567.c: New test. diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index 5c0697a..8ddf368 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -6676,7 +6676,7 @@ digest_init (location_t init_loc, tree type, tree init, tree origtype, inside_init = convert (type, inside_init); if (require_constant - && (code == VECTOR_TYPE || !flag_isoc99) + && (code == VECTOR_TYPE || !pedantic || !flag_isoc99) && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR) { /* As an extension, allow initializing objects with static storage diff --git gcc/testsuite/gcc.dg/pr63567.c gcc/testsuite/gcc.dg/pr63567.c index e69de29..cf942ef 100644 --- gcc/testsuite/gcc.dg/pr63567.c +++ gcc/testsuite/gcc.dg/pr63567.c @@ -0,0 +1,11 @@ +/* PR c/63567 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +/* Allow initializing objects with static storage duration with + compound literals even in non-pedantic gnu99/gnu11. This is + being used in Linux kernel. */ + +struct T { int i; }; +struct S { struct T t; }; +static struct S s = (struct S) { .t = { 42 } }; Marek