Bug 22378 - [regression 4.0.1 -> 4.0.0,3.4.x] Friend decl ceases to declare class
Summary: [regression 4.0.1 -> 4.0.0,3.4.x] Friend decl ceases to declare class
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-08 19:50 UTC by John Vickers
Modified: 2005-07-23 22:49 UTC (History)
1 user (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 John Vickers 2005-07-08 19:50:57 UTC
[jv@smith misc]$ cat -n decl_friend_class.cpp
     1
     2  #ifdef DD
     3  class d;
     4  #endif
     5
     6  class c
     7  {
     8    friend class d;
     9    d* p;
    10  };
    11
[jv@smith misc]$ /usr/local/gcc/gcc-4.0.0/bin/g++ -c -W -Wall decl_friend_class.cpp
[jv@smith misc]$ /usr/local/gcc/gcc-4.0.1/bin/g++ -c -W -Wall decl_friend_class.cpp
decl_friend_class.cpp:9: error: ISO C++ forbids declaration of 'd' with no type
decl_friend_class.cpp:9: error: expected ';' before '*' token
[jv@smith misc]$ /usr/local/gcc/gcc-4.0.1/bin/g++ -c -W -Wall -fpermissive
decl_friend_class.cpp
decl_friend_class.cpp:9: warning: ISO C++ forbids declaration of 'd' with no type
decl_friend_class.cpp:9: error: expected ';' before '*' token
[jv@smith misc]$ /usr/local/gcc/gcc-4.0.1/bin/g++ -c -W -Wall -DDD
decl_friend_class.cpp
[jv@smith misc]$ icc -c -w2 decl_friend_class.cpp
[jv@smith misc]$

The icc here is icc 8.1

The original testcase comes from SystemC 2.0.1,
in include/systemc/kernel/sc_module_name.h

( http://www.systemc.org/ )

IANAC++LL.  It is not immediately clear to me from the
standard whether a friend class decl declares that class,
though the description of a friend function decl suggests
- to me, anyway - that it might.

I would be grateful if anyone could refer me to a discussion
of whether or not this is valid C++, acording to current
interpretations of the standard.

However:

I believe that this code is accepted by gcc-2.95, gcc-3.2.x, gcc-3.4.x,
gcc-4.0.0 without warning, so if it has been determined to be invalid,
it should reeceive a "deprecated" warning and/or require -fpermissive
before it ceases to be accepted by gcc.

Regards,

John.

I will test minor release candidates more in future...
Comment 1 Andrew Pinski 2005-07-08 19:53:57 UTC
The code is in fact invalid.

friend should not inject the class at all.

The reason why we did not have a deprecated period or allow it with -fpermissive is because we 
actually got a bug report about accepting this invalid code.

Just add the forward declaration.