Bug 46839 - Parser confuses derived member with std::forward
Summary: Parser confuses derived member with std::forward
Status: RESOLVED DUPLICATE of bug 20308
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-07 17:02 UTC by Tobias Föhst
Modified: 2010-12-07 17:24 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Info about gcc build configuration (487 bytes, text/plain)
2010-12-07 17:02 UTC, Tobias Föhst
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Föhst 2010-12-07 17:02:34 UTC
Created attachment 22673 [details]
Info about gcc build configuration

01: #include <iostream>
02: #include <utility>
03: using namespace std;
04:
05: template <typename T> struct A
06: {
07:   T forward;
08:   A() : forward(0) {}
09: };
10:
11: template <typename T> struct B : public A<T>
12: {
13:   void Function()
14:   {
15:     cout << (this->forward > 1) << endl;
16:     cout << (this->forward < 1) << endl;
17:   }
18: };
19:
20: int main(int argc, char **argv)
21: {
22:   return 0;
23: }

g++ -Wall -std=gnu++0x

: In member function ‘void B<T>::Function()’:
:16: error: parse error in template argument list

Used compiler version: gcc version 4.4.3 (Gentoo 4.4.3-r2 p1.2)
4.3 and 4.5 versions show the same behavior.

It seems, that in line 16 "forward <" is parsed as the beginning of a template instantiation. To get this effect, the inclusion of <utility>, using namespace std and using derived members in a template class is necessary. Maybe, using namespace typically appears after template definition in other h-files, but a scenario like this might occur. Apart from that: Would "this->std::forward<...>" be valid C++ code?

Therefore, I think that is a bug in the parsers which neglects the occurrence of this and starts to interpret forward as the std::forward template.

Regards,
Tobias Föhst
Comment 1 Tobias Föhst 2010-12-07 17:12:45 UTC
I forgot: Line 15 is only there to prove that this->forward with another successor than '<' can be resolved as the member derived from A<T>.
Comment 2 Paolo Carlini 2010-12-07 17:19:42 UTC
Note that Intel compiler, based on the EDG C++ front-end, also rejects this code in strict mode. Likewise of course Comeau. This is enough to show the issue:

template<typename T>
  void forward(T);

template <typename T> struct A
{
  T forward;
};

template <typename T> struct B : public A<T>
{
  void Function()
  {
    this->forward < 1;
  }
};
Comment 3 Andrew Pinski 2010-12-07 17:24:19 UTC
See PR 20308 and such.

*** This bug has been marked as a duplicate of bug 20308 ***