I have code which uses a preprocessor-heavy framework to generate some utility classes. Apparently, some of the macros result in the same friend
declaration being included twice in a class, something like this:
class Friendly {
// :::
friend class Bestie;
friend class Bestie;
// :::
};
When built with gcc (4.8.1), it generates a warning like
Bestie
is already a friend ofFriendly
[enabled by default]
I can't really see a use in this warning. I'm curious why it was included in gcc in the first place. However, as that is hardly answerable by the SO community, I'll state my question like this: What problems could arise from a friend
declaration being repeated, or what likely programmer errors could such an occurrence indicate?
The only problem I can think of which this could be hinting at is "You may have intended to write something else here instead of the same thing again, so I will helpfully warn you about this." However, in such case, the intended friendship would be missing, which would lead to an "access control violation" error in the code exercising the friendship, so I see little use of the warning itself.
Are there any potential problems I'm overlooking?
I dont think it is usefull to declare your friend class many times. I think it was a bug which was reported and I think they have provided a work around. It is better to just declare a friend to your class at once and should avod the duplication later. Also check this
I think the warning was only to inform the user that he has written redundant code many times which is of no use. Else I dont think that there was any use of this warning. That is why most of the programmers reported it as a bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With