This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/28031] [4.2 regression] bogus jump to case label crosses initialization error with C99 anonymous initializers



------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]