Warning C4430 not being thrown in friend declaration

class myClass;

class otherClass {

public:

otherClass(int x): valor(x) {}

inline int sum(myClass &obj);

private:

int valor;

};

class myClass {

public:

myClass(int x): val(x) {}

friend otherClass::sum(myClass&);

private:

int val;

};

inline int otherClass::sum(myClass &obj) {

return obj.val + valor;

}

The above is a minimalist example to illustrate the problem at hand.

Note how the friend declaration is not defining the return type of otherClass::sum() and yet Warning C4430 is not being thrown.

Is this a bug Or is there some compiler option I'm setting that precludes the warning

This is my compiler's command line:

/Od /D "_WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /FD /EHsc /MDd /Gy /Za /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W4 /nologo /c /Zi /TP /errorReport:prompt



Answer this question

Warning C4430 not being thrown in friend declaration

  • edburdo

    Curious, because this piece of code, generates C4430:

    class foo
    {
    friend operator==(const foo& f1, const foo& f2);
    };



  • eza

    I just saw this. Yep it's a bug and it still repro's with the latest build of the compiler.

  • John Black

    A friend function declaration requires a function-declarator. Since functions cannot be overloaded by return type, a return type declaration is not needed. If you include one, it is checked, possibly generating C2556.



  • dan kisting

    nobugz wrote:
    A friend function declaration requires a function-declarator. Since functions cannot be overloaded by return type, a return type declaration is not needed. If you include one, it is checked, possibly generating C2556.

    Wouldn't that be the same as state that any function declaration does not require a return type We know that is not true. Previous compilers assumed int. That is no longer the case.

    When I include the return type, no warning is generated. Which is as expected, since when I include the return type I'm following ISO (read 7.1 and 11.4).


  • Adrian_Peirson

    Posted bug report with same title
  • Warning C4430 not being thrown in friend declaration