[cfe-commits] r82649 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/Sema.h lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExprCXX.cpp test/SemaCXX/decl-init-ref.cpp
Fariborz Jahanian
fjahanian at apple.com
Wed Sep 23 13:55:32 PDT 2009
Author: fjahanian
Date: Wed Sep 23 15:55:32 2009
New Revision: 82649
URL: http://llvm.org/viewvc/llvm-project?rev=82649&view=rev
Log:
This patch addresses a few issues related to 8.5.3 [dcl.init.ref]
It uses a recent API to find inherited conversion functions to do
the initializer to reference lvalue conversion (and removes a FIXME).
It issues the ambiguity diagnostics when multiple conversions are found.
WIP.
Added:
cfe/trunk/test/SemaCXX/decl-init-ref.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=82649&r1=82648&r2=82649&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 23 15:55:32 2009
@@ -476,6 +476,8 @@
// 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 "
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=82649&r1=82648&r2=82649&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Sep 23 15:55:32 2009
@@ -3469,6 +3469,11 @@
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);
bool PerformImplicitConversion(Expr *&From, QualType ToType,
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=82649&r1=82648&r2=82649&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Sep 23 15:55:32 2009
@@ -3478,7 +3478,7 @@
OverloadCandidateSet CandidateSet;
OverloadedFunctionDecl *Conversions
- = T2RecordDecl->getConversionFunctions();
+ = T2RecordDecl->getVisibleConversionFunctions();
for (OverloadedFunctionDecl::function_iterator Func
= Conversions->function_begin();
Func != Conversions->function_end(); ++Func) {
@@ -3489,7 +3489,7 @@
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() &&
@@ -3688,7 +3688,27 @@
}
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;
}
}
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=82649&r1=82648&r2=82649&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Sep 23 15:55:32 2009
@@ -996,6 +996,15 @@
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,
Added: cfe/trunk/test/SemaCXX/decl-init-ref.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/decl-init-ref.cpp?rev=82649&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/decl-init-ref.cpp (added)
+++ cfe/trunk/test/SemaCXX/decl-init-ref.cpp Wed Sep 23 15:55:32 2009
@@ -0,0 +1,24 @@
+// 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'}}
+}
More information about the cfe-commits
mailing list