[Bug c++/45829] New: Unary minus on static const class variable triggering linker error

2010-09-29 Thread sander.land at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45829

   Summary: Unary minus on static const class variable triggering
linker error
   Product: gcc
   Version: 4.4.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: sander.l...@gmail.com


Created attachment 21912
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=21912
Example

The use of an unary minus on a static const variable in a class seems to
trigger a linker error (undefined reference to ...)
Workaround: if instead of the unary minus "-var", a binary operator "0.0-var"
is used, the bug disappears.
See attachment for example.


$ g++ -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-ppl --with-cloog --with-tune=generic --with-arch_32=i586
--build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.1 20090725 (Red Hat 4.4.1-2) (GCC) 

$ uname -a
Linux ***.uk 2.6.30.10-105.2.23.fc11.x86_64 #1 SMP Thu Feb 11 07:06:34 UTC
2010 x86_64 x86_64 x86_64 GNU/Linux


[Bug c++/45829] Unary minus on static const class variable triggering linker error

2010-09-29 Thread sander.land at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45829

--- Comment #2 from Sander Land  2010-09-29 
12:49:23 UTC ---
I did define the constant, though now see the attachment apparently failed?
Full text below:

struct x {
 static const double a = 3.14;
 double f() {
  double b = -a;// undefined reference to `x::a'
//double b = 0.0-a; // works fine
  return a;
 }
};

int main() {
 x o;
 o.f();
 return 0;
}


[Bug c++/45829] Unary minus on static const class variable triggering linker error

2010-09-29 Thread sander.land at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45829

--- Comment #4 from Sander Land  2010-09-29 
13:05:45 UTC ---
(In reply to comment #3)
> You didn't.  A definition would be
> 
> const double x::a;
> 
> at file-scope.  Your "definition" is a declaration.

Fair enough, I thought it was both. Still doesn't explain the binary operator
(and everything else) working, -Wall not giving anything, while the unary
operator triggers a linker error.