]> granicus.if.org Git - clang/commitdiff
Pass the correct object argument when a member call to an 'unrelated' class is made.
authorFaisal Vali <faisalv@yahoo.com>
Sun, 27 Aug 2017 02:21:21 +0000 (02:21 +0000)
committerFaisal Vali <faisalv@yahoo.com>
Sun, 27 Aug 2017 02:21:21 +0000 (02:21 +0000)
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

lib/Sema/SemaExprMember.cpp
test/SemaCXX/member-expr.cpp

index 1c34ace856280271a911a4e2f0e26e839eed5899..47b18dc39ead2184e490b36eb8ff789b5bd18db8 100644 (file)
@@ -243,7 +243,6 @@ Sema::BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
     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);
@@ -252,6 +251,7 @@ Sema::BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
     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:
index 3571fa748b818dedbffb638d7bcb4e636a824648..53f4673a3d44207d04a5bd78d756f6b9df47eb84 100644 (file)
@@ -228,3 +228,25 @@ namespace pr16676 {
         .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