public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50028] New: Ternary operator and static const member variable
@ 2011-08-09 13:54 protocolocon at gmail dot com
2011-08-09 13:55 ` [Bug c++/50028] " protocolocon at gmail dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: protocolocon at gmail dot com @ 2011-08-09 13:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50028
Summary: Ternary operator and static const member variable
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: protocolocon@gmail.com
Created attachment 24960
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24960
Preprocessor intermediate file
Problem:
The following code:
#include <stdlib.h>
#include <stdio.h>
class test
{
public:
static const unsigned char OPT1=27;
static const unsigned char OPT2=72;
};
int main()
{
unsigned cond=rand();
unsigned value1, value2;
if(cond) value1=test::OPT1; else value1=test::OPT2;
value2=cond?test::OPT1:test::OPT2;
printf("%d %d\n", value1, value2);
return 0;
}
Compiles w/o warnings with:
$ g++ -Wall -Wextra -o testO2 -g -O2 test.cc
But fails to compile/link with:
$ g++ -Wall -Wextra -o testO2 -g -O0 test.cc
/tmp/ccwLVGVv.o: In function `main':
/home/asier/desarrollo/tmp/gcc_poc/test.cc:16: undefined reference to
`test::OPT1'
/home/asier/desarrollo/tmp/gcc_poc/test.cc:16: undefined reference to
`test::OPT2'
collect2: ld returned 1 exit status
Analysis:
The problem only happens in the ternary operator, but not in the if statement
that precedes it. Compiler is not substituting class constants in conditional
operator so that compilation unit gets a reference to a test::OPT1 and
test::OPT2 in the .rodata section (that actually does not exist).
See attacked preprocesor output and intermediate assembly code.
Compilers tested:
GCC 4.3
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.5-4'
--with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--enable-multiarch --enable-linker-build-id --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.3.5 (Debian 4.3.5-4)
GCC 4.4
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.4 --enable-shared --enable-multiarch
--enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc
--with-arch-32=i586 --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
GCC 4.6
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.1-4'
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-multiarch
--with-multiarch-defaults=x86_64-linux-gnu --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib/x86_64-linux-gnu
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib/x86_64-linux-gnu
--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc
--with-arch-32=i586 --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.1 (Debian 4.6.1-4)
System info:
Linux frito 2.6.32-5-amd64 #1 SMP Mon Mar 7 21:35:22 UTC 2011 x86_64 GNU/Linux
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/50028] Ternary operator and static const member variable
2011-08-09 13:54 [Bug c++/50028] New: Ternary operator and static const member variable protocolocon at gmail dot com
@ 2011-08-09 13:55 ` protocolocon at gmail dot com
2011-08-09 14:08 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: protocolocon at gmail dot com @ 2011-08-09 13:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50028
--- Comment #1 from protocolocon <protocolocon at gmail dot com> 2011-08-09 13:55:05 UTC ---
Created attachment 24961
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24961
Intermediate assembly code
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/50028] Ternary operator and static const member variable
2011-08-09 13:54 [Bug c++/50028] New: Ternary operator and static const member variable protocolocon at gmail dot com
2011-08-09 13:55 ` [Bug c++/50028] " protocolocon at gmail dot com
@ 2011-08-09 14:08 ` redi at gcc dot gnu.org
2011-08-09 14:16 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2011-08-09 14:08 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50028
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-08-09 14:08:25 UTC ---
you need to define the static members
PR 10483
PR 13795
PR 13332
PR 44673
etc. etc. etc
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/50028] Ternary operator and static const member variable
2011-08-09 13:54 [Bug c++/50028] New: Ternary operator and static const member variable protocolocon at gmail dot com
2011-08-09 13:55 ` [Bug c++/50028] " protocolocon at gmail dot com
2011-08-09 14:08 ` redi at gcc dot gnu.org
@ 2011-08-09 14:16 ` redi at gcc dot gnu.org
2011-08-09 14:32 ` protocolocon at gmail dot com
2011-08-09 14:40 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2011-08-09 14:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50028
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-08-09 14:16:03 UTC ---
and PR 42101
and finally,
http://gcc.gnu.org/wiki/VerboseDiagnostics#missing_static_const_definition
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/50028] Ternary operator and static const member variable
2011-08-09 13:54 [Bug c++/50028] New: Ternary operator and static const member variable protocolocon at gmail dot com
` (2 preceding siblings ...)
2011-08-09 14:16 ` redi at gcc dot gnu.org
@ 2011-08-09 14:32 ` protocolocon at gmail dot com
2011-08-09 14:40 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: protocolocon at gmail dot com @ 2011-08-09 14:32 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50028
--- Comment #4 from protocolocon <protocolocon at gmail dot com> 2011-08-09 14:32:04 UTC ---
(In reply to comment #3)
> and PR 42101
>
> and finally,
> http://gcc.gnu.org/wiki/VerboseDiagnostics#missing_static_const_definition
Thanks for the fast replay and sorry for submitting a duplicate.
Still not completely convinced, but I will assimilate it.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/50028] Ternary operator and static const member variable
2011-08-09 13:54 [Bug c++/50028] New: Ternary operator and static const member variable protocolocon at gmail dot com
` (3 preceding siblings ...)
2011-08-09 14:32 ` protocolocon at gmail dot com
@ 2011-08-09 14:40 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2011-08-09 14:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50028
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-08-09 14:39:44 UTC ---
that last link should be
http://gcc.gnu.org/wiki/VerboseDiagnostics#undefined_reference_to_.60S::a.27
(I'm not sure why the "Permalink" doesn't work)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-08-09 14:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-09 13:54 [Bug c++/50028] New: Ternary operator and static const member variable protocolocon at gmail dot com
2011-08-09 13:55 ` [Bug c++/50028] " protocolocon at gmail dot com
2011-08-09 14:08 ` redi at gcc dot gnu.org
2011-08-09 14:16 ` redi at gcc dot gnu.org
2011-08-09 14:32 ` protocolocon at gmail dot com
2011-08-09 14:40 ` redi at gcc dot gnu.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).