GCC is not able to compile the following code #include <array> using Ar = std::array<unsigned long, 10>; template<typename T> constexpr T Apply(const T& in, T (*f)(const T&)) { return f(in); } static constexpr Ar id(const Ar& line) { return line; } static constexpr Ar ar1 = {{1}}; static constexpr Ar results1 = Apply<Ar>(ar1, &id); It complains that bug4.cpp:10:50: in constexpr expansion of ‘Apply<std::array<long unsigned int, 10ul> >((* & ar1), id)’ bug4.cpp:6:63: error: expression ‘id’ does not designate a constexpr function constexpr T Apply(const T& in, T (*f)(const T&)) { return f(in); } This seems to be a problem with template substitution since manually specializing the template makes the error vanish: #include <array> using Ar = std::array<unsigned long, 10>; template<typename T> constexpr T Apply(const T& in, T (*f)(const T&)) { return f(in); } // manual specialization: template<> constexpr Ar Apply<Ar>(const Ar& in, Ar (*f)(const Ar&)) { return f(in); } static constexpr Ar id(const Ar& line) { return line; } static constexpr Ar ar1 = {{1}}; static constexpr Ar results1 = Apply<Ar>(ar1, &id); System informations: Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/4.8/lto-wrapper Target: x86_64-suse-linux Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.8 --enable-ssp --disable-libssp --disable-plugin --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --enable-linker-build-id --program-suffix=-4.8 --enable-linux-futex --without-system-libunwind --with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux Thread model: posix gcc version 4.8.1 20130909 [gcc-4_8-branch revision 202388] (SUSE Linux)
Created attachment 32155 [details] preprocessed code
Sorry ! The version I submitted is not the most reduced. Here is a version not using vectors: constexpr int Apply(const int in, int (*f)(const int&)) { return f(in); } using Foo = int; static constexpr int id(const Foo& i) { return i; } static constexpr int results1 = Apply(0, &id); Note: Replacing the Foo by int in the definition of id makes the problem vanish.
The problem remains with the newly released gcc 4.9.0. I upgraded the version tag.
This is fixed in mainline, I'm adding the testcase and closing the bug.
Author: paolo Date: Tue Nov 18 11:57:16 2014 New Revision: 217709 URL: https://gcc.gnu.org/viewcvs?rev=217709&root=gcc&view=rev Log: 2014-11-18 Paolo Carlini <paolo.carlini@oracle.com> PR c++/60245 * g++.dg/cpp0x/constexpr-60245.C: New. Added: trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-60245.C Modified: trunk/gcc/testsuite/ChangeLog
Done.