// C++ initialization
def err_lvalue_to_rvalue_ref : Error<"rvalue reference cannot bind to lvalue">;
+def err_lvalue_to_rvalue_ambig_ref : Error<"rvalue reference cannot bind to lvalue "
+ "due to multiple conversion functions">;
// FIXME: passing in an English string as %1!
def err_not_reference_to_const_init : Error<
"non-const lvalue reference to type %0 cannot be initialized "
const char *Flavor,
bool AllowExplicit = false,
bool Elidable = false);
+ bool PerformImplicitConversion(Expr *&From, QualType ToType,
+ const char *Flavor,
+ bool AllowExplicit,
+ bool Elidable,
+ ImplicitConversionSequence& ICS);
bool PerformImplicitConversion(Expr *&From, QualType ToType,
const ImplicitConversionSequence& ICS,
const char *Flavor);
OverloadCandidateSet CandidateSet;
OverloadedFunctionDecl *Conversions
- = T2RecordDecl->getConversionFunctions();
+ = T2RecordDecl->getVisibleConversionFunctions();
for (OverloadedFunctionDecl::function_iterator Func
= Conversions->function_begin();
Func != Conversions->function_end(); ++Func) {
Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl());
else
Conv = cast<CXXConversionDecl>(*Func);
-
+
// If the conversion function doesn't return a reference type,
// it can't be considered for this conversion.
if (Conv->getConversionType()->isLValueReferenceType() &&
}
return ICS->ConversionKind == ImplicitConversionSequence::BadConversion;
} else {
- return PerformImplicitConversion(Init, T1, "initializing");
+ ImplicitConversionSequence Conversions;
+ bool badConversion = PerformImplicitConversion(Init, T1, "initializing",
+ false, false,
+ Conversions);
+ if (badConversion) {
+ if ((Conversions.ConversionKind ==
+ ImplicitConversionSequence::BadConversion)
+ && Conversions.ConversionFunctionSet.size() > 0) {
+ Diag(Init->getSourceRange().getBegin(),
+ diag::err_lvalue_to_rvalue_ambig_ref) << Init->getSourceRange();
+ for (int j = Conversions.ConversionFunctionSet.size()-1;
+ j >= 0; j--) {
+ FunctionDecl *Func = Conversions.ConversionFunctionSet[j];
+ Diag(Func->getLocation(), diag::err_ovl_candidate);
+ }
+ }
+ else
+ Diag(Init->getSourceRange().getBegin(), diag::err_lvalue_to_rvalue_ref)
+ << Init->getSourceRange();
+ }
+ return badConversion;
}
}
const char *Flavor, bool AllowExplicit,
bool Elidable) {
ImplicitConversionSequence ICS;
+ return PerformImplicitConversion(From, ToType, Flavor, AllowExplicit,
+ Elidable, ICS);
+}
+
+bool
+Sema::PerformImplicitConversion(Expr *&From, QualType ToType,
+ const char *Flavor, bool AllowExplicit,
+ bool Elidable,
+ ImplicitConversionSequence& ICS) {
ICS.ConversionKind = ImplicitConversionSequence::BadConversion;
if (Elidable && getLangOptions().CPlusPlus0x) {
ICS = TryImplicitConversion(From, ToType,
--- /dev/null
+// RUN: clang-cc -fsyntax-only -verify -std=c++0x %s
+
+struct A {}; // expected-note {{candidate function}}
+
+struct BASE {
+ operator A(); // expected-note {{candidate function}}
+};
+
+struct BASE1 {
+ operator A(); // expected-note {{candidate function}}
+};
+
+class B : public BASE , public BASE1
+{
+ public:
+ B();
+} b;
+
+extern B f();
+
+int main() {
+ const A& rca = f(); // expected-error {{rvalue reference cannot bind to lvalue due to multiple conversion functions}}
+ A& ra = f(); // expected-error {{non-const lvalue reference to type 'struct A' cannot be initialized with a temporary of type 'class B'}}
+}