Bug 60611 - friend function declaration rejected when the namespace in which it is declared is not explicitely specified in the declaration
Summary: friend function declaration rejected when the namespace in which it is declar...
Status: RESOLVED DUPLICATE of bug 57376
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: c++-friends, cxxfriends
  Show dependency treegraph
 
Reported: 2014-03-21 14:05 UTC by nicolas.bertolotti
Modified: 2019-01-24 11:40 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-03-21 00:00:00


Attachments
Source file to reproduce the issue (151 bytes, text/plain)
2014-03-21 14:05 UTC, nicolas.bertolotti
Details

Note You need to log in before you can comment on or make changes to this bug.
Description nicolas.bertolotti 2014-03-21 14:05:28 UTC
Created attachment 32419 [details]
Source file to reproduce the issue

If you compile the following piece of code using g++ (4.7.2):
"
class class1; 

namespace ns1 { 

class class2; 
class class3; 
}

ns1::class3 *func(ns1::class2 * cfg, const class1 * def); 

namespace ns1 { 

class class4 { 
#ifdef WORKAROUND
friend ns1::class3 *(::func)(ns1::class2 * cfg, const class1 * def);
#else
friend class3 *(::func)(class2 * cfg, const class1 * def); 
#endif
}; 
}
" (also attached)
you get the following:
$ g++ -c test.cpp
test.cpp:17:25: error: ‘func’ is neither function nor member function; cannot be declared friend
test.cpp:17:23: error: expected ‘;’ at end of member declaration
test.cpp:17:32: error: expected ‘)’ before ‘*’ token

Now, if you explicitely add the namespaces as they appear in the initial declaration (add -DWORKAROUND), the compilation succeeds.
Comment 1 Jonathan Wakely 2019-01-24 11:40:10 UTC
This looks like a dup

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