https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91850

            Bug ID: 91850
           Summary: linker can not locate constexpr static class array
                    member when code compiled without optimization
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: veffremov.ve at gmail dot com
  Target Milestone: ---

Affected versions: I have tried the following compiler versions gcc-8, gcc-6.
Also tried compiling for X64 and ARM platform. All exhibit the same issue.

Compiling the following snippet of code without optimization result in the
linker complaining it can not find A::a
Compiling with -O, -Os, -O1, -O2 or -O3 works fine

Code to reproduce the issue:
<<START
#include <stdio.h>

class A {
public:
static constexpr int a[2] = {1, 2};
static int m(int x) {
return a[x];
}
};

int main() {
  printf("R=%d", A::m(1));
  return 0;
}
<<END

Running on Ubuntu 19.04, the following command: 'g++ -o tt  f1.cc' produces the
 error:
/usr/bin/ld: /tmp/ccVisGqO.o: in function `A::m(int)':
f1.cc:(.text._ZN1A1mEi[_ZN1A1mEi]+0x17): undefined reference to `A::a'

Running 'g++ -o tt  -O1 f1.cc' completes with no errors.

System details:
OS: ubuntu 19.04, X64 machine
GCC version:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 8.3.0-6ubuntu1'
--with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-8
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie
--with-system-zlib --with-target-system-zlib --enable-objc-gc=auto
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Ubuntu 8.3.0-6ubuntu1)

Reply via email to