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

            Bug ID: 85470
           Summary: Strange error about "call to non-constexpr function"
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: officesamurai at gmail dot com
  Target Milestone: ---

GCC 7 fails to compile the following code:

---- test.cpp ----

template <class T>
struct StaticObject
{
    static T& create()
    {
      static T t;
      return t;
    }

    static T & instance;
};

template <class T> T & StaticObject<T>::instance = StaticObject<T>::create();

extern template class StaticObject<int>;

void test()
{
    StaticObject<int>::instance;
}

---- command line -----

$ g++-7.3.0 -v
Using built-in specs.
COLLECT_GCC=g++-7.3.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-7.3.0/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-7.3.0
Thread model: posix
gcc version 7.3.0 (GCC)

$ g++-7.3.0 -c test.cpp
test.cpp: In instantiation of ‘int& StaticObject<int>::instance’:
test.cpp:19:24:   required from here
test.cpp:13:75: error: call to non-constexpr function ‘static T&
StaticObject<T>::create() [with T = int]’
 template <class T> T & StaticObject<T>::instance = StaticObject<T>::create();


P.S. I also tried 7.1 (same error) and 6.3 (no error)

Reply via email to