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

            Bug ID: 78470
           Summary: static class member cannot be reference by algorithm
                    functions with -O0 option
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: frankbozar.cs02 at g2 dot nctu.edu.tw
  Target Milestone: ---

Created attachment 40109
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40109&action=edit
the preprocessed file

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++-6
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/6.2.0/lto-wrapper
Target: x86_64-apple-darwin15.6.0
Configured with: ../configure --build=x86_64-apple-darwin15.6.0
--prefix=/usr/local/Cellar/gcc/6.2.0
--libdir=/usr/local/Cellar/gcc/6.2.0/lib/gcc/6
--enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-6
--with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr
--with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl
--with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking
--enable-checking=release --enable-lto --with-build-config=bootstrap-debug
--disable-werror --with-pkgversion='Homebrew gcc 6.2.0 --without-multilib'
--with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin
--disable-nls --disable-multilib --with-native-system-header-dir=/usr/include
--with-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
Thread model: posix
gcc version 6.2.0 (Homebrew gcc 6.2.0 --without-multilib) 



This piece of code compiles with any level of optimization except that -O0
gives an error.
==================================================
#include<algorithm>

struct foo
{
    static constexpr int bar=100;

    int operator()() const
    {
        return std::max(bar, bar);//got an error here
    }
} F;

int main()
{
    F();
}
==================================================
$ g++ -std=c++14 -O0 bug.cpp 
Undefined symbols for architecture x86_64:
  "foo::bar", referenced from:
      foo::operator()() const in ccCz1Nua.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

With a bit of modification, it works with -O0.
==================================================
#include<algorithm>

struct foo
{
    static constexpr int bar=100;

    int operator()() const
    {
        return (bar, bar);//this line is modified
    }
} F;

int main()
{
    F();
}
==================================================


It also happens when using -std=c++11, and the on linux platform.

>g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --enable-libmpx --with-system-zlib --with-isl
--enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu
--disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object
--enable-linker-build-id --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu
--enable-gnu-indirect-function --disable-multilib --disable-werror
--enable-checking=release
Thread model: posix
gcc version 6.2.1 20160830 (GCC)

Reply via email to