- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
we just stumbled over a weird parser error in ICC (both 13 and 15). The following code does not compile:
#include <iostream> template<class T> int bar ( const T& ) { return 0; } struct Foo { int bar; }; template<class F> void callBar ( F& foo ) { if( foo.bar<0 ) std::cout<<foo.bar<<std::endl; } int main () { Foo foo; foo.bar = -1; callBar( foo ); return 0; }
On both compilers, it fails with
test.cc(14): error: expected a ">" if( foo.bar < 0 ) ^ compilation aborted for test.cc (code 2)
The problem seems to be that for some reason, the "<" after "bar" causes the compiler to assume that "bar" refers to the freestanding template function. Accordingly, it interprets 0 as the template argument and then expects a ">" to end the template argument list. This looks a little bit like the inverse of the well-known situation where you have to precede template member function invocation by the "template" keyword as in "foo. template baz<2>()".
GCC also fails to compile the example above, while clang has no problems with it. Both ICC and GCC will happily accept the code after adding parentheses around "foo.bar".
Is this a defect, or is the compiler supposed to reject code like that according to the standard?
Thanks,
Steffen
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This looks to me a compiler error. I have submitted a report to Intel compiler development team on this. I will update the thread when I have more information.
Thanks,
Om
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page