[cfe-commits] r82566 - in /cfe/trunk/lib/Sema: Sema.h SemaOverload.cpp

Fariborz Jahanian fjahanian at apple.com
Tue Sep 22 13:24:30 PDT 2009


Author: fjahanian
Date: Tue Sep 22 15:24:30 2009
New Revision: 82566

URL: http://llvm.org/viewvc/llvm-project?rev=82566&view=rev
Log:
Code refactoring and cleanup.


Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=82566&r1=82565&r2=82566&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Sep 22 15:24:30 2009
@@ -791,6 +791,8 @@
                                OverloadCandidateSet& Conversions,
                                bool AllowConversionFunctions,
                                bool AllowExplicit, bool ForceRValue);
+  bool DiagnoseAmbiguousUserDefinedConversion(Expr *From, QualType ToType);
+                                              
 
   ImplicitConversionSequence::CompareKind
   CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1,

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=82566&r1=82565&r2=82566&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Sep 22 15:24:30 2009
@@ -1501,6 +1501,22 @@
 
   return OR_No_Viable_Function;
 }
+  
+bool
+Sema::DiagnoseAmbiguousUserDefinedConversion(Expr *From, QualType ToType) {
+  ImplicitConversionSequence ICS;
+  OverloadCandidateSet CandidateSet;
+  OverloadingResult OvResult = 
+    IsUserDefinedConversion(From, ToType, ICS.UserDefined,
+                            CandidateSet, true, false, false);
+  if (OvResult != OR_Ambiguous)
+    return false;
+  Diag(From->getSourceRange().getBegin(),
+       diag::err_typecheck_ambiguous_condition)
+  << From->getType() << ToType << From->getSourceRange();
+    PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false);
+  return true;  
+}
 
 /// CompareImplicitConversionSequences - Compare two implicit
 /// conversion sequences to determine whether one is better than the
@@ -1983,18 +1999,10 @@
   if (!PerformImplicitConversion(From, ToType, Flavor,
                                  /*AllowExplicit=*/false, Elidable))
     return false;
-  ImplicitConversionSequence ICS;
-  OverloadCandidateSet CandidateSet;
-  if (IsUserDefinedConversion(From, ToType, ICS.UserDefined,
-                              CandidateSet,
-                              true, false, false) != OR_Ambiguous)
+  if (!DiagnoseAmbiguousUserDefinedConversion(From, ToType))
     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;
 }
 
@@ -2109,19 +2117,12 @@
   ImplicitConversionSequence ICS = TryContextuallyConvertToBool(From);
   if (!PerformImplicitConversion(From, Context.BoolTy, ICS, "converting"))
     return false;
-
-    OverloadCandidateSet CandidateSet;
-    if (IsUserDefinedConversion(From, Context.BoolTy, ICS.UserDefined,
-                            CandidateSet,
-                            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_condition)
-          << From->getType() << Context.BoolTy << From->getSourceRange();
-    PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false);
-    return true;
+  
+  if (!DiagnoseAmbiguousUserDefinedConversion(From, Context.BoolTy))
+    return  Diag(From->getSourceRange().getBegin(),
+                 diag::err_typecheck_bool_condition)
+                  << From->getType() << From->getSourceRange();
+  return true;
 }
 
 /// AddOverloadCandidate - Adds the given function to the set of





More information about the cfe-commits mailing list