[cfe-commits] r82565 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaOverload.cpp test/SemaCXX/ambig-user-defined-convesions.cpp
Fariborz Jahanian
fjahanian at apple.com
Tue Sep 22 12:53:16 PDT 2009
Author: fjahanian
Date: Tue Sep 22 14:53:15 2009
New Revision: 82565
URL: http://llvm.org/viewvc/llvm-project?rev=82565&view=rev
Log:
Issue good ambiguity diagnostic when convesion fails.
Added:
cfe/trunk/test/SemaCXX/ambig-user-defined-convesions.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=82565&r1=82564&r2=82565&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Sep 22 14:53:15 2009
@@ -1634,8 +1634,8 @@
"types may not be defined in conditions">;
def err_typecheck_bool_condition : Error<
"value of type %0 is not contextually convertible to 'bool'">;
-def err_typecheck_ambiguous_bool_condition : Error<
- "conversion from %0 to 'bool' is ambiguous">;
+def err_typecheck_ambiguous_condition : Error<
+ "conversion from %0 to %1 is ambiguous">;
def err_expected_class_or_namespace : Error<"expected a class or namespace">;
def err_invalid_declarator_scope : Error<
"definition or redeclaration of %0 not in a namespace enclosing %1">;
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=82565&r1=82564&r2=82565&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Sep 22 14:53:15 2009
@@ -1983,10 +1983,19 @@
if (!PerformImplicitConversion(From, ToType, Flavor,
/*AllowExplicit=*/false, Elidable))
return false;
-
- return Diag(From->getSourceRange().getBegin(),
- diag::err_typecheck_convert_incompatible)
- << ToType << From->getType() << Flavor << From->getSourceRange();
+ ImplicitConversionSequence ICS;
+ OverloadCandidateSet CandidateSet;
+ if (IsUserDefinedConversion(From, ToType, ICS.UserDefined,
+ CandidateSet,
+ true, false, false) != OR_Ambiguous)
+ return Diag(From->getSourceRange().getBegin(),
+ diag::err_typecheck_convert_incompatible)
+ << ToType << From->getType() << Flavor << From->getSourceRange();
+ Diag(From->getSourceRange().getBegin(),
+ diag::err_typecheck_ambiguous_condition)
+ << From->getType() << ToType << From->getSourceRange();
+ PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false);
+ return true;
}
/// TryObjectArgumentInitialization - Try to initialize the object
@@ -2104,13 +2113,13 @@
OverloadCandidateSet CandidateSet;
if (IsUserDefinedConversion(From, Context.BoolTy, ICS.UserDefined,
CandidateSet,
- true, true, false) != OR_Ambiguous)
+ true, false, false) != OR_Ambiguous)
return Diag(From->getSourceRange().getBegin(),
diag::err_typecheck_bool_condition)
<< From->getType() << From->getSourceRange();
Diag(From->getSourceRange().getBegin(),
- diag::err_typecheck_ambiguous_bool_condition)
- << From->getType() << From->getSourceRange();
+ diag::err_typecheck_ambiguous_condition)
+ << From->getType() << Context.BoolTy << From->getSourceRange();
PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false);
return true;
}
Added: cfe/trunk/test/SemaCXX/ambig-user-defined-convesions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ambig-user-defined-convesions.cpp?rev=82565&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/ambig-user-defined-convesions.cpp (added)
+++ cfe/trunk/test/SemaCXX/ambig-user-defined-convesions.cpp Tue Sep 22 14:53:15 2009
@@ -0,0 +1,19 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+struct BASE {
+ operator int &(); // expected-note {{candidate function}}
+};
+struct BASE1 {
+ operator int &(); // expected-note {{candidate function}}
+};
+
+struct B : public BASE, BASE1 {
+
+};
+
+extern B f();
+
+const int main() {
+ return f(); // expected-error {{conversion from 'struct B' to 'int const' is ambiguous}}
+}
+
More information about the cfe-commits
mailing list