public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17323] New: ICE on invalid code if static member array initialized with size computed as division by zero
@ 2004-09-04 18:55 niemayer at isg dot de
  2004-09-04 18:56 ` [Bug c++/17323] " niemayer at isg dot de
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: niemayer at isg dot de @ 2004-09-04 18:55 UTC (permalink / raw)
  To: gcc-bugs

The following tiny piece of C++ code causes an ICE:

---------------------- ice.cxx --------------------------------------
template <class T>
class A {
	static const int x = 1024/sizeof(T);	
	static char i[x];
};

class B : public A<B> { };
-------------------------------------------------------------------

Output after "gcc -c ice.cxx" is:
ice.cxx: In instantiation of `A<B>':
ice.cxx:8:   instantiated from here
ice.cxx:4: error: invalid application of `sizeof' to incomplete type `B' 
ice.cxx:4: warning: division by zero in `1024 / 0'
gcc: Internal error: Segmentation fault (program cc1plus)
Please submit a full bug report.


BTW: I would be very interested to hear if there's a legal (compile-time)
equivalent to the code above - so far I've found only clumsy work-arounds that
need run-time tests.

-- 
           Summary: ICE on invalid code if static member array initialized
                    with size computed as division by zero
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: niemayer at isg dot de
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/17323] ICE on invalid code if static member array initialized with size computed as division by zero
  2004-09-04 18:55 [Bug c++/17323] New: ICE on invalid code if static member array initialized with size computed as division by zero niemayer at isg dot de
@ 2004-09-04 18:56 ` niemayer at isg dot de
  2004-09-06 16:13 ` lerdsuwa at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: niemayer at isg dot de @ 2004-09-04 18:56 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Jens dot Maurer at is-
                   |                            |teledata dot com


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


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

* [Bug c++/17323] ICE on invalid code if static member array initialized with size computed as division by zero
  2004-09-04 18:55 [Bug c++/17323] New: ICE on invalid code if static member array initialized with size computed as division by zero niemayer at isg dot de
  2004-09-04 18:56 ` [Bug c++/17323] " niemayer at isg dot de
@ 2004-09-06 16:13 ` lerdsuwa at gcc dot gnu dot org
  2004-09-06 16:56 ` giovannibajo at libero dot it
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: lerdsuwa at gcc dot gnu dot org @ 2004-09-06 16:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From lerdsuwa at gcc dot gnu dot org  2004-09-06 16:13 -------
Confirm the ICE.

I don't know if this workaround is good enough - A<B> now only
counts the size of B only, the 'x' and 'i' variables not included:

  class B { ... };
  class C: public B, A<B> { ... };


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-09-06 16:13:25
               date|                            |


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


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

* [Bug c++/17323] ICE on invalid code if static member array initialized with size computed as division by zero
  2004-09-04 18:55 [Bug c++/17323] New: ICE on invalid code if static member array initialized with size computed as division by zero niemayer at isg dot de
  2004-09-04 18:56 ` [Bug c++/17323] " niemayer at isg dot de
  2004-09-06 16:13 ` lerdsuwa at gcc dot gnu dot org
@ 2004-09-06 16:56 ` giovannibajo at libero dot it
  2004-09-07 23:53 ` bangerth at dealii dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: giovannibajo at libero dot it @ 2004-09-06 16:56 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-09-06 16:56 -------
This is probably unbroken if we internally return "1" as size of the incomplete 
type, after we emit the diagnostic. After all, no types in C++ can have size 0, 
so expanding sizeof to zero is asking for troubles.

-- 


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


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

* [Bug c++/17323] ICE on invalid code if static member array initialized with size computed as division by zero
  2004-09-04 18:55 [Bug c++/17323] New: ICE on invalid code if static member array initialized with size computed as division by zero niemayer at isg dot de
                   ` (2 preceding siblings ...)
  2004-09-06 16:56 ` giovannibajo at libero dot it
