From: Fariborz Jahanian Date: Wed, 14 Oct 2009 00:52:43 +0000 (+0000) Subject: Handle ambiguity of reference initialization. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d9290cb5ad9eae8d10487cea5392331cf6a47142;p=clang Handle ambiguity of reference initialization. Removes a FIXME. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84068 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 9e50ca65fb..5efab50ae3 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -793,6 +793,8 @@ def err_ovl_builtin_unary_candidate : Note< 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">; +def err_ref_init_ambiguous : Error< + "reference initialization of type %0 with initializer of type %1 is ambiguous">; def err_ovl_deleted_init : Error< "call to %select{unavailable|deleted}0 constructor of %1">; def err_ovl_ambiguous_oper : Error< diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 075f756bb5..acb2a67770 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -3731,7 +3731,16 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, break; case OR_Ambiguous: - assert(false && "Ambiguous reference binding conversions not implemented."); + if (ICS) { + for (OverloadCandidateSet::iterator Cand = CandidateSet.begin(); + Cand != CandidateSet.end(); ++Cand) + if (Cand->Viable) + ICS->ConversionFunctionSet.push_back(Cand->Function); + break; + } + Diag(DeclLoc, diag::err_ref_init_ambiguous) << DeclType << Init->getType() + << Init->getSourceRange(); + PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/true); return true; case OR_No_Viable_Function: diff --git a/test/SemaCXX/ref-init-ambiguous.cpp b/test/SemaCXX/ref-init-ambiguous.cpp new file mode 100644 index 0000000000..dda1ead7b6 --- /dev/null +++ b/test/SemaCXX/ref-init-ambiguous.cpp @@ -0,0 +1,28 @@ +// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x + +enum E2 { }; + +struct A { + operator E2&(); // expected-note 3 {{candidate function}} +}; + +struct B { + operator E2&(); // expected-note 3 {{candidate function}} +}; + +struct C : B, A { +}; + +void test(C c) { + const E2 &e2 = c; // expected-error {{reference initialization of type 'enum E2 const &' with initializer of type 'struct C' is ambiguous}} +} + +void foo(const E2 &); + +const E2 & re(C c) { + foo(c); // expected-error {{reference initialization of type 'enum E2 const &' with initializer of type 'struct C' is ambiguous}} + + return c; // expected-error {{reference initialization of type 'enum E2 const &' with initializer of type 'struct C' is ambiguous}} +} + +