[cfe-commits] r89216 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/Sema.h lib/Sema/SemaOverload.cpp test/CXX/basic/basic.lookup/basic.lookup.qual/namespace.qual/p2.cpp test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p1.cpp test/SemaCXX/rval-references.cpp test/SemaTemplate/constructor-template.cpp
Fariborz Jahanian
fjahanian at apple.com
Wed Nov 18 10:26:29 PST 2009
Author: fjahanian
Date: Wed Nov 18 12:26:29 2009
New Revision: 89216
URL: http://llvm.org/viewvc/llvm-project?rev=89216&view=rev
Log:
Improve on diagnosing type mismatches because of
lack of viable convesion functions.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.qual/namespace.qual/p2.cpp
cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p1.cpp
cfe/trunk/test/SemaCXX/rval-references.cpp
cfe/trunk/test/SemaTemplate/constructor-template.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=89216&r1=89215&r2=89216&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Nov 18 12:26:29 2009
@@ -1811,6 +1811,8 @@
"value of type %0 is not contextually convertible to 'bool'">;
def err_typecheck_ambiguous_condition : Error<
"conversion from %0 to %1 is ambiguous">;
+def err_typecheck_nonviable_condition : Error<
+ "no viable conversion from %0 to %1 is possible">;
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/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=89216&r1=89215&r2=89216&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Nov 18 12:26:29 2009
@@ -822,7 +822,7 @@
bool AllowConversionFunctions,
bool AllowExplicit, bool ForceRValue,
bool UserCast = false);
- bool DiagnoseAmbiguousUserDefinedConversion(Expr *From, QualType ToType);
+ bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
ImplicitConversionSequence::CompareKind
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=89216&r1=89215&r2=89216&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Nov 18 12:26:29 2009
@@ -1545,18 +1545,23 @@
}
bool
-Sema::DiagnoseAmbiguousUserDefinedConversion(Expr *From, QualType ToType) {
+Sema::DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType) {
ImplicitConversionSequence ICS;
OverloadCandidateSet CandidateSet;
OverloadingResult OvResult =
IsUserDefinedConversion(From, ToType, ICS.UserDefined,
CandidateSet, true, false, false);
- if (OvResult != OR_Ambiguous)
+ if (OvResult == OR_Ambiguous)
+ Diag(From->getSourceRange().getBegin(),
+ diag::err_typecheck_ambiguous_condition)
+ << From->getType() << ToType << From->getSourceRange();
+ else if (OvResult == OR_No_Viable_Function && !CandidateSet.empty())
+ Diag(From->getSourceRange().getBegin(),
+ diag::err_typecheck_nonviable_condition)
+ << From->getType() << ToType << From->getSourceRange();
+ else
return false;
- Diag(From->getSourceRange().getBegin(),
- diag::err_typecheck_ambiguous_condition)
- << From->getType() << ToType << From->getSourceRange();
- PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false);
+ PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false);
return true;
}
@@ -2072,7 +2077,7 @@
if (!PerformImplicitConversion(From, ToType, Flavor,
/*AllowExplicit=*/false, Elidable))
return false;
- if (!DiagnoseAmbiguousUserDefinedConversion(From, ToType))
+ if (!DiagnoseMultipleUserDefinedConversion(From, ToType))
return Diag(From->getSourceRange().getBegin(),
diag::err_typecheck_convert_incompatible)
<< ToType << From->getType() << Flavor << From->getSourceRange();
@@ -2192,7 +2197,7 @@
if (!PerformImplicitConversion(From, Context.BoolTy, ICS, "converting"))
return false;
- if (!DiagnoseAmbiguousUserDefinedConversion(From, Context.BoolTy))
+ if (!DiagnoseMultipleUserDefinedConversion(From, Context.BoolTy))
return Diag(From->getSourceRange().getBegin(),
diag::err_typecheck_bool_condition)
<< From->getType() << From->getSourceRange();
Modified: cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.qual/namespace.qual/p2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.qual/namespace.qual/p2.cpp?rev=89216&r1=89215&r2=89216&view=diff
==============================================================================
--- cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.qual/namespace.qual/p2.cpp (original)
+++ cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.qual/namespace.qual/p2.cpp Wed Nov 18 12:26:29 2009
@@ -31,7 +31,7 @@
}
namespace Numbers {
- struct Number {
+ struct Number { // expected-note 2 {{candidate}}
explicit Number(double d) : d(d) {}
double d;
};
@@ -57,9 +57,9 @@
int i = Ints::zero;
Numbers2::f(i);
- Numbers2::g(i); // expected-error {{incompatible type passing 'int'}}
+ Numbers2::g(i); // expected-error {{no viable conversion from 'int' to 'struct Numbers::Number' is possible}}
float f = Floats::zero;
Numbers2::f(f);
- Numbers2::g(f); // expected-error {{incompatible type passing 'float'}}
+ Numbers2::g(f); // expected-error {{no viable conversion from 'float' to 'struct Numbers::Number' is possible}}
}
Modified: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p1.cpp?rev=89216&r1=89215&r2=89216&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p1.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p1.cpp Wed Nov 18 12:26:29 2009
@@ -4,7 +4,7 @@
template <unsigned N> class test {};
-class foo {};
+class foo {}; // expected-note {{candidate}}
test<0> foo(foo); // expected-note {{candidate}}
namespace Test0 {
@@ -38,7 +38,7 @@
test<2> _1 = (foo)(a);
class Test0::foo b;
- test<2> _2 = (foo)(b); // expected-error {{incompatible type passing}}
+ test<2> _2 = (foo)(b); // expected-error {{no viable conversion from 'class Test0::foo' to 'class foo' is possible}}
}
}
}
Modified: cfe/trunk/test/SemaCXX/rval-references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/rval-references.cpp?rev=89216&r1=89215&r2=89216&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/rval-references.cpp (original)
+++ cfe/trunk/test/SemaCXX/rval-references.cpp Wed Nov 18 12:26:29 2009
@@ -65,9 +65,9 @@
// Test the return dance. This also tests IsReturnCopyElidable.
struct MoveOnly {
MoveOnly();
- MoveOnly(const MoveOnly&) = delete;
- MoveOnly(MoveOnly&&);
- MoveOnly(int&&);
+ MoveOnly(const MoveOnly&) = delete; // expected-note {{candidate function}}
+ MoveOnly(MoveOnly&&); // expected-note {{candidate function}}
+ MoveOnly(int&&); // expected-note {{candidate function}}
};
MoveOnly returning() {
@@ -87,5 +87,5 @@
else if (0) // Copy from reference can't be elided
return r; // expected-error {{incompatible type returning}}
else // Construction from different type can't be elided
- return i; // expected-error {{incompatible type returning}}
+ return i; // expected-error {{no viable conversion from 'int' to 'struct MoveOnly'}}
}
Modified: cfe/trunk/test/SemaTemplate/constructor-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/constructor-template.cpp?rev=89216&r1=89215&r2=89216&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/constructor-template.cpp (original)
+++ cfe/trunk/test/SemaTemplate/constructor-template.cpp Wed Nov 18 12:26:29 2009
@@ -53,7 +53,7 @@
struct X2 {
X2();
- X2(X2&);
+ X2(X2&); // expected-note {{candidate function}}
template<typename T> X2(T);
};
@@ -61,7 +61,7 @@
if (Cond)
return x2; // okay, uses copy constructor
- return X2(); // expected-error{{incompatible type}}
+ return X2(); // expected-error{{no viable conversion from 'struct X2' to 'struct X2' is possible}}
}
struct X3 {
@@ -73,12 +73,12 @@
struct X4 {
X4();
~X4();
- X4(X4&);
+ X4(X4&); // expected-note {{candidate function}}
template<typename T> X4(const T&, int = 17);
};
X4 test_X4(bool Cond, X4 x4) {
X4 a(x4, 17); // okay, constructor template
X4 b(x4); // okay, copy constructor
- return X4(); // expected-error{{incompatible type}}
+ return X4(); // expected-error{{no viable conversion}}
}
More information about the cfe-commits
mailing list