-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Add tests for CWG issues about friend declaration matching #106117
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
Conversation
@llvm/pr-subscribers-clang Author: Vlad Serebrennikov (Endilll) ChangesThis patch covers CWG issues regarding declaration matching when CWG138 "Friend declaration name lookup"P1787R6: I find it hard to pin down the scope of this issue, so I'm relying on three examples from the filing to define it. Because of that, it's also hard to pinpoint exact wording changes that resolve it. Relevant references are: [dcl.meaning.general]/2, [[namespace.udecl]/10](https://eel.is/c++draft/namespace.udecl#10), [[dcl.type.elab]/3](https://eel.is/c++draft/dcl.type.elab#3), [[basic.lookup.elab]/1](https://eel.is/c++draft/basic.lookup.elab#1). CWG386 "Friend declaration of name brought in by using-declaration"P1787R6: Wording ([dcl.meaning.general]/2): This issue focuses on interaction of CWG1477 "Definition of a
|
I think both CWG1900 and CW1477 can be marked as implemented with such a test namespace N {
struct A {
friend int f();
};
}
int N::f() { return 0; }
int N::g() { return 0; }
// expected-error@-1 {{out-of-line definition of 'g' does not match any declaration in namespace 'N'}} Resolved by https://eel.is/c++draft/dcl.meaning#general-3.4.sentence-2 added by p1787r6 |
// so target scope of this friend declaration is also N1. | ||
// FIXME: This is well-formed. | ||
friend void f<>( Test* x ); | ||
// expected-error@-1 {{no function template matches function template specialization 'f'}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, it's confused by the namespaces - or more likely, the using declarations
https://compiler-explorer.com/z/oP6Er4e4j
// expected-error@-1 {{cannot befriend target of using declaration}} | ||
// expected-note@#cwg138-ex1-foo {{target of using declaration}} | ||
// expected-note@#cwg138-ex1-using {{using declaration}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to try to fix this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has that good first issue feel, so I'll refrain for now. But I'll get to all name lookup issues when I'm done with writing tests for P1787R6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Please wait a couple of days in case @hubert-reinterpretcast @shafik @AaronBallman have more feedback
@cor3ntin Can you take another look? I added CWG1900 section to the PR description. Nothing has changes for other Core issues. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/4752 Here is the relevant piece of the build log for the reference
|
The failure is unrelated. |
This patch covers CWG issues regarding declaration matching when
friend
declarations are involved: CWG138, CWG386, CWG1477, and CWG1900. Atypical for our CWG tests, the ones in this patch are quite extensively commented in-line, explaining the mechanics. PR description focuses on high-level concerns and references.CWG138 "Friend declaration name lookup"
P1787R6:
I find it hard to pin down the scope of this issue, so I'm relying on three examples from the filing to define it. Because of that, it's also hard to pinpoint exact wording changes that resolve it. Relevant references are: [dcl.meaning.general]/2, [namespace.udecl]/10, [dcl.type.elab]/3, [basic.lookup.elab]/1.
CWG386 "Friend declaration of name brought in by using-declaration"
P1787R6:
Wording ([dcl.meaning.general]/2):
This issue focuses on interaction of
friend
declarations with template-id and qualified-id with using-declarations. The short answer is that terminal name in such declarations undergo lookup, and using-declarations do what they usually do helping that lookup. Target scope of such friend declaration is the target scope of lookup result, so no conflicts arise with the using-declarations.CWG1477 "Definition of a
friend
outside its namespace"P1787R6:
Wording ([dcl.meaning.general]/3.4):
This issue focuses on befriending a function in one scope, then defining it from other scope using qualified-id. Contrary to what P1787R6 says in prose, this example is accepted by the wording in that paper. In the wording quote above, note the absence of a statement like "terminal name of the declarator-id is not bound", contrary to similar statements made before that in [dcl.meaning.general] about friend declarations and template-ids.
There's also a note in [basic.scope.scope] that supports the rejection, but it's considered incorrect and expected to be removed in the future. This is tracked in cplusplus/draft#7238.
CWG1900 "Do
friend
declarations count as “previous declarations”?"P1787R6:
Wording ([dcl.meaning.general]/2.3):
Wording ([basic.scope.scope]/7):
Wording ([dcl.meaning.general]/3.4):
In the new wording it's clear that while
friend
declarations of functions do not bind names, declaration is still introduced, and is nominable, making it eligible for a later definition by qualified-id.