https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62163
Bug ID: 62163 Summary: Dependent function call in constant expression produces error in template definition context Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hstong at ca dot ibm.com GCC does not wait until a (dependent) function call is substituted with arguments before reporting a hard error in the case below. It appears that GCC tries to evaluate the constant expression with the lookup results from the template definition context. ### SOURCE (gccSfinaeDependentConstexpr.cc): unsigned foo(int); template <unsigned N> struct Q; template <typename T> void bar(T, Q<foo(T())> * = 0); void bar(void *) { } namespace M { struct Z; constexpr unsigned foo(Z *) { return 0; } } int main() { M::Z *p = 0; bar(p); } ### COMPILER OPTIONS: -std=c++11 ### COMPILER OUTPUT: gccSfinaeDependentConstexpr.cc:5:44: error: call to non-constexpr function 'unsigned int foo(int)' template <typename T> void bar(T, Q<foo(T())> * = 0); ^ ### COMPILER VERSION INFO: Using built-in specs. COLLECT_GCC=/opt/gcc-4.9.0/bin/g++ Target: x86_64-unknown-linux-gnu Configured with: ./configure --prefix=/home/matthew/gcc-4.9.0-prefix Thread model: posix gcc version 4.9.0 (GCC)