https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61745
Bug ID: 61745
Summary: template friend for dyadic operator- is only accepted
if the monadic operator- follows it
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jarausch at igpm dot rwth-aachen.de
If a template class contains both, the monadic and the dyadic operator-
the friend declaration is only accepted if it preceeds the
definition of the monadic operator.
This occurs with gcc 4.7.4 4.8.3 and 4.9.0
template <typename INT,INT P> class Zp;
template <typename INT,INT P>
Zp<INT,P> operator-(const Zp<INT,P>& a, const Zp<INT,P>& b);
template <typename INT,INT P>
class Zp {
public:
static const INT p = P;
private:
INT val;
public:
Zp() : val(0) {}
Zp( INT x ) : val(x%p) { if (x < 0 ) x+= p; }
// this compiles only if the following definition is moved AFTER the friend
declataion
Zp operator-() const { return Zp(p-val); }
friend Zp<INT,P> operator- <>(const Zp<INT,P>& a, const Zp<INT,P>& b);
/*
Quest_Templ.C:23:28: error: declaration of 'operator-' as non-function
friend Zp<INT,P> operator- <Zp<>(const Zp<INT,P>& a, const Zp<INT,P>& b);
^
Quest_Templ.C:23:28: error: expected ';' at end of member declaration
Quest_Templ.C:23:30: error: expected unqualified-id before '<' token
friend Zp<INT,P> operator- <Zp<>(const Zp<INT,P>& a, const Zp<INT,P>& b);
*/
};