-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lib] LWG 3239: inline definition in the header / class synopsis #3110
Comments
For hidden friends this is intentional, to show that they are supposed to be defined inline and not have a namespace-scope declaration. Simply defining them inline isn't sufficient for that though (nothing prevents an implementation from adding a declaration outside the class), so there's a proposal to define new wording that states the intent clearly. For member functions there's a sort-of-policy to define then inline if they use return type deduction, which is @AlisdairM's idea and is proving unpopular. |
For constructors we've been defining them inline for some time, when the constructor delegates to another and has an empty body. |
I've started a description here: I'm mostly ok (although not enthusiastic) regarding the rule for the delegating constructors, but the hidden friends are not helpful as-is. We should rather have blanket wording that all friends shown in a class synopsis shall not have namespace-level declarations (unless expressly shown otherwise), which automatically implies that the friend declaration must also be the definition (but that's an implementation detail). |
That's what http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1601r0.pdf aims to fix. |
Except it doesn't add wording that prevents an implementation from adding a namespace-scope redeclaration. |
A namespace-scope redeclaration would make this requirement hard to meet:
That suggests that every hidden friend does need a separate
|
Or we could just add that blanket wording now, saying that all friend functions defined inline in the class synopsis are to be found via ADL only (maybe with a note saying that means no namespace-scope declaration). That would be a much smaller edit and would fix all existing uses of the idiom. |
So, the result seems to be:
|
Is there any reason to restrict this to only those friend functions that are defined in the class definition, as opposed to all friend functions declared in a class definition and not redeclared outside that class definition at namespace scope? To my knowledge we have no non-hidden friends declared in the Library since we largely leave it unspecified how non-member functions obtain access to class members needed to achieve their specification. Conversely, we have seen a couple examples of functions that couldn't be inlined into a class definition due to the need to specify some non-code behavior; it would be a shame if we eventually stumble across such a function that we'd like to be a hidden friend. EDIT: Bah, the second bullet above addresses my problem scenario. Let's ignore that bit of rationale, and revert my statement to "it would be nice to keep the location of function specification (inline in the class definition vs. |
@CaseyCarter, I agree. In general, we should keep the amount of inline code to a minimum, and favor This needs LWG coordination via LWG issue 3239. |
Right. Technically, only a namespace-scope declaration in a synopsis codeblock counts as such, but we should avoid that subtlety. |
Editorial teleconference: Let's wait until the LWG issue is resolved. |
P1965R0 got merged, and with the updated editorial guidance, this seems to be moot. |
Beyond the accepted =default and =delete, actual code definitions (with braces) have crept up in the header or class synopses with the recent batch of motions. The alternative presentation would be to have an itemdecl / itemdescr with "Effects: Equivalent to" codeblock.
For example, this applies to constructors and inline friends.
We should clarify the style guidelines to say what we want here.
The text was updated successfully, but these errors were encountered: