public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/5079: static const int optimization fails in conditional expressions
@ 2001-12-15  9:45 nathan
  0 siblings, 0 replies; 2+ messages in thread
From: nathan @ 2001-12-15  9:45 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, muaddib, nobody

Synopsis: static const int optimization fails in conditional expressions

State-Changed-From-To: open->analyzed
State-Changed-By: nathan
State-Changed-When: Sat Dec 15 09:45:12 2001
State-Changed-Why:
    This is an optimizer defficiency.  Your code is ill formed
    as you must give an out-of-class definition of the static
    constant member. See [9.4.2]/4

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5079


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

* c++/5079: static const int optimization fails in conditional expressions
@ 2001-12-11 15:16 James Jurach
  0 siblings, 0 replies; 2+ messages in thread
From: James Jurach @ 2001-12-11 15:16 UTC (permalink / raw)
  To: gcc-gnats, debian-gcc; +Cc: devteam, sa


>Number:         5079
>Category:       c++
>Synopsis:       static const int optimization fails in conditional expressions
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Dec 11 15:16:02 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     James Jurach
>Release:        3.0.3 20011209 (Debian prerelease) (Debian testing/unstable)
>Organization:
FundsXpress
>Environment:
System: Linux mabel 2.2.19 #2 Thu Sep 6 14:51:54 CDT 2001 i686 unknown
Architecture: i686

	
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f77,proto,objc --prefix=/usr --infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as --with-gnu-ld --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-checking --enable-threads=posix --enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc i386-linux
>Description:

When class members declared as static const int appear in conditional
expressions, they are not properly optimized out.  The compiler treats them
as undefined variables, rather than integer literals.  The result is the
following error message:

 /tmp/ccruMK1G.o: In function `main':
 /tmp/ccruMK1G.o(.text+0x1b): undefined reference to `Foo::erf'
 /tmp/ccruMK1G.o(.text+0x29): undefined reference to `Foo::foo'
 collect2: ld returned 1 exit status

This problem exists in 2.96, but does not exist in 2.95 and before.

>How-To-Repeat:

$ g++-3.0 -Wall -o condexpr condexpr.cpp
/tmp/ccBleh7H.o: In function `main':
/tmp/ccBleh7H.o(.text+0x1f): undefined reference to `Foo::erf'
/tmp/ccBleh7H.o(.text+0x29): undefined reference to `Foo::foo'
collect2: ld returned 1 exit status
$

-*- begin of condexpr.cpp -*-
#include <iostream.h>

class Foo {
 public:
  static const int erf = 0;
  static const int foo = 1;
};

int main(int argc,char **argv) {
  cout << "foo: " << (argc%2 ? Foo::erf : Foo::foo) << endl;
  return 0;
}
-*- end of condexpr.cpp -*-


>Fix:

Type-casting the const int's appears to be a work around, albeit a wretched
one for production code:

 cout << "foo: " << (argc%2 ? (int)Foo::erf : (int)Foo::foo) << endl;

>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2001-12-15 17:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-15  9:45 c++/5079: static const int optimization fails in conditional expressions nathan
  -- strict thread matches above, loose matches on Subject: below --
2001-12-11 15:16 James Jurach

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