different friend functions behaviour

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello gcc-help list,

I notice a strange (as my opinion) behaviour on gcc version 4.3.2.

I know that started from gcc-4.1 "ARM-style name-injection of friend declarations is no longer the default" .

So the following code doesn't build:
$ cat test_friend_function_1.cpp

class test {
public:
friend void ftest1(int x) {
}

};

int main(int argc, char *argv[]) {
ftest1(5);
}

$ g++ test_friend_function_1.cpp
test_friend_function_1.cpp: In function ‘int main(int, char**)’:
test_friend_function_1.cpp:10: error: ‘ftest1’ was not declared in this scope
$
... BUILD ERRORS

So as it's shown in http://gcc.gnu.org/ml/gcc-bugs/2008-08/msg00860.html it is necessary to use -ffriend-injection option.

$ g++ -ffriend-injection test_friend_function_1.cpp
$
... BUILD SUCCESS

But if I try with the following code:
$ cat test_friend_function_2.cpp

class test {
public:
friend void ftest2(test x) {
}

};

int main(int argc, char *argv[]) {
ftest2(test());
}

$ g++ test_friend_function_2.cpp
$
... BUILD SUCCESS

The build process goes even without the -ffriend-injection option.

The difference between the two friend functions is that the first has not any test class as argument while the second has a test class as argument.

Is this the right behaviour?

Thank you in advance for answers and/or comments.


Fabio Tesser















[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux