public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49896] New: undefined reference to static const integral member whose address is not used, for some values of the constant
@ 2011-07-29  7:53 matthieu.imbert@ens-lyon.fr
  2011-07-29 10:06 ` [Bug c++/49896] " rguenth at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: matthieu.imbert@ens-lyon.fr @ 2011-07-29  7:53 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: undefined reference to static const integral member
                    whose address is not used, for some values of the
                    constant
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: matthieu.imbert@ens-lyon.fr


A static const int member is declared and initialized in a template class.
Its value (not its address) is used in a method of the class.
If the value of the constant has its most significant bit set (int is 32 bits),
then there is an undefined reference to the member at link.

Here is a code snippet to reproduce this:

>>> snippet test.cpp >>>

template<class C>
class test {
 protected:
  static const int version = 0x80000000;
  //static const int version = 0x0fffffff;
 public:
  int getVersion();
};

template<class C>
int test<C>::getVersion() {
  return version;
}

class dummy_class {};

int main() {
  test<dummy_class> t;
  return t.getVersion();
}

<<< end of snippet <<<

compilation:

$ gcc -Wall -Wextra -Wstrict-aliasing test2.cpp
/tmp/cc4duaE3.o: In function `test<dummy_class>::getVersion()':
test2.cpp:(.text._ZN4testI11dummy_classE10getVersionEv[test<dummy_class>::getVersion()]+0xa):
undefined reference to `test<dummy_class>::version'
collect2: ld returned 1 exit status

if the constant value is 0x0fffffff instead of 0x80000000 it compiles fine.

i get this issue on this version of gcc (the default version currently on
debian testing):

$ gcc -v
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)

I checked with gcc 4.5.3-3 and i don't have the link error.


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

end of thread, other threads:[~2011-10-11 18:22 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-29  7:53 [Bug c++/49896] New: undefined reference to static const integral member whose address is not used, for some values of the constant matthieu.imbert@ens-lyon.fr
2011-07-29 10:06 ` [Bug c++/49896] " rguenth at gcc dot gnu.org
2011-07-29 10:37 ` matthieu.imbert@ens-lyon.fr
2011-07-29 12:50 ` matthieu.imbert@ens-lyon.fr
2011-07-29 17:55 ` harald at gigawatt dot nl
2011-07-30 12:10 ` redi at gcc dot gnu.org
2011-07-30 14:59 ` harald at gigawatt dot nl
2011-10-09 15:23 ` paolo.carlini at oracle dot com
2011-10-09 21:07 ` jason at gcc dot gnu.org
2011-10-11 17:54 ` jason at gcc dot gnu.org
2011-10-11 18:19 ` jason at gcc dot gnu.org
2011-10-11 18:22 ` jason 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).