This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13795] New: ternary operator fails to compile with static const class members
- From: "perry at kundert dot ca" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 21 Jan 2004 19:06:17 -0000
- Subject: [Bug c++/13795] New: ternary operator fails to compile with static const class members
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
DESCRIPTION
Ternary operator fails to compile correctly, if the ternary test operand is
not a constant,
and both operands are declared as "static const", and at least one of them is a
"static const"
integral member of a class. The integral "static const" class members are not
being used in
such a way that they should need to actually be defined in any compilation unit.
According to Stroustrup "The C++ Programming Language", 3rd. ed., 10.4.6.2
Member
Constants, an integral static const needs to be defined somewhere, "If (and only
if) you use an
initialized member in away that requires it to be stored as an object in memory,
the member
must be (uniquely) defined somewhere."
The compiler seems to be looking for the "static const int" as an actual
defined variable
in memory, instead of realising that it is a constant.
HOST:
$ uname -a
Linux wirelock 2.4.20-28.9smp #1 SMP Thu Dec 18 13:37:36 EST 2003 i686 i686
i386 GNU/Linux
GNU GCC VERSION:
$ g++ -v
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/specs
Configured with: ../gcc-3.3.2/configure --enable-languages=c,c++
Thread model: posix
gcc version 3.3.2
FAILURES:
$ g++ -DBORKEN=1 -o teststaticconst teststaticconst.C
/tmp/ccLN59qg.o(.text+0x1b): In function `main':
: undefined reference to `sc::value1'
/tmp/ccLN59qg.o(.text+0x25): In function `main':
: undefined reference to `sc::value2'
$ g++ -DBORKEN=2 -o teststaticconst teststaticconst.C; ./teststaticconst hi
there
/tmp/ccnZG9JI.o(.text+0x25): In function `main':
: undefined reference to `sc::value2'
WORKAROUNDS:
$ g++ -DWORKS=1 -o teststaticconst teststaticconst.C
$ g++ -DWORKS=2 -o teststaticconst teststaticconst.C
$ g++ -DWORKS=3 -o teststaticconst teststaticconst.C
$ g++ -DWORKS=4 -o teststaticconst teststaticconst.C
--
Summary: ternary operator fails to compile with static const
class members
Product: gcc
Version: 3.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: perry at kundert dot ca
CC: gcc-bugs at gcc dot gnu dot org,perry at kundert dot ca
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13795