-
Notifications
You must be signed in to change notification settings - Fork 771
[dcl.spec.auto.general] Call to conversion function whose conversion-function-id contains a placeholder CWG2493 #4811
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
Comments
Issue #4671 is potentially related to this. I think we could consider |
However, "operator auto" should be the declarator-id on grammar, which means the name lookup rule has to use the declarator-id to find out the declaration. Maybe, the rule for "how auto gets transformed to int" would cover this concern. |
I don't think that's obvious. See prior discussion in http://lists.isocpp.org/core/2018/01/3737.php, which seemed to be leaning towards #1 being correct. |
That discussion predates P1787R6, I believe. |
[dcl.spec.auto.general] p6 says
The use of |
I don't think P1787R6 really intended to address this question. To the extent it did anything here, I think it made the problem worse -- after that wording change, I think we no longer consider a function whose name is |
The interpretation that I want, consistent with the (unfortunate) fact that struct X {
virtual operator int() {return 1;}
};
struct Y {
operator auto() {return 1;}
};
int f(X x) {return x.operator int();} // OK
int f(Y y) {return y.operator int();} // error: name lookup failed
struct Y2 : X {
operator auto() override {return 1;} // error: doesn't override
}; This was, I believe, at least my subconscious intent in writing P1787. Since we can't refer to a function with an undeduced return type, this almost works even for a function that has been declared but not defined: struct Z {
operator auto();
};
void f(Z z) {
z.operator auto(); // error: name lookup failed
z.operator int(); // error: maybe you guessed its name right, but you can't call it here
} However, it breaks down if we try to do more than that: struct W {
operator auto();
operator auto(); // ???
}; Of course, neither does it really work to just say that struct V {
operator auto();
operator auto*(); // OK...
static int i;
};
V::operator auto() {return &i;}
V::operator auto*() {return &i;}
int *p=V(); // what does this call? If we do say that |
In this example, GCC only accepts the manner of #2 while Clang only accepts #1. However, The usage of #1 seems to be ill-formed as per [dcl.spec.auto#6]. For
operator int
, it's not the id-expression of the conversion function whose name should have beenoperator auto
.As per [dcl.spec.auto#13], that is:
So, it seems that
operator auto
might be the unique name to nominate the conversion function(As a qualified-id that appears in the declarator-id when defining the entity outside the enclosing class definition).So, the issue falls out which is the name of the conversion function? Literally, the unique name should be
operator auto
, however, when using the name as an id-expression of a class member access expression, such usage is forbidden by [dcl.spec.auto]. The standard does not specify what should do here.The text was updated successfully, but these errors were encountered: