This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/17122] Unable to compile friend operator within template
- From: "manu at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 12 Apr 2012 13:05:16 +0000
- Subject: [Bug c++/17122] Unable to compile friend operator within template
- Auto-submitted: auto-generated
- References: <bug-17122-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17122
Manuel LÃpez-IbÃÃez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu.org
--- Comment #14 from Manuel LÃpez-IbÃÃez <manu at gcc dot gnu.org> 2012-04-12 13:05:16 UTC ---
(In reply to comment #13)
> Are any of the examples in this PR actually valid?
>
> I think G++ is correct to reject them.
>
> foo ::operator+ is parsed the same as foo::operator+ so still finds the member
> function, the parentheses prevent that.
Maybe g++ is correct to reject them, but the diagnostics printed are awful.
They are actually worse than saying:
error: Something is wrong somewhere, Please fix it.
template <class blah>
class foo;
template <class blah>
void operator+(int, foo<blah>);
template <class blah>
void operator-(int, foo<blah>);
template <class blah>
class foo
{
public:
void operator+(int){}
friend void operator+<>(int, foo);//eliminating <> generates warning to add
//them
friend void operator-(int, foo);//eliminating <> generates warning to add
//them
};
template <class blah>
void operator+(int, foo<blah>){}
template <class blah>
void operator-(int, foo<blah>){}
int main()
{
foo<double> inst;
inst+1;
1+inst;
};
pr17122.C:15:23: error: declaration of âoperator+â as non-function
friend void operator+<>(int, foo);//eliminating <> generates warning to add
^
pr17122.C:15:23: error: expected â;â at end of member declaration
friend void operator+<>(int, foo);//eliminating <> generates warning to add
^
pr17122.C:15:24: error: expected unqualified-id before â<â token
friend void operator+<>(int, foo);//eliminating <> generates warning to add
^
pr17122.C:17:33: warning: friend declaration âvoid operator-(int, foo<blah>)â
declares a non-template function [-Wnon-template-friend]
friend void operator-(int, foo);//eliminating <> generates warning to add
^
pr17122.C:17:33: note: (if this is not what you intended, make sure the
function template has already been declared and add <> after the function name
here)
friend void operator-(int, foo);//eliminating <> generates warning to add
^