Re: Bug in template parsing?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
发送日期: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







[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux