From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27064 invoked by alias); 21 May 2008 14:29:03 -0000 Received: (qmail 27054 invoked by uid 22791); 21 May 2008 14:29:02 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 21 May 2008 14:28:34 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m4LESWbD013292 for ; Wed, 21 May 2008 10:28:32 -0400 Received: from file.rdu.redhat.com (file.rdu.redhat.com [10.11.255.147]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m4LESVG3009701; Wed, 21 May 2008 10:28:31 -0400 Received: from devserv.devel.redhat.com (devserv.devel.redhat.com [10.10.36.72]) by file.rdu.redhat.com (8.13.1/8.13.1) with ESMTP id m4LESVQC019820; Wed, 21 May 2008 10:28:31 -0400 Received: from devserv.devel.redhat.com (localhost.localdomain [127.0.0.1]) by devserv.devel.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id m4LESVUK010551; Wed, 21 May 2008 10:28:31 -0400 Received: (from jakub@localhost) by devserv.devel.redhat.com (8.12.11.20060308/8.12.11/Submit) id m4LESV2O010549; Wed, 21 May 2008 10:28:31 -0400 Date: Wed, 21 May 2008 15:05:00 -0000 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: Re: Patch ping Message-ID: <20080521142831.GG29975@devserv.devel.redhat.com> Reply-To: Jakub Jelinek References: <20080507083202.GI2255@devserv.devel.redhat.com> <4821C23A.3040906@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4821C23A.3040906@redhat.com> User-Agent: Mutt/1.4.1i X-IsSubscribed: yes 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 X-SW-Source: 2008-05/txt/msg01311.txt.bz2 On Wed, May 07, 2008 at 10:52:42AM -0400, Jason Merrill wrote: > Jakub Jelinek wrote: > >- C++ compound literal diagnostics PR c++/36023 P2 4.3/4.4 > > http://gcc.gnu.org/ml/gcc-patches/2008-04/msg02045.html > > Rather than duplicating code, please split out the parts of > check_initializer that are also appropriate for finish_compound_literal. Sorry for getting to this so late. check_initializer has: if (TREE_CODE (type) == ARRAY_TYPE) { tree element_type = TREE_TYPE (type); /* The array type itself need not be complete, because the initializer may tell us how many elements are in the array. But, the elements of the array must be complete. */ if (!COMPLETE_TYPE_P (complete_type (element_type))) { error ("elements of array %q#D have incomplete type", decl); return NULL_TREE; } /* It is not valid to initialize a VLA. */ if (init && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type))) || !TREE_CONSTANT (TYPE_SIZE (element_type)))) { error ("variable-sized object %qD may not be initialized", decl); return NULL_TREE; } } While the 3 if conditions can be the same (assuming finish_compound_literal passes compound_literal as init), the problem is with the diagnostics, as finish_compound_literal doesn't have any decl, just the type, and in check_initializer reporting the decl is really preferrable over just returning the type. So, if I were to move the above into separate function, it would need to special case that, say: bool check_array_initializer (tree decl, tree type, tree init) { if (TREE_CODE (type) == ARRAY_TYPE) { tree element_type = TREE_TYPE (type); /* The array type itself need not be complete, because the initializer may tell us how many elements are in the array. But, the elements of the array must be complete. */ if (!COMPLETE_TYPE_P (complete_type (element_type))) { if (decl) error ("elements of array %q#D have incomplete type", decl); else error ("elements of array %q#T have incomplete type", type); return true; } /* It is not valid to initialize a VLA. */ if (init && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type))) || !TREE_CONSTANT (TYPE_SIZE (element_type)))) { if (decl) error ("variable-sized object %qD may not be initialized", decl); else error ("variable-sized compound literal"); return true; } } return false; } and check_initializer replacing its code with if (check_array_initializer (decl, type, init)) return NULL_TREE; and finish_compound_literal adding: if (check_array_initializer (NULL_TREE, type, compound_literal)) return error_mark_node; I think this is uglification rather than cleanup, especially given the size of the duplicated code and that the error messages need to be different, but certainly if you prefer it that way, I can write a patch. Jakub