This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Bug in template parsing?
- From: "lh mouse"<lh_mouse at 126 dot com>
- To: "Marcel Keller"<M dot Keller at bristol dot ac dot uk>, "gcc-help"<gcc-help at gcc dot gnu dot org>
- Date: Wed, 15 Jun 2016 09:52:41 +0800
- Subject: Re: Bug in template parsing?
- Authentication-results: sourceware.org; auth=none
- References: <57607698 dot 4090903 at bristol dot ac dot uk>
Without the `template` keyword the compiler is unable to tell what entity 'T().f' is. It could legally be accessing a data member of a temporary object.
As a result, the C++ standard specifies that whatever (unprefixed) name that is dependent on a template parameter hence is unable to be identified in the template definition should be treated as a non-template.
In your example, the first < was considered not following a template name and was parsed as the builtin less-than operator rather than an angle bracket, hence the error.
(This is also the principle why the `typename` keyword is needed before a dependent type. You are gonna need both in the case of a dependent class template.)
------------------
Best regards,
lh_mouse
2016-06-15
-------------------------------------------------------------
åääïMarcel Keller <M.Keller@bristol.ac.uk>
åéææï2016-06-15 05:26
æääïgcc-help
æéï
äéïBug in template parsing?
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?
Best regards,
Marcel