Bug 24629 - Can't use template argument as friend
Summary: Can't use template argument as friend
Status: RESOLVED DUPLICATE of bug 47721
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.4
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 30390 36601 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-11-02 01:48 UTC by Michael Lindner
Modified: 2011-02-14 23:07 UTC (History)
3 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Lindner 2005-11-02 01:48:11 UTC
Fails on:
  gcc (GCC) 3.3.4 (Mandrakelinux 10.1 3.3.4-2mdk)
  Linux 2.6.8.1-12mdk #1 i686 Athlon XP GNU/Linux

and

  g++ (GCC) 3.4.0
  SunOS 5.9 Generic_112233-12 sun4u sparc SUNW,UltraAX-i2

The following fails to compile:

template<class T>
class Foo {
    // The "friend" declaration below causes fialure with
    // error: using template type parameter `T' after `class'
    friend class T;
};

class Bar {
};

int
main(int, char**)
{
    Foo<Bar> foo;
    return 0;
}
Comment 1 Andrew Pinski 2005-11-02 01:53:40 UTC
I don't think this is valid C++ (at least C++98).
Comment 2 Giovanni Bajo 2005-11-02 09:20:06 UTC
Template parameters can't be used in friend declarations (nor in any elaborated type specifier construct).
Comment 3 Michael Lindner 2005-11-03 01:28:29 UTC
Mea Culpa. It was supported by the other compilers I use (MS and Sun), and it seemed like such an obvious thing to want to do, and I didn't think anyone would want explicitly to exclude it, so I didn't check the standard. I'm *very* sorry to have wasted your time. FWIW, I discovered a workaround at http://www.byte.com/documents/s=9162/cujexp0312wilson2/
Comment 4 Andrew Pinski 2007-01-06 05:28:20 UTC
*** Bug 30390 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2008-06-22 20:13:43 UTC
*** Bug 36601 has been marked as a duplicate of this bug. ***
Comment 6 Andrew Pinski 2011-02-14 23:07:25 UTC
C++0x has changed the rules slightly and allows:
template<class T>
class Foo {
    friend T;
};

But GCC does not implement this new rule yet. See 47721.

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