On 15.06.2016 0:26, Marcel Keller wrote:
Hi,
Trying to compile the attached code with GCC 5.3.0 gives the error:
templ_bug.cpp: In function ‘void g()’:
templ_bug.cpp:15:12: error: expected primary-expression before ‘)’ token
T().f<t>();
^
templ_bug.cpp: In instantiation of ‘void g() [with T = A; int t = 0]’:
templ_bug.cpp:19:10: required from here
templ_bug.cpp:15:8: error: invalid operands of types ‘<unresolved
overloaded function type>’ and ‘int’ to binary ‘operator<’
T().f<t>();
^
However, if I uncomment the commented line, it works fine. I cannot
understand why this should make a difference. Is there a mistake in the
code or a bug in GCC?
According to [temp.names]/4:
"When the name of a member template specialization appears after . or ->
in a postfix-expression or after a nested-name-specifier in a
qualified-id, and the object expression of the postfix-expression is
type-dependent or the nested-name-specifier in the qualified-id refers
to a dependent type, but the name is not a member of the current
instantiation (14.6.2.1), the member template name must be prefixed by
the keyword template."
I.e., you should write:
T().template f<t>();
--
Mikhail Maltsev