This is related to bug #35167 in: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35167
The attached test case compiles if the preprocessor symbol MAKE_IT_WORK is defined. Otherwise fails with: main.cpp: In static member function 'static const X& A<Q>::getIt2() [with Q = X]': main.cpp:34: instantiated from here main.cpp:28: error: 'static const X& A<Q>::getIt() [with Q = X]' cannot appear in a constant-expression This has hit us with 4.4.1 on sparc-sun-solaris2.10, and reproduced in 3.3.1 on x86_64-linux-gnu. The referred bug seems to imply that this behaviour is a non-bug, but then I don't understand why the same explanation (based on the requirement of a qualified-id for the address-of (&) operator) doesn't apply to the case in which the class defining the scope (A in the test case when MAKE_IT_WORK is defined), making it compile fine. It seems to be a total inconsistency, unless the phrase "in the current context" of Comment #2 refers specifically to "being compiling code". In any case, about the referred paragraph in the other bug: 5.19/4 An address constant expression is a pointer to an lvalue designating an object of static storage duration, a string literal (_lex.string_), or a function. The pointer shall be created explicitly, using the unary & operator, or implicitly using a non-type template parameter of pointer type, or using an expression of array (_conv.array_) or function (_conv.func_) type. Creating the pointer implicitly from a function type doesn't explicitly (no pun intended) require that creation to use an expression with the unary & operator. I mean, if the function type named by a unqualified-id has no ambiguity (as it's the case, since the unqualified-id has been declared at the current template class and not hidden at the current function scope), I don't see the point in forcing usage of the class qualifier, moreover if the case works ok for a non-template class. The thing is this will force us to update some macros to take also the name of the enclosing class to generate a qualified static member function identifier, while it's not needed for the other compilers we use. So, I would request the compiler to be fixed to treat both cases (A being a template class or not) equally, seeming the most sensible option not requiring a explicit A::getIt() in the IndirectCaller template parameter for the code to compile. -- Summary: unqualified member function reference is or not valid in constant expression depending on class being a template or not Product: gcc Version: 4.4.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: skandalfo at gmail dot com GCC build triplet: sparc-sun-solaris2.10 GCC host triplet: sparc-sun-solaris2.10 GCC target triplet: sparc-sun-solaris2.10 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41544