Prior to this patch, clang would do the wrong thing here (see inline comments for pre-patch behavior):
struct A {
void bar(int) { }
static void bar(double) { }
void g(int*);
static void g(char *);
};
struct B {
void f() {
A::bar(3); // selects (double) ??!!
A::g((int*)0); // Instead of no object argument, states conversion error?!!
}
};
The fix is as follows: When we detect that what appears to be an implicit member function call (A::bar) is actually a call to a member of a class (A) unrelated to the type (B) that contains the member function (B::f) from which the call is being made, don't treat it (A::bar) as an Implicit Member Call Expression.
P.S. I wonder if there is an existing bug report related to this? (Surprisingly, a cursory search did not find one).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311839
91177308-0d34-0410-b5e6-
96231b3b80d8
return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, true, S);
case IMA_Mixed:
- case IMA_Mixed_Unrelated:
case IMA_Unresolved:
return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, false,
S);
Diag(R.getNameLoc(), diag::warn_cxx98_compat_non_static_member_use)
<< R.getLookupNameInfo().getName();
// Fall through.
+ case IMA_Mixed_Unrelated:
case IMA_Static:
case IMA_Abstract:
case IMA_Mixed_StaticContext:
.i; // expected-error {{member reference type 'pr16676::S *' is a pointer; did you mean to use '->'}}
}
}
+
+namespace unrelated_class_instance_call_should_be_illformed {
+
+
+struct A {
+ void bar(int) { }
+ static void bar(double) { }
+
+ void g(int*);
+ static void g(char *);
+};
+
+
+struct B {
+ void f() {
+ A::bar(3); //expected-error{{call to non-static member}}
+ A::g((int*)0); //expected-error{{call to non-static member}}
+ }
+};
+
+
+} // ns unrelated_class_mixed_static_nonstatic_call_should_be_illformed