public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15938] New: ICE with anonymous unions
@ 2004-06-11 12:24 reichelt at gcc dot gnu dot org
  2004-06-11 13:33 ` [Bug c++/15938] " pinskia at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 16+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2004-06-11 12:24 UTC (permalink / raw)
  To: gcc-bugs

The following code is accepted by the C frontend, but the C++ frontend
segfaults (since gcc 2.95.x).

===================================
typedef union
{
    struct { int i; };
    struct { char c; };
} A;

A a = { 0 };
===================================

bug.cc:7: error: union `A' with no named members cannot be initialized
bug.cc:7: internal compiler error: Segmentation fault
Please submit a full bug report, [etc.]

Apart from the segfault, should the code be accepted by the C++ frontend
as well or should it be rejected as it is now?

BTW, the PR was inspired by a question on the gcc mailing list:
http://gcc.gnu.org/ml/gcc/2004-06/msg00158.html

-- 
           Summary: ICE with anonymous unions
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Keywords: ice-on-invalid-code
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: reichelt at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
  2004-06-11 12:24 [Bug c++/15938] New: ICE with anonymous unions reichelt at gcc dot gnu dot org
@ 2004-06-11 13:33 ` pinskia at gcc dot gnu dot org
  2005-01-06  2:02 ` pinskia at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-11 13:33 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-11 13:33 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
      Known to fail|                            |2.95.3 3.0.4 3.2.2 3.2.3
                   |                            |3.3.1 3.5.0 3.4.0
   Last reconfirmed|0000-00-00 00:00:00         |2004-06-11 13:33:16
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
  2004-06-11 12:24 [Bug c++/15938] New: ICE with anonymous unions reichelt at gcc dot gnu dot org
  2004-06-11 13:33 ` [Bug c++/15938] " pinskia at gcc dot gnu dot org
@ 2005-01-06  2:02 ` pinskia at gcc dot gnu dot org
  2005-03-20 20:13 ` pcarlini at suse dot de
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-06  2:02 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |error-recovery
   Last reconfirmed|2004-06-11 13:33:16         |2005-01-06 02:02:15
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
  2004-06-11 12:24 [Bug c++/15938] New: ICE with anonymous unions reichelt at gcc dot gnu dot org
  2004-06-11 13:33 ` [Bug c++/15938] " pinskia at gcc dot gnu dot org
  2005-01-06  2:02 ` pinskia at gcc dot gnu dot org
@ 2005-03-20 20:13 ` pcarlini at suse dot de
  2005-07-20 13:46 ` reichelt at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: pcarlini at suse dot de @ 2005-03-20 20:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pcarlini at suse dot de  2005-03-20 20:13 -------
Seenms doable...

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |pcarlini at suse dot de
                   |dot org                     |
             Status|NEW                         |ASSIGNED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
  2004-06-11 12:24 [Bug c++/15938] New: ICE with anonymous unions reichelt at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2005-03-20 20:13 ` pcarlini at suse dot de
@ 2005-07-20 13:46 ` reichelt at gcc dot gnu dot org
  2005-07-21  2:08 ` giovannibajo at libero dot it
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2005-07-20 13:46 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From reichelt at gcc dot gnu dot org  2005-07-20 13:17 -------
On mainline the code is accepted since today.

This is probably due to Giovanni's patch
http://gcc.gnu.org/ml/gcc-cvs/2005-07/msg00718.html


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |giovannibajo at gcc dot gnu
                   |                            |dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
  2004-06-11 12:24 [Bug c++/15938] New: ICE with anonymous unions reichelt at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2005-07-20 13:46 ` reichelt at gcc dot gnu dot org
@ 2005-07-21  2:08 ` giovannibajo at libero dot it
  2005-07-21  2:53 ` gdr at integrable-solutions dot net
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: giovannibajo at libero dot it @ 2005-07-21  2:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2005-07-21 01:51 -------
Yes, it's because of my patch.

I would like to know if we agree that the code is invalid or not. It's a bit 
hard to have a definitive answer since it is GNU C++ (uses an extension), but 
given that the C frontend accepts it, I don't see why we should reject it. In 
which case, this bug can be closed as fixed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gdr at gcc dot gnu dot org,
                   |                            |nathan at gcc dot gnu dot
                   |                            |org
         AssignedTo|pcarlini at suse dot de     |giovannibajo at libero dot
                   |                            |it


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
  2004-06-11 12:24 [Bug c++/15938] New: ICE with anonymous unions reichelt at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2005-07-21  2:08 ` giovannibajo at libero dot it
@ 2005-07-21  2:53 ` gdr at integrable-solutions dot net
  2005-07-21 13:23 ` giovannibajo at libero dot it
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: gdr at integrable-solutions dot net @ 2005-07-21  2:53 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gdr at integrable-solutions dot net  2005-07-21 02:35 -------
Subject: Re:  ICE with anonymous unions

"giovannibajo at libero dot it" <gcc-bugzilla@gcc.gnu.org> writes:

| Yes, it's because of my patch.
| 
| I would like to know if we agree that the code is invalid or not. It's a bit 
| hard to have a definitive answer since it is GNU C++ (uses an extension), but 
| given that the C frontend accepts it, I don't see why we should reject it. In 
| which case, this bug can be closed as fixed.

[I will address the validity issue as far as GNU C++ is concerned ]

Clearly, this being invalid according to ISO C++ and accepted by the C
front-end (with appropriate diagnostic), the only question that
remains is whether this is valid C++

  typedef union {
     struct unique_name_1 { int i; };
     struct unique_name_2 { char c; };
  } A;

The answer is yes.  Now, the remaning thing is apply the name 
restrictions as for unnamed unions.

Thanks,

-- Gaby


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
  2004-06-11 12:24 [Bug c++/15938] New: ICE with anonymous unions reichelt at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2005-07-21  2:53 ` gdr at integrable-solutions dot net
@ 2005-07-21 13:23 ` giovannibajo at libero dot it
  2005-07-21 15:12 ` cvs-commit at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: giovannibajo at libero dot it @ 2005-07-21 13:23 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2005-07-21 13:18 -------
=================================================
typedef union
{
  struct { int i; };
  struct { char c; };
} A;

A a = { 0 };
A b = {{ 0 }};
A c = {{{ 0 }}};     // { dg-error "braces" }
=================================================
pr15938.cc:9: error: braces around scalar initializer for type 'int'

I believe everything is correct.
Volker, would you mind committing this testcase and closing this bug?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.1.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
  2004-06-11 12:24 [Bug c++/15938] New: ICE with anonymous unions reichelt at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2005-07-21 13:23 ` giovannibajo at libero dot it
@ 2005-07-21 15:12 ` cvs-commit at gcc dot gnu dot org
  2005-07-21 15:15 ` reichelt at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-07-21 15:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-07-21 14:50 -------
Subject: Bug 15938

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	reichelt@gcc.gnu.org	2005-07-21 14:50:47

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/init: union2.C 

Log message:
	PR c++/15938
	* g++.dg/init/union2.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5795&r2=1.5796
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/union2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
  2004-06-11 12:24 [Bug c++/15938] New: ICE with anonymous unions reichelt at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2005-07-21 15:12 ` cvs-commit at gcc dot gnu dot org
@ 2005-07-21 15:15 ` reichelt at gcc dot gnu dot org
  2005-07-21 15:56 ` giovannibajo at libero dot it
  2005-07-23  5:03 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 16+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2005-07-21 15:15 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From reichelt at gcc dot gnu dot org  2005-07-21 15:12 -------
The ICE is fixed now. But maybe some additional code cleanup is needed:\x13

Giovanni, what about the following code snippet from typeck2.c?
Is the comment still valid? What about the error message, is it
still triggered in some cases?

      /* Find the first named field.  ANSI decided in September 1990
	 that only named fields count here.  */
      tree field = TYPE_FIELDS (type);
      while (field && (!DECL_NAME (field) || TREE_CODE (field) != FIELD_DECL))
	field = TREE_CHAIN (field);
      if (!field)
	{
	  error ("union %qT with no named members cannot be initialized",
		 type);
	  ce->value = error_mark_node;
	}
      ce->index = field;


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
  2004-06-11 12:24 [Bug c++/15938] New: ICE with anonymous unions reichelt at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2005-07-21 15:15 ` reichelt at gcc dot gnu dot org
@ 2005-07-21 15:56 ` giovannibajo at libero dot it
  2005-07-23  5:03 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 16+ messages in thread
From: giovannibajo at libero dot it @ 2005-07-21 15:56 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2005-07-21 15:32 -------
It might indeed be obsolete code: I don't think you can currently create an 
union (or a record) with only unnamed fields. If you want to purse this 
further, you could regtest changing this:

      if (!field)
	{
	  error ("union %qT with no named members cannot be initialized",
		 type);
	  ce->value = error_mark_node;
	}

with "gcc_assert (field);". Which will probably succeed, as there are no 
occurrences of this error message in my last g++.log.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
  2004-06-11 12:24 [Bug c++/15938] New: ICE with anonymous unions reichelt at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2005-07-21 15:56 ` giovannibajo at libero dot it
@ 2005-07-23  5:03 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-23  5:03 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
       [not found] <bug-15938-1771@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2005-11-25 15:45 ` reichelt at gcc dot gnu dot org
@ 2005-11-27 23:38 ` giovannibajo at libero dot it
  3 siblings, 0 replies; 16+ messages in thread
From: giovannibajo at libero dot it @ 2005-11-27 23:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from giovannibajo at libero dot it  2005-11-27 23:38 -------
Thanks Volker


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
       [not found] <bug-15938-1771@http.gcc.gnu.org/bugzilla/>
  2005-10-05 19:37 ` pinskia at gcc dot gnu dot org
  2005-10-13 11:22 ` reichelt at gcc dot gnu dot org
@ 2005-11-25 15:45 ` reichelt at gcc dot gnu dot org
  2005-11-27 23:38 ` giovannibajo at libero dot it
  3 siblings, 0 replies; 16+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2005-11-25 15:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from reichelt at gcc dot gnu dot org  2005-11-25 15:45 -------
I removed the dead code as discussed in comment #8 and later:
http://gcc.gnu.org/ml/gcc-cvs/2005-11/msg01213.html


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
       [not found] <bug-15938-1771@http.gcc.gnu.org/bugzilla/>
  2005-10-05 19:37 ` pinskia at gcc dot gnu dot org
@ 2005-10-13 11:22 ` reichelt at gcc dot gnu dot org
  2005-11-25 15:45 ` reichelt at gcc dot gnu dot org
  2005-11-27 23:38 ` giovannibajo at libero dot it
  3 siblings, 0 replies; 16+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2005-10-13 11:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from reichelt at gcc dot gnu dot org  2005-10-13 11:22 -------
Closing, since the problem is fixed on mainline.

I'll submit a patch to remove the obsolete code once 4.1 has branched.


-- 

reichelt at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
           Keywords|error-recovery, ice-on-     |ice-on-valid-code
                   |invalid-code                |
         Resolution|                            |FIXED
   Target Milestone|---                         |4.1.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/15938] ICE with anonymous unions
       [not found] <bug-15938-1771@http.gcc.gnu.org/bugzilla/>
@ 2005-10-05 19:37 ` pinskia at gcc dot gnu dot org
  2005-10-13 11:22 ` reichelt at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-10-05 19:37 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.1.0                       |---


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15938


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2005-11-27 23:38 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-11 12:24 [Bug c++/15938] New: ICE with anonymous unions reichelt at gcc dot gnu dot org
2004-06-11 13:33 ` [Bug c++/15938] " pinskia at gcc dot gnu dot org
2005-01-06  2:02 ` pinskia at gcc dot gnu dot org
2005-03-20 20:13 ` pcarlini at suse dot de
2005-07-20 13:46 ` reichelt at gcc dot gnu dot org
2005-07-21  2:08 ` giovannibajo at libero dot it
2005-07-21  2:53 ` gdr at integrable-solutions dot net
2005-07-21 13:23 ` giovannibajo at libero dot it
2005-07-21 15:12 ` cvs-commit at gcc dot gnu dot org
2005-07-21 15:15 ` reichelt at gcc dot gnu dot org
2005-07-21 15:56 ` giovannibajo at libero dot it
2005-07-23  5:03 ` pinskia at gcc dot gnu dot org
     [not found] <bug-15938-1771@http.gcc.gnu.org/bugzilla/>
2005-10-05 19:37 ` pinskia at gcc dot gnu dot org
2005-10-13 11:22 ` reichelt at gcc dot gnu dot org
2005-11-25 15:45 ` reichelt at gcc dot gnu dot org
2005-11-27 23:38 ` giovannibajo at libero dot it

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).