]> granicus.if.org Git - clang/commitdiff
Use the member function location in enable_if diagnostics.
authorGeorge Burgess IV <george.burgess.iv@gmail.com>
Wed, 16 Nov 2016 21:31:25 +0000 (21:31 +0000)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Wed, 16 Nov 2016 21:31:25 +0000 (21:31 +0000)
Before:
<stdin>:3:3: error: no matching member function for call to 'bar'
  Foo().bar();
  ^

After:
<stdin>:3:9: error: no matching member function for call to 'bar'
  Foo().bar();
        ^

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@287154 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOverload.cpp
test/SemaCXX/enable_if.cpp

index 2e567863261c9b9f1a256c88d65e43140081303e..cf90a3438351e050f2bb7f2a49075e7cb366a60c 100644 (file)
@@ -12499,9 +12499,9 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
   // In the case the method to call was not selected by the overloading
   // resolution process, we still need to handle the enable_if attribute. Do
   // that here, so it will not hide previous -- and more relevant -- errors.
-  if (isa<MemberExpr>(NakedMemExpr)) {
+  if (auto *MemE = dyn_cast<MemberExpr>(NakedMemExpr)) {
     if (const EnableIfAttr *Attr = CheckEnableIf(Method, Args, true)) {
-      Diag(MemExprE->getLocStart(),
+      Diag(MemE->getMemberLoc(),
            diag::err_ovl_no_viable_member_function_in_call)
           << Method << Method->getSourceRange();
       Diag(Method->getLocation(),
index 81308136c4801445cc5f42ca1a8779c84f6ca8b2..e265b410ac8e2149bbd7b43b99e57e3277472e99 100644 (file)
@@ -440,3 +440,13 @@ void testFoo() {
   foo(1, 0, m, 3); // expected-error{{no matching}}
 }
 }
+
+// Tests that we emit errors at the point of the method call, rather than the
+// beginning of the expression that happens to be a member call.
+namespace member_loc {
+  struct Foo { void bar() __attribute__((enable_if(0, ""))); }; // expected-note{{disabled}}
+  void testFoo() {
+    Foo()
+      .bar(); // expected-error{{no matching member function}}
+  }
+}