CWG Issue 477 (original) (raw)
This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-11-05
477. Can virtual appear in a friend declaration?
Section: 9.2.3 [dcl.fct.spec]Status: CD1Submitter: Daveed VandevoordeDate: 23 Sep 2004
[Voted into WP at the October, 2006 meeting.]
I couldn't find wording that makes it invalid to sayfriend virtual... The closest seems to be 9.2.3 [dcl.fct.spec] paragraph 5, which says:
The virtual specifier shall only be used in declarations of nonstatic class member functions that appear within a_member-specification_ of a class definition; see 11.7.3 [class.virtual].
I don't think that excludes a friend declaration (which is a valid member-specification by 11.4 [class.mem]).
John Spicer: I agree that virtual should not be allowed on friend declarations. I think the wording in 9.2.3 [dcl.fct.spec] is intended to be the declaration of a function within its class, although I think the wording should be improved to make it clearer.
Proposed resolution (October, 2005):
Change 9.2.3 [dcl.fct.spec] paragraphs 5-6 as indicated:
The virtual specifier shall
onlybe used only indeclarationsthe initial declarationof a non-static class memberfunctions that appear within a_member-specification_ of a class definitionfunction; see 11.7.3 [class.virtual].The explicit specifier shall be used only in
declarationsthe declaration ofconstructorsa constructor withinaits class definition; see 11.4.8.2 [class.conv.ctor].