@ 2004-09-07 23:53 ` bangerth at dealii dot org
  2004-09-08  7:04 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2004-09-07 23:53 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-09-07 23:53 -------
Wouldn't we then run into the same problem when using 
  (sizeof(T)-1) 
? 
 
W. 

-- 


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


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

* [Bug c++/17323] ICE on invalid code if static member array initialized with size computed as division by zero
  2004-09-04 18:55 [Bug c++/17323] New: ICE on invalid code if static member array initialized with size computed as division by zero niemayer at isg dot de
                   ` (3 preceding siblings ...)
  2004-09-07 23:53 ` bangerth at dealii dot org
@ 2004-09-08  7:04 ` pinskia at gcc dot gnu dot org
  2005-02-10 20:32 ` [Bug c++/17323] [3.4/4.0 regression] " reichelt at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-08  7:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-09-08 07:04 -------
hmm, the problem looks like it has nothing to do with sizeof at all but it has to do with DECL_INITIAL 
for x still being an INIT_EXPR so we check the first operand for value_dependent_expression_p but 
since that just links back to x, we go into an infinite loop which causes this ICE (stack overflow).
Maybe we should have cleared out the DECL_INITIAL and put a error_node there instead.


Part of the backtrace (I cannot get all of it because it is just repeating two parts of 
alue_dependent_expression_p)

#40392 0x080eab2d in cp_parser_type_specifier (parser=0xf6e128f0, flags=Variable "flags" is not 
available.
) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:12809
warning: Source file is more recent than executable.

12809       CLASSTYPE_DECLARED_CLASS (type) = (class_key == class_type);
(gdb) up -1
#40391 0x080776e1 in xref_basetypes (ref=0xf6e14074, base_list=0xf6e13180) at /home/gates/
pinskia/src/gnu/gcc/src/gcc/cp/decl.c:9136
warning: Source file is more recent than executable.


Also gdb just seg faults on me alot when going through all these stack frames (yes I am using the cvs 
version, I should report a bug).

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-invalid-code


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


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

* [Bug c++/17323] [3.4/4.0 regression] ICE on invalid code if static member array initialized with size computed as division by zero
  2004-09-04 18:55 [Bug c++/17323] New: ICE on invalid code if static member array initialized with size computed as division by zero niemayer at isg dot de
                   ` (4 preceding siblings ...)
  2004-09-08  7:04 ` pinskia at gcc dot gnu dot org
@ 2005-02-10 20:32 ` reichelt at gcc dot gnu dot org
  2005-05-19 17:36 ` [Bug c++/17323] [3.4/4.0/4.1 " mmitchel at gcc dot gnu dot org
  2005-06-14  8:31 ` reichelt at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2005-02-10 20:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From reichelt at gcc dot gnu dot org  2005-02-10 16:14 -------
Here's a reduced testcase without sizeof:

=================================
template<int N> struct A
{
    static const int i = 8/N;
    char c[i];
};

A<0> a;
=================================

The error message is:

mmm.cc: In instantiation of 'A<0>':
mmm.cc:7:   instantiated from here
mmm.cc:3: warning: division by zero in '8 / 0'
g++: Internal error: Segmentation fault (program cc1plus)

The ICE appears with 3.4.0. Before I get the following error message:

mmm.cc: In instantiation of `A<0>':
mmm.cc:7:   instantiated from here
mmm.cc:3: warning: division by zero in `8 / 0'
mmm.cc:7: error: variable-size type declared outside of any function
mmm.cc:7: error: variable-size type declared outside of any function


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |reichelt at gcc dot gnu dot
                   |                            |org
           Keywords|                            |monitored
            Summary|ICE on invalid code if      |[3.4/4.0 regression] ICE on
                   |static member array         |invalid code if static
                   |initialized with size       |member array initialized
                   |computed as division by zero|with size computed as
                   |                            |division by zero
   Target Milestone|---                         |3.4.4


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


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

* [Bug c++/17323] [3.4/4.0/4.1 regression] ICE on invalid code if static member array initialized with size computed as division by zero
  2004-09-04 18:55 [Bug c++/17323] New: ICE on invalid code if static member array initialized with size computed as division by zero niemayer at isg dot de
                   ` (5 preceding siblings ...)
  2005-02-10 20:32 ` [Bug c++/17323] [3.4/4.0 regression] " reichelt at gcc dot gnu dot org
@ 2005-05-19 17:36 ` mmitchel at gcc dot gnu dot org
  2005-06-14  8:31 ` reichelt at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-05-19 17:36 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|3.4.4                       |3.4.5


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


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

* [Bug c++/17323] [3.4/4.0/4.1 regression] ICE on invalid code if static member array initialized with size computed as division by zero
  2004-09-04 18:55 [Bug c++/17323] New: ICE on invalid code if static member array initialized with size computed as division by zero niemayer at isg dot de
                   ` (6 preceding siblings ...)
  2005-05-19 17:36 ` [Bug c++/17323] [3.4/4.0/4.1 " mmitchel at gcc dot gnu dot org
@ 2005-06-14  8:31 ` reichelt at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2005-06-14  8:31 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From reichelt at gcc dot gnu dot org  2005-06-14 08:30 -------
Fixed by Nathan's patch for PR 20789.

Fixed already on mainline and 3.4 branch.
The patch will be applied to the 4.0 branch once GCC 4.0.1 is out.
So closing as fixed.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2005-06-14  8:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-04 18:55 [Bug c++/17323] New: ICE on invalid code if static member array initialized with size computed as division by zero niemayer at isg dot de
2004-09-04 18:56 ` [Bug c++/17323] " niemayer at isg dot de
2004-09-06 16:13 ` lerdsuwa at gcc dot gnu dot org
2004-09-06 16:56 ` giovannibajo at libero dot it
2004-09-07 23:53 ` bangerth at dealii dot org
2004-09-08  7:04 ` pinskia at gcc dot gnu dot org
2005-02-10 20:32 ` [Bug c++/17323] [3.4/4.0 regression] " reichelt at gcc dot gnu dot org
2005-05-19 17:36 ` [Bug c++/17323] [3.4/4.0/4.1 " mmitchel at gcc dot gnu dot org
2005-06-14  8:31 ` reichelt at gcc dot gnu dot org

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