public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/21089] New: c++ accepts invalid static const double members with initializer
@ 2005-04-18 17:26 matz at suse dot de
  2005-04-18 17:32 ` [Bug c++/21089] " pinskia at gcc dot gnu dot org
                   ` (20 more replies)
  0 siblings, 21 replies; 22+ messages in thread
From: matz at suse dot de @ 2005-04-18 17:26 UTC (permalink / raw)
  To: gcc-bugs

See this testcase: 
------------------------- 
struct Ball { 
    static const double diameter = 20; 
    void setPosition(double ,double ); 
    double vect_Pos; 
}; 
 
void move (double, double); 
 
void Ball::setPosition(double xval,double yval) { 
    vect_Pos=xval; 
    move(xval-(diameter/2),yval-(diameter/2)); 
} 
------------------------- 
 
This is from kbilliard, and I only noticed the problem, because a reference 
to Ball::diameter is left in the generated code, which can't be resolved, 
as it's defined nowhere.  Initially I was tricked by the java like syntax, 
but then saw PR20098, according to which this is invalid code (for two 
reasons).  So it seems there are two problems: 
  1) missed optimization, as for instance if I remove the 'vectPos=xval' line 
     I get no linker error, and in fact in the dumps the references to 
     diameter are substituted by the defined value (double)20 
  2) the invalidness of the code is not diagnosed. 
 
It's invalid for two reasons I think, first the missing definition, instead 
of the declaration.  But that can't be diagnosed except by the linker, which 
indeed it does. 
 
But when reading PR20098 I learned that static const members are only  
allowed to have an initializer when they are of integral type.  This is 
not the case here.  If the compiler would have diagnosed it, the root cause 
of this problem had been more visible.

-- 
           Summary: c++ accepts invalid static const double members with
                    initializer
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: matz at suse dot de
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/21089] c++ accepts invalid static const double members with initializer
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
@ 2005-04-18 17:32 ` pinskia at gcc dot gnu dot org
  2005-04-18 17:40 ` matz at suse dot de
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-18 17:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-18 17:32 -------
Yes this is invalid C++ (and is rejected by -pedantic) but we somehow declared this as an extension see 
PR 11393 which is still open and other threads within a past year.

*** This bug has been marked as a duplicate of 11393 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


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

* [Bug c++/21089] c++ accepts invalid static const double members with initializer
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
  2005-04-18 17:32 ` [Bug c++/21089] " pinskia at gcc dot gnu dot org
@ 2005-04-18 17:40 ` matz at suse dot de
  2005-04-18 17:47 ` [Bug c++/21089] C++ front-end does not "inline" the static const double members pinskia at gcc dot gnu dot org
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: matz at suse dot de @ 2005-04-18 17:40 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From matz at suse dot de  2005-04-18 17:40 -------
Indeed.  Okay, but then this really is an optimization regression compared 
to gcc 3.3.x which compiled this just fine.  As it's only rejected with 
-pedantic (and I think it's a sensible extension), shouldn't we make sure 
that we can compile this comparatively simple source, i.e. propagate 
the constant correctly everywhere?  I'm not sure what to do, reopening with 
a new subject, or creating a new bug? 

-- 


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


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

* [Bug c++/21089] C++ front-end does not "inline" the static const double members
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
  2005-04-18 17:32 ` [Bug c++/21089] " pinskia at gcc dot gnu dot org
  2005-04-18 17:40 ` matz at suse dot de
@ 2005-04-18 17:47 ` pinskia at gcc dot gnu dot org
  2005-04-18 17:50 ` [Bug c++/21089] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-18 17:47 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-18 17:47 -------
(In reply to comment #2)
> Indeed.  Okay, but then this really is an optimization regression compared 
> to gcc 3.3.x which compiled this just fine.  As it's only rejected with 
> -pedantic (and I think it's a sensible extension), shouldn't we make sure 
> that we can compile this comparatively simple source, i.e. propagate 
> the constant correctly everywhere?  I'm not sure what to do, reopening with 
> a new subject, or creating a new bug? 

Oh, in that case I will reopen the bug with a different summary.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
           Keywords|                            |missed-optimization
         Resolution|DUPLICATE                   |
            Summary|c++ accepts invalid static  |C++ front-end does not
                   |const double members with   |"inline" the static const
                   |initializer                 |double members


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double members
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (2 preceding siblings ...)
  2005-04-18 17:47 ` [Bug c++/21089] C++ front-end does not "inline" the static const double members pinskia at gcc dot gnu dot org
@ 2005-04-18 17:50 ` pinskia at gcc dot gnu dot org
  2005-04-18 17:53 ` [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double pinskia at gcc dot gnu dot org
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-18 17:50 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-18 17:50 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
      Known to fail|                            |4.0.0 4.1.0
      Known to work|                            |3.4.0
   Last reconfirmed|0000-00-00 00:00:00         |2005-04-18 17:50:29
               date|                            |
            Summary|C++ front-end does not      |[4.0/4.1 Regression] C++
                   |"inline" the static const   |front-end does not "inline"
                   |double members              |the static const double
                   |                            |members
   Target Milestone|---                         |4.0.0


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (3 preceding siblings ...)
  2005-04-18 17:50 ` [Bug c++/21089] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
@ 2005-04-18 17:53 ` pinskia at gcc dot gnu dot org
  2005-04-18 17:59 ` matz at suse dot de
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-18 17:53 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-18 17:53 -------
It has nothing to do with members of classes either, see the following code:
static const double a = 1.0;
static const double b = a+1.0;

double c()
{
  return b;
}

We now longer inline 2.0 into c.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[4.0/4.1 Regression] C++    |[4.0/4.1 Regression] C++
                   |front-end does not "inline" |front-end does not "inline"
                   |the static const double     |the static const double
                   |members                     |


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (4 preceding siblings ...)
  2005-04-18 17:53 ` [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double pinskia at gcc dot gnu dot org
@ 2005-04-18 17:59 ` matz at suse dot de
  2005-04-18 18:04 ` pinskia at gcc dot gnu dot org
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: matz at suse dot de @ 2005-04-18 17:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From matz at suse dot de  2005-04-18 17:59 -------
With -O0 we also don't inline 'a'.  I thought in the past this already  
was done in the frontend, so the -O option didn't matter?  If yes, this  
has changed (if not, well, I'm wrong ;-) ).  

-- 


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (5 preceding siblings ...)
  2005-04-18 17:59 ` matz at suse dot de
@ 2005-04-18 18:04 ` pinskia at gcc dot gnu dot org
  2005-04-18 18:06 ` pinskia at gcc dot gnu dot org
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-18 18:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-18 18:04 -------
(In reply to comment #6)
> With -O0 we also don't inline 'a'.  I thought in the past this already  
> was done in the frontend, so the -O option didn't matter?  If yes, this  
> has changed (if not, well, I'm wrong ;-) ).  

The code for 3.4.0 at -O0 for the example in comment #5:
.LC0:
        .long   0
        .long   1073741824
        .text
        .align 2
.globl _Z1cv
        .type   _Z1cv, @function
_Z1cv:
        pushl   %ebp
        movl    %esp, %ebp
        fldl    .LC0
        popl    %ebp
        ret
        .size   _Z1cv, .-_Z1cv
        .section        .rodata
        .align 8
        .type   a, @object
        .size   a, 8
a:
        .long   0
        .long   1072693248
        .align 8
        .type   b, @object
        .size   b, 8
b:
        .long   0
        .long   1073741824

so we did inline 2.0 before.

The code for 4.0.0 and above is even worse:
_Z1cv:
        pushl   %ebp
        movl    %esp, %ebp
        fldl    b
        popl    %ebp
        ret
        .size   _Z1cv, .-_Z1cv
        .text
        .align 2
        .type   _Z41__static_initialization_and_destruction_0ii, @function
_Z41__static_initialization_and_destruction_0ii:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        movl    %eax, -4(%ebp)
        movl    %edx, -8(%ebp)
        cmpl    $65535, -8(%ebp)
        jne     .L7
        cmpl    $1, -4(%ebp)
        jne     .L7
        fldl    a
        fld1
        faddp   %st, %st(1)
        fstpl   b
.L7:
        leave
        ret
        .size   _Z41__static_initialization_and_destruction_0ii, .-
_Z41__static_initialization_and_destruction_0ii
        .text
        .align 2
        .type   _GLOBAL__I__Z1cv, @function
_GLOBAL__I__Z1cv:
        pushl   %ebp
        movl    %esp, %ebp
        movl    $65535, %edx
        movl    $1, %eax
        call    _Z41__static_initialization_and_destruction_0ii
        popl    %ebp
        ret

We dymanically initialize b too which is what partly PR 20912 is about, Diego filed after seeing eon fail 
because the front-end was still marking b as constant.

-- 


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (6 preceding siblings ...)
  2005-04-18 18:04 ` pinskia at gcc dot gnu dot org
@ 2005-04-18 18:06 ` pinskia at gcc dot gnu dot org
  2005-04-18 18:19 ` pinskia at gcc dot gnu dot org
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-18 18:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-18 18:06 -------
Also note this worked with "4.0.0 2004121", so something after that date changed the problem.

-- 


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (7 preceding siblings ...)
  2005-04-18 18:06 ` pinskia at gcc dot gnu dot org
@ 2005-04-18 18:19 ` pinskia at gcc dot gnu dot org
  2005-04-18 18:34 ` pinskia at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-18 18:19 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-18 18:19 -------
(In reply to comment #8)
> Also note this worked with "4.0.0 20041211", so something after that date changed the problem.

And it was broken by "4.0.0 20050113".  so there is only a month time which it could have changed.

-- 


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (8 preceding siblings ...)
  2005-04-18 18:19 ` pinskia at gcc dot gnu dot org
@ 2005-04-18 18:34 ` pinskia at gcc dot gnu dot org
  2005-04-18 18:41 ` sabre at nondot dot org
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-18 18:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-18 18:34 -------
Looks like this was caused by:
2004-12-16  Nathan Sidwell  <nathan@codesourcery.com>

        PR c++/18905
        * cp-tree.h (integral_constant_value): Declare.
        * call.c (null_ptr_cst_p): Use integral_constant_value, not
        decl_constant_value.
        (convert_like_real): Likewise.
        * class.c (check_bitfield_decl): Likewise.
        * cvt.c (ocp_convert): Likewise.
        (convert): Remove unnecessary decl_constant_value call.
        * decl.c (compute_array_index_type): Use integral_constant_value,
        not decl_constant_value.
        (build_enumerator): Likewise.
        * decl2.c (grokfield): Likewise.
        * init.c (decl_constant_value): Simplify.
        (integral_constant_value): New.
        * pt.c (fold_decl_constant_value): Use integral_constant_value,
        remove subsequent check.
        (tsubst): Use integral_constant_value, not decl_constant_value.
        (tsubst_copy, unify): Likewise.
        * typeck.c (decay_conversion): Likewise.
        (build_compound_expr): Remove unnecessary decl_constant_value
        calls.
        (build_static_cast_1, build_reinterpret_cast_1):
        (convert_for_assignment): Remove comment about not calling
        decl_constant_value.


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


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (9 preceding siblings ...)
  2005-04-18 18:34 ` pinskia at gcc dot gnu dot org
@ 2005-04-18 18:41 ` sabre at nondot dot org
  2005-04-18 19:36 ` schlie at comcast dot net
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: sabre at nondot dot org @ 2005-04-18 18:41 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From sabre at nondot dot org  2005-04-18 18:41 -------
Is this optimization valid?  Note that it will change the behavior of this c++
program:


----
#include <stdio.h>
static const double X = 1.0;
static struct S { S(); } s;
static const double Y = X+2.0;

S::S() {
  printf("%f\n", Y);
}
int main() {}
----

In particular, I think the C++ standard specifies that memory is zero
initialized and then ctors (within a translation unit) are run in order.  IANALL
though.

-Chris


-- 


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (10 preceding siblings ...)
  2005-04-18 18:41 ` sabre at nondot dot org
@ 2005-04-18 19:36 ` schlie at comcast dot net
  2005-04-21  5:03 ` mmitchel at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: schlie at comcast dot net @ 2005-04-18 19:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schlie at comcast dot net  2005-04-18 19:36 -------
(In reply to comment #11)

I believe the optimization necessitates the variable's declaration be changed
(either explicitly, or by implication):

 static const double b = a+1.0; => const double b = a+1.0;

If it's static-const value can't be pre-computed at compile time. (as opposed
to allowing a non-const-literal value to initialize a global static const object).

 (as with: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20912 )




-- 


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (11 preceding siblings ...)
  2005-04-18 19:36 ` schlie at comcast dot net
@ 2005-04-21  5:03 ` mmitchel at gcc dot gnu dot org
  2005-04-28  2:11 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-04-21  5:03 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.0.0                       |4.0.1


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (12 preceding siblings ...)
  2005-04-21  5:03 ` mmitchel at gcc dot gnu dot org
@ 2005-04-28  2:11 ` pinskia at gcc dot gnu dot org
  2005-04-28  2:46 ` matz at suse dot de
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-28  2:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-28 02:09 -------
(In reply to comment #11)
> Is this optimization valid?  Note that it will change the behavior of this c++
> program:

You are correct Chris, this was an invalid optimization.

This is a dup of bug 19320.  Though we still have a "wrong code" bug with respect with const still being 
on the decl but that is PR 20912.

*** This bug has been marked as a duplicate of 19320 ***

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


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (13 preceding siblings ...)
  2005-04-28  2:11 ` pinskia at gcc dot gnu dot org
@ 2005-04-28  2:46 ` matz at suse dot de
  2005-04-28  8:03 ` nathan at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: matz at suse dot de @ 2005-04-28  2:46 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From matz at suse dot de  2005-04-28 02:46 -------
Uhm, wait.  Perhaps the optimization would be invalid for your changed example 
from comment #5, but see below.  But it will not be invalid for my initial testcase, 
where it missed to propagate 20.0 into setPosition. 
 
Why I think the transformation is valid _also_ for comment #5: See 3.6.2 #2: 
------------------------------- 
An implementation is permitted to perform the initialization of an object of namespace scope 
with static storage duration as a static initialization even if such initialization is not required to 
be done statically, provided that 
  * the dynamic version of the initialization does not change the 
    value of any other object of namespace scope with static storage duration prior to its 
     initialization, and 
  * the static version of the initialization produces the same value in the 
    initialized object as would be produced by the dynamic initialization if all objects not required 
    to be initialized statically were initialized dynamically. 
------------------------------------- 
 
It then goes on to provide an example which uses an inline function to dynamically initialize 
something, where comment #5 uses an arithmetic expression.  So I think we are permitted 
to do this optimization, in both, by initial example, and Andrews example from comment #5. 
 
Reopening. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|DUPLICATE                   |


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (14 preceding siblings ...)
  2005-04-28  2:46 ` matz at suse dot de
@ 2005-04-28  8:03 ` nathan at gcc dot gnu dot org
  2005-04-28  9:24 ` matz at suse dot de
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: nathan at gcc dot gnu dot org @ 2005-04-28  8:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From nathan at gcc dot gnu dot org  2005-04-28 08:02 -------
the example test case is invalid even with the gnu extension.  As with
static const int members, you must have a single out-of-class definition of
the member EVEN IF the member is initialized in class. [9.4.2/4]

-- 


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (15 preceding siblings ...)
  2005-04-28  8:03 ` nathan at gcc dot gnu dot org
@ 2005-04-28  9:24 ` matz at suse dot de
  2005-05-02 14:21 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: matz at suse dot de @ 2005-04-28  9:24 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From matz at suse dot de  2005-04-28 09:24 -------
Yes, I determined that already in the initial report; to cite myself: 
 
> It's invalid for two reasons I think, first the missing definition, instead  
> of the declaration. 
 
[the second reason being the use of the GNU extension]. 
 
But it can be trivially made valid (just provide a definition), and I assumed 
this to be done for sake of this bugreport.  Using the GNU extension this 
would then be valid, and _then_ the value is still not propagated to the 
method body.  _That_'s what I'm complaining about, the missed optimization. 

-- 


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (16 preceding siblings ...)
  2005-04-28  9:24 ` matz at suse dot de
@ 2005-05-02 14:21 ` pinskia at gcc dot gnu dot org
  2005-07-08  1:42 ` mmitchel at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-02 14:21 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |NEW


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (17 preceding siblings ...)
  2005-05-02 14:21 ` pinskia at gcc dot gnu dot org
@ 2005-07-08  1:42 ` mmitchel at gcc dot gnu dot org
  2005-09-20 14:33 ` pinskia at gcc dot gnu dot org
  2005-09-27 16:25 ` mmitchel at gcc dot gnu dot org
  20 siblings, 0 replies; 22+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-07-08  1:42 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.0.1                       |4.0.2


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (18 preceding siblings ...)
  2005-07-08  1:42 ` mmitchel at gcc dot gnu dot org
@ 2005-09-20 14:33 ` pinskia at gcc dot gnu dot org
  2005-09-27 16:25 ` mmitchel at gcc dot gnu dot org
  20 siblings, 0 replies; 22+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-20 14:33 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-20 14:33 -------
*** Bug 23975 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lidaobing at gmail dot com


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


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

* [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double
  2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
                   ` (19 preceding siblings ...)
  2005-09-20 14:33 ` pinskia at gcc dot gnu dot org
@ 2005-09-27 16:25 ` mmitchel at gcc dot gnu dot org
  20 siblings, 0 replies; 22+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-09-27 16:25 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.0.2                       |4.0.3


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


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

end of thread, other threads:[~2005-09-27 16:20 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-18 17:26 [Bug c++/21089] New: c++ accepts invalid static const double members with initializer matz at suse dot de
2005-04-18 17:32 ` [Bug c++/21089] " pinskia at gcc dot gnu dot org
2005-04-18 17:40 ` matz at suse dot de
2005-04-18 17:47 ` [Bug c++/21089] C++ front-end does not "inline" the static const double members pinskia at gcc dot gnu dot org
2005-04-18 17:50 ` [Bug c++/21089] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
2005-04-18 17:53 ` [Bug c++/21089] [4.0/4.1 Regression] C++ front-end does not "inline" the static const double pinskia at gcc dot gnu dot org
2005-04-18 17:59 ` matz at suse dot de
2005-04-18 18:04 ` pinskia at gcc dot gnu dot org
2005-04-18 18:06 ` pinskia at gcc dot gnu dot org
2005-04-18 18:19 ` pinskia at gcc dot gnu dot org
2005-04-18 18:34 ` pinskia at gcc dot gnu dot org
2005-04-18 18:41 ` sabre at nondot dot org
2005-04-18 19:36 ` schlie at comcast dot net
2005-04-21  5:03 ` mmitchel at gcc dot gnu dot org
2005-04-28  2:11 ` pinskia at gcc dot gnu dot org
2005-04-28  2:46 ` matz at suse dot de
2005-04-28  8:03 ` nathan at gcc dot gnu dot org
2005-04-28  9:24 ` matz at suse dot de
2005-05-02 14:21 ` pinskia at gcc dot gnu dot org
2005-07-08  1:42 ` mmitchel at gcc dot gnu dot org
2005-09-20 14:33 ` pinskia at gcc dot gnu dot org
2005-09-27 16:25 ` mmitchel 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).