[cfe-commits] r83650 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaOverload.cpp test/SemaCXX/builtin-ptrtomember-ambig.cpp

Fariborz Jahanian fjahanian at apple.com
Fri Oct 9 10:09:58 PDT 2009


Author: fjahanian
Date: Fri Oct  9 12:09:58 2009
New Revision: 83650

URL: http://llvm.org/viewvc/llvm-project?rev=83650&view=rev
Log:
Produce good looking diagnostics on ambiguous built-in operators.
Now we produce things like:
bug1.cpp:21:11: error: use of overloaded operator '->*' is ambiguous
        int i = c->*pmf;        // expected-error {{use of overloaded operator '->*' is ambiguous}} \
                ~^  ~~~
bug1.cpp:21:11: note: built-in candidate operator ->* ('struct A volatile *', 'int const struct A::*')
bug1.cpp:21:11: note: built-in candidate operator ->* ('struct A volatile *', 'int restrict struct A::*')
..

Still need to look at an issue (indicated as FIXME in the test case).

Added:
    cfe/trunk/test/SemaCXX/builtin-ptrtomember-ambig.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=83650&r1=83649&r2=83650&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Oct  9 12:09:58 2009
@@ -778,7 +778,7 @@
   "candidate function template specialization %0">;
 def err_ovl_candidate_deleted : Note<
   "candidate function has been explicitly %select{made unavailable|deleted}0">;
-def err_ovl_builtin_candidate : Note<"built-in candidate function %0 for operator '%1'">;
+def err_ovl_builtin_candidate : Note<"built-in candidate operator %2 (%0, %1)">;
 def err_ovl_no_viable_function_in_init : Error<
   "no matching constructor for initialization of %0">;
 def err_ovl_ambiguous_init : Error<"call to constructor of %0 is ambiguous">;

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=83650&r1=83649&r2=83650&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Oct  9 12:09:58 2009
@@ -4045,14 +4045,12 @@
         Diag(Cand->Surrogate->getLocation(), diag::err_ovl_surrogate_cand)
           << FnType;
       } else if (OnlyViable) {
-        QualType FnType
-          = Context.getFunctionType(Cand->BuiltinTypes.ResultTy,
-                                    Cand->BuiltinTypes.ParamTypes,
-                                    Cand->Conversions.size(),
-                                    false, 0);
-
-        Diag(OpLoc, diag::err_ovl_builtin_candidate) << FnType <<
-	  BinaryOperator::getOpcodeStr(Opc);
+        assert(Cand->Conversions.size() == 2 && 
+               "builtin-binary-operator-not-binary");
+        Diag(OpLoc, diag::err_ovl_builtin_candidate) 
+          << Cand->BuiltinTypes.ParamTypes[0] 
+          << Cand->BuiltinTypes.ParamTypes[1] 
+          << BinaryOperator::getOpcodeStr(Opc);
       }
     }
   }

Added: cfe/trunk/test/SemaCXX/builtin-ptrtomember-ambig.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-ptrtomember-ambig.cpp?rev=83650&view=auto

==============================================================================
--- cfe/trunk/test/SemaCXX/builtin-ptrtomember-ambig.cpp (added)
+++ cfe/trunk/test/SemaCXX/builtin-ptrtomember-ambig.cpp Fri Oct  9 12:09:58 2009
@@ -0,0 +1,24 @@
+// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x
+
+struct A {};
+
+struct R {
+    operator const A*();
+};
+
+
+struct B  : R {
+    operator A*();
+};
+
+struct C : B {
+
+};
+
+
+void foo(C c, int A::* pmf) {
+       				// FIXME. Why so many built-in candidates?
+	int i = c->*pmf; 	// expected-error {{use of overloaded operator '->*' is ambiguous}} \
+				// expected-note 40 {{built-in candidate operator ->* ('struct A}}
+}
+





More information about the cfe-commits mailing list