From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31322 invoked by alias); 21 Jul 2006 01:42:36 -0000 Received: (qmail 31292 invoked by uid 48); 21 Jul 2006 01:42:28 -0000 Date: Fri, 21 Jul 2006 01:42:00 -0000 Message-ID: <20060721014228.31291.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c++/28031] [4.2 regression] bogus jump to case label crosses initialization error with C99 anonymous initializers In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "mmitchel at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-07/txt/msg01621.txt.bz2 List-Id: ------- Comment #4 from mmitchel at gcc dot gnu dot org 2006-07-21 01:42 ------- In C99, a compound literal in the body of a function has automatic storage duration associated with the enclosing block. That's what the C++ front end now does. In that context, the error given is entirely reasonable; it's the same error you would get for: switch (n) { int i = 3; case 1: ; } since here, "i" is a variable in scope. (C99 doesn't disallow this case, apparently, but C++ does.) The counter-argument is that perhaps in C++ compound-literals should have storage duration that lasts only until the enclosing full expression. However, that would be an incompatibility with C99, as things like: struct S *p = &(struct S){3}; p->i = 7; would then be valid C99 (as the object is in scope), but undefined in C++ (as the anonymous variable would have gone out of scope). Therefore, I believe the current C++ implementation to make the most sense, absent clear direction from the ISO C++ committee. -- mmitchel at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28031