This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: g++ 2.95.2 can't handle dependent friend member functions
- To: <sebor at my-Deja dot com>
- Subject: Re: g++ 2.95.2 can't handle dependent friend member functions
- From: <llewelly at 198 dot dsl dot xmission dot com>
- Date: Fri, 24 Dec 1999 14:50:25 -0700 (MST)
- cc: gcc-bugs at gcc dot gnu dot org
On Fri, 24 Dec 1999, wrote:
> Hi,
>
> the program below doesn't compile with g++ 2.95.2. I can't find anything
> in 11.4 or in 14.5.3 that would indicate that the code is not legal. It
> compiles fine with edg 2.42. Am I missing something or is this a g++
> bug?
>
> Thanks
> Martin
>
>
> $ cat test.cpp
>
> struct B
> {
> static void foo () { }
> };
>
>
> template <class T>
> struct A
> {
> friend void T::foo (); // <-- error
> friend void B::foo (); // <-- ok
> };
>
> int main ()
> {
> A<B> a;
> }
>
>
> $ g++ -v test.cpp
> Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs
> gcc version 2.95.2 19991024 (release)
> /usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cpp -lang-c++ -v -D__GNUC__=2
> -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix
> -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix
> -D__linux -Asystem(posix) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386)
> -Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686 -D__i686__
> -D__pentiumpro -D__pentiumpro__
> /build/sebor/dev/stdlib2/tests/regress/src/test.cpp /tmp/ccWfj4o0.ii
> GNU CPP version 2.95.2 19991024 (release) (i386 Linux/ELF)
> #include "..." search starts here:
> #include <...> search starts here:
> /usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3
> /usr/local/include
>
> /usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../i686-pc-linux-gnu/include
> /usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/include
> /usr/include
> End of search list.
> The following default directories have been omitted from the search
> path:
> End of omitted list.
> /usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cc1plus /tmp/ccWfj4o0.ii
> -quiet -dumpbase test.cc -version -o /tmp/ccofIB0P.s
> GNU C++ version 2.95.2 19991024 (release) (i686-pc-linux-gnu) compiled
> by GNU C version 2.95.2 19991024 (release).
> test.cpp:12: `T::foo' is not a valid declarator
> test.cpp:12: perhaps you want `typename T::foo' to make it a type
> test.cpp: In instantiation of `A<B>':
> test.cpp:18: instantiated from here
> test.cpp:5: confused by earlier errors, bailing out
>
>
Adding 'typename' to the friend decl (as the error message suggests, and
as one might do for a friend class ) fails as well:
$cat template_dependent_friend_bug.cc
struct B
{
static void foo () { }
};
template <class T>
struct A
{
friend typename void T::foo (); // <-- error
friend void B::foo (); // <-- ok
};
int main ()
{
A<B> a;
}
{~/cc_exer}g++ -save-temps template_dependent_friend_bug.cc
template_dependent_friend_bug.cc:10: parse error before `void'
template_dependent_friend_bug.cc: In instantiation of `A<B>':
template_dependent_friend_bug.cc:16: instantiated from here
template_dependent_friend_bug.cc:3: confused by earlier errors, bailing
out
Placing typename after void also fails:
$cat template_dependent_friend_bug.cc
struct B
{
static void foo () { }
};
template <class T>
struct A
{
friend void typename T::foo (); // <-- error
friend void B::foo (); // <-- ok
};
int main ()
{
A<B> a;
}
$g++ -save-temps template_dependent_friend_bug.cc
template_dependent_friend_bug.cc:10: two or more data types in declaration
of `type name'
template_dependent_friend_bug.cc:10: invalid type `void' declared `friend'
template_dependent_friend_bug.cc:10: parse error before `('
template_dependent_friend_bug.cc: In instantiation of `A<B>':
template_dependent_friend_bug.cc:16: instantiated from here
template_dependent_friend_bug.cc:3: confused by earlier errors, bailing
out
( by the way, I have used friend classes with operator()() members as a
substitute for this. I will send an example if anyone wants one.)