This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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
#include <iostream>
using namespace std;

class A
{
public:
  template <int t> void f() { cout << "Hello world" << endl; }
};

//template <class T> void f();

template <class T, int t>
void g()
{
  T().f<t>();
}

int main() {
  g<A,0>();
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]