zcov: / lib/Sema/SemaOverload.cpp


Files: 1 Branches Taken: 78.4% 1852 / 2363
Generated: 2010-02-10 01:31 Branches Executed: 93.1% 2201 / 2363
Line Coverage: 88.4% 2189 / 2475


Programs: 2 Runs 3018


       1                 : //===--- SemaOverload.cpp - C++ Overloading ---------------------*- C++ -*-===//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : //
      10                 : // This file provides Sema routines for C++ overloading.
      11                 : //
      12                 : //===----------------------------------------------------------------------===//
      13                 : 
      14                 : #include "Sema.h"
      15                 : #include "Lookup.h"
      16                 : #include "SemaInit.h"
      17                 : #include "clang/Basic/Diagnostic.h"
      18                 : #include "clang/Lex/Preprocessor.h"
      19                 : #include "clang/AST/ASTContext.h"
      20                 : #include "clang/AST/CXXInheritance.h"
      21                 : #include "clang/AST/Expr.h"
      22                 : #include "clang/AST/ExprCXX.h"
      23                 : #include "clang/AST/TypeOrdering.h"
      24                 : #include "clang/Basic/PartialDiagnostic.h"
      25                 : #include "llvm/ADT/SmallPtrSet.h"
      26                 : #include "llvm/ADT/STLExtras.h"
      27                 : #include <algorithm>
      28                 : 
      29                 : namespace clang {
      30                 : 
      31                 : /// GetConversionCategory - Retrieve the implicit conversion
      32                 : /// category corresponding to the given implicit conversion kind.
      33                 : ImplicitConversionCategory
      34                0: GetConversionCategory(ImplicitConversionKind Kind) {
      35                 :   static const ImplicitConversionCategory
      36                 :     Category[(int)ICK_Num_Conversion_Kinds] = {
      37                 :     ICC_Identity,
      38                 :     ICC_Lvalue_Transformation,
      39                 :     ICC_Lvalue_Transformation,
      40                 :     ICC_Lvalue_Transformation,
      41                 :     ICC_Identity,
      42                 :     ICC_Qualification_Adjustment,
      43                 :     ICC_Promotion,
      44                 :     ICC_Promotion,
      45                 :     ICC_Promotion,
      46                 :     ICC_Conversion,
      47                 :     ICC_Conversion,
      48                 :     ICC_Conversion,
      49                 :     ICC_Conversion,
      50                 :     ICC_Conversion,
      51                 :     ICC_Conversion,
      52                 :     ICC_Conversion,
      53                 :     ICC_Conversion,
      54                 :     ICC_Conversion,
      55                 :     ICC_Conversion
      56                 :   };
      57                0:   return Category[(int)Kind];
      58                 : }
      59                 : 
      60                 : /// GetConversionRank - Retrieve the implicit conversion rank
      61                 : /// corresponding to the given implicit conversion kind.
      62           215403: ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind) {
      63                 :   static const ImplicitConversionRank
      64                 :     Rank[(int)ICK_Num_Conversion_Kinds] = {
      65                 :     ICR_Exact_Match,
      66                 :     ICR_Exact_Match,
      67                 :     ICR_Exact_Match,
      68                 :     ICR_Exact_Match,
      69                 :     ICR_Exact_Match,
      70                 :     ICR_Exact_Match,
      71                 :     ICR_Promotion,
      72                 :     ICR_Promotion,
      73                 :     ICR_Promotion,
      74                 :     ICR_Conversion,
      75                 :     ICR_Conversion,
      76                 :     ICR_Conversion,
      77                 :     ICR_Conversion,
      78                 :     ICR_Conversion,
      79                 :     ICR_Conversion,
      80                 :     ICR_Conversion,
      81                 :     ICR_Conversion,
      82                 :     ICR_Conversion,
      83                 :     ICR_Conversion
      84                 :   };
      85           215403:   return Rank[(int)Kind];
      86                 : }
      87                 : 
      88                 : /// GetImplicitConversionName - Return the name of this kind of
      89                 : /// implicit conversion.
      90                0: const char* GetImplicitConversionName(ImplicitConversionKind Kind) {
      91                 :   static const char* const Name[(int)ICK_Num_Conversion_Kinds] = {
      92                 :     "No conversion",
      93                 :     "Lvalue-to-rvalue",
      94                 :     "Array-to-pointer",
      95                 :     "Function-to-pointer",
      96                 :     "Noreturn adjustment",
      97                 :     "Qualification",
      98                 :     "Integral promotion",
      99                 :     "Floating point promotion",
     100                 :     "Complex promotion",
     101                 :     "Integral conversion",
     102                 :     "Floating conversion",
     103                 :     "Complex conversion",
     104                 :     "Floating-integral conversion",
     105                 :     "Complex-real conversion",
     106                 :     "Pointer conversion",
     107                 :     "Pointer-to-member conversion",
     108                 :     "Boolean conversion",
     109                 :     "Compatible-types conversion",
     110                 :     "Derived-to-base conversion"
     111                 :   };
     112                0:   return Name[Kind];
     113                 : }
     114                 : 
     115                 : /// StandardConversionSequence - Set the standard conversion
     116                 : /// sequence to the identity conversion.
     117            68761: void StandardConversionSequence::setAsIdentityConversion() {
     118            68761:   First = ICK_Identity;
     119            68761:   Second = ICK_Identity;
     120            68761:   Third = ICK_Identity;
     121            68761:   Deprecated = false;
     122            68761:   ReferenceBinding = false;
     123            68761:   DirectBinding = false;
     124            68761:   RRefBinding = false;
     125            68761:   CopyConstructor = 0;
     126            68761: }
     127                 : 
     128                 : /// getRank - Retrieve the rank of this standard conversion sequence
     129                 : /// (C++ 13.3.3.1.1p3). The rank is the largest rank of each of the
     130                 : /// implicit conversions.
     131            56862: ImplicitConversionRank StandardConversionSequence::getRank() const {
     132            56862:   ImplicitConversionRank Rank = ICR_Exact_Match;
                        0: branch 1 not taken
                    56862: branch 2 taken
     133            56862:   if  (GetConversionRank(First) > Rank)
     134                0:     Rank = GetConversionRank(First);
                    44817: branch 1 taken
                    12045: branch 2 taken
     135            56862:   if  (GetConversionRank(Second) > Rank)
     136            44817:     Rank = GetConversionRank(Second);
                        0: branch 1 not taken
                    56862: branch 2 taken
     137            56862:   if  (GetConversionRank(Third) > Rank)
     138                0:     Rank = GetConversionRank(Third);
     139            56862:   return Rank;
     140                 : }
     141                 : 
     142                 : /// isPointerConversionToBool - Determines whether this conversion is
     143                 : /// a conversion of a pointer or pointer-to-member to bool. This is
     144                 : /// used as part of the ranking of standard conversion sequences
     145                 : /// (C++ 13.3.3.2p4).
     146            16734: bool StandardConversionSequence::isPointerConversionToBool() const {
     147                 :   // Note that FromType has not necessarily been transformed by the
     148                 :   // array-to-pointer or function-to-pointer implicit conversions, so
     149                 :   // check for their presence as well as checking whether FromType is
     150                 :   // a pointer.
                        8: branch 3 taken
                    16726: branch 4 taken
                        4: branch 8 taken
                        4: branch 9 taken
                        4: branch 13 taken
                        0: branch 14 not taken
                        4: branch 15 taken
                        0: branch 16 not taken
                        0: branch 17 not taken
                        4: branch 18 taken
                        4: branch 19 taken
                    16730: branch 20 taken
     151            16734:   if (getToType(1)->isBooleanType() &&
     152                 :       (getFromType()->isPointerType() || getFromType()->isBlockPointerType() ||
     153                 :        First == ICK_Array_To_Pointer || First == ICK_Function_To_Pointer))
     154                4:     return true;
     155                 : 
     156            16730:   return false;
     157                 : }
     158                 : 
     159                 : /// isPointerConversionToVoidPointer - Determines whether this
     160                 : /// conversion is a conversion of a pointer to a void pointer. This is
     161                 : /// used as part of the ranking of standard conversion sequences (C++
     162                 : /// 13.3.3.2p4).
     163                 : bool
     164                 : StandardConversionSequence::
     165            16728: isPointerConversionToVoidPointer(ASTContext& Context) const {
     166            16728:   QualType FromType = getFromType();
     167            16728:   QualType ToType = getToType(1);
     168                 : 
     169                 :   // Note that FromType has not necessarily been transformed by the
     170                 :   // array-to-pointer implicit conversion, so check for its presence
     171                 :   // and redo the conversion to get a pointer.
                        0: branch 0 not taken
                    16728: branch 1 taken
     172            16728:   if (First == ICK_Array_To_Pointer)
     173                0:     FromType = Context.getArrayDecayedType(FromType);
     174                 : 
                       88: branch 0 taken
                    16640: branch 1 taken
                       28: branch 4 taken
                       60: branch 5 taken
                       28: branch 6 taken
                    16700: branch 7 taken
     175            16728:   if (Second == ICK_Pointer_Conversion && FromType->isPointerType())
                       28: branch 2 taken
                        0: branch 3 not taken
     176               28:     if (const PointerType* ToPtrType = ToType->getAs<PointerType>())
     177               28:       return ToPtrType->getPointeeType()->isVoidType();
     178                 : 
     179            16700:   return false;
     180                 : }
     181                 : 
     182                 : /// DebugPrint - Print this standard conversion sequence to standard
     183                 : /// error. Useful for debugging overloading issues.
     184                0: void StandardConversionSequence::DebugPrint() const {
     185                0:   llvm::raw_ostream &OS = llvm::errs();
     186                0:   bool PrintedSomething = false;
                        0: branch 0 not taken
                        0: branch 1 not taken
     187                0:   if (First != ICK_Identity) {
     188                0:     OS << GetImplicitConversionName(First);
     189                0:     PrintedSomething = true;
     190                 :   }
     191                 : 
                        0: branch 0 not taken
                        0: branch 1 not taken
     192                0:   if (Second != ICK_Identity) {
                        0: branch 0 not taken
                        0: branch 1 not taken
     193                0:     if (PrintedSomething) {
     194                0:       OS << " -> ";
     195                 :     }
     196                0:     OS << GetImplicitConversionName(Second);
     197                 : 
                        0: branch 0 not taken
                        0: branch 1 not taken
     198                0:     if (CopyConstructor) {
     199                0:       OS << " (by copy constructor)";
                        0: branch 0 not taken
                        0: branch 1 not taken
     200                0:     } else if (DirectBinding) {
     201                0:       OS << " (direct reference binding)";
                        0: branch 0 not taken
                        0: branch 1 not taken
     202                0:     } else if (ReferenceBinding) {
     203                0:       OS << " (reference binding)";
     204                 :     }
     205                0:     PrintedSomething = true;
     206                 :   }
     207                 : 
                        0: branch 0 not taken
                        0: branch 1 not taken
     208                0:   if (Third != ICK_Identity) {
                        0: branch 0 not taken
                        0: branch 1 not taken
     209                0:     if (PrintedSomething) {
     210                0:       OS << " -> ";
     211                 :     }
     212                0:     OS << GetImplicitConversionName(Third);
     213                0:     PrintedSomething = true;
     214                 :   }
     215                 : 
                        0: branch 0 not taken
                        0: branch 1 not taken
     216                0:   if (!PrintedSomething) {
     217                0:     OS << "No conversions required";
     218                 :   }
     219                0: }
     220                 : 
     221                 : /// DebugPrint - Print this user-defined conversion sequence to standard
     222                 : /// error. Useful for debugging overloading issues.
     223                0: void UserDefinedConversionSequence::DebugPrint() const {
     224                0:   llvm::raw_ostream &OS = llvm::errs();
                        0: branch 0 not taken
                        0: branch 1 not taken
                        0: branch 2 not taken
                        0: branch 3 not taken
                        0: branch 4 not taken
                        0: branch 5 not taken
     225                0:   if (Before.First || Before.Second || Before.Third) {
     226                0:     Before.DebugPrint();
     227                0:     OS << " -> ";
     228                 :   }
     229                0:   OS << "'" << ConversionFunction->getNameAsString() << "'";
                        0: branch 0 not taken
                        0: branch 1 not taken
                        0: branch 2 not taken
                        0: branch 3 not taken
                        0: branch 4 not taken
                        0: branch 5 not taken
     230                0:   if (After.First || After.Second || After.Third) {
     231                0:     OS << " -> ";
     232                0:     After.DebugPrint();
     233                 :   }
     234                0: }
     235                 : 
     236                 : /// DebugPrint - Print this implicit conversion sequence to standard
     237                 : /// error. Useful for debugging overloading issues.
     238                0: void ImplicitConversionSequence::DebugPrint() const {
     239                0:   llvm::raw_ostream &OS = llvm::errs();
                        0: branch 0 not taken
                        0: branch 1 not taken
                        0: branch 2 not taken
                        0: branch 3 not taken
                        0: branch 4 not taken
                        0: branch 5 not taken
     240                0:   switch (ConversionKind) {
     241                 :   case StandardConversion:
     242                0:     OS << "Standard conversion: ";
     243                0:     Standard.DebugPrint();
     244                0:     break;
     245                 :   case UserDefinedConversion:
     246                0:     OS << "User-defined conversion: ";
     247                0:     UserDefined.DebugPrint();
     248                0:     break;
     249                 :   case EllipsisConversion:
     250                0:     OS << "Ellipsis conversion";
     251                0:     break;
     252                 :   case AmbiguousConversion:
     253                0:     OS << "Ambiguous conversion";
     254                0:     break;
     255                 :   case BadConversion:
     256                0:     OS << "Bad conversion";
     257                 :     break;
     258                 :   }
     259                 : 
     260                0:   OS << "\n";
     261                0: }
     262                 : 
     263               26: void AmbiguousConversionSequence::construct() {
                       26: branch 2 taken
                        0: branch 3 not taken
     264               26:   new (&conversions()) ConversionSet();
     265               26: }
     266                 : 
     267               58: void AmbiguousConversionSequence::destruct() {
     268               58:   conversions().~ConversionSet();
     269               58: }
     270                 : 
     271                 : void
     272               32: AmbiguousConversionSequence::copyFrom(const AmbiguousConversionSequence &O) {
     273               32:   FromTypePtr = O.FromTypePtr;
     274               32:   ToTypePtr = O.ToTypePtr;
                       32: branch 3 taken
                        0: branch 4 not taken
     275               32:   new (&conversions()) ConversionSet(O.conversions());
     276               32: }
     277                 : 
     278                 : 
     279                 : // IsOverload - Determine whether the given New declaration is an
     280                 : // overload of the declarations in Old. This routine returns false if
     281                 : // New and Old cannot be overloaded, e.g., if New has the same
     282                 : // signature as some function in Old (C++ 1.3.10) or if the Old
     283                 : // declarations aren't functions (or function templates) at all. When
     284                 : // it does return false, MatchedDecl will point to the decl that New
     285                 : // cannot be overloaded with.  This decl may be a UsingShadowDecl on
     286                 : // top of the underlying declaration.
     287                 : //
     288                 : // Example: Given the following input:
     289                 : //
     290                 : //   void f(int, float); // #1
     291                 : //   void f(int, int); // #2
     292                 : //   int f(int, int); // #3
     293                 : //
     294                 : // When we process #1, there is no previous declaration of "f",
     295                 : // so IsOverload will not be used.
     296                 : //
     297                 : // When we process #2, Old contains only the FunctionDecl for #1.  By
     298                 : // comparing the parameter types, we see that #1 and #2 are overloaded
     299                 : // (since they have different signatures), so this routine returns
     300                 : // false; MatchedDecl is unchanged.
     301                 : //
     302                 : // When we process #3, Old is an overload set containing #1 and #2. We
     303                 : // compare the signatures of #3 to #1 (they're overloaded, so we do
     304                 : // nothing) and then #3 to #2. Since the signatures of #3 and #2 are
     305                 : // identical (return types of functions are not part of the
     306                 : // signature), IsOverload returns false and MatchedDecl will be set to
     307                 : // point to the FunctionDecl for #2.
     308                 : Sema::OverloadKind
     309                 : Sema::CheckOverload(FunctionDecl *New, const LookupResult &Old,
     310             1132:                     NamedDecl *&Match) {
                     1669: branch 4 taken
                      625: branch 5 taken
     311             2294:   for (LookupResult::iterator I = Old.begin(), E = Old.end();
     312                 :          I != E; ++I) {
     313             1669:     NamedDecl *OldD = (*I)->getUnderlyingDecl();
                      158: branch 1 taken
                     1511: branch 2 taken
     314             1669:     if (FunctionTemplateDecl *OldT = dyn_cast<FunctionTemplateDecl>(OldD)) {
                       35: branch 2 taken
                      123: branch 3 taken
     315              158:       if (!IsOverload(New, OldT->getTemplatedDecl())) {
     316               35:         Match = *I;
     317               35:         return Ovl_Match;
     318                 :       }
                     1502: branch 1 taken
                        9: branch 2 taken
     319             1511:     } else if (FunctionDecl *OldF = dyn_cast<FunctionDecl>(OldD)) {
                      469: branch 1 taken
                     1033: branch 2 taken
     320             1502:       if (!IsOverload(New, OldF)) {
     321              469:         Match = *I;
     322              469:         return Ovl_Match;
     323                 :       }
                        7: branch 1 taken
                        2: branch 2 taken
                        0: branch 4 not taken
                        7: branch 5 taken
                        2: branch 6 taken
                        7: branch 7 taken
     324                9:     } else if (isa<UsingDecl>(OldD) || isa<TagDecl>(OldD)) {
     325                 :       // We can overload with these, which can show up when doing
     326                 :       // redeclaration checks for UsingDecls.
                        0: branch 1 not taken
                        2: branch 2 taken
     327                2:       assert(Old.getLookupKind() == LookupUsingDeclName);
                        3: branch 1 taken
                        4: branch 2 taken
     328                7:     } else if (isa<UnresolvedUsingValueDecl>(OldD)) {
     329                 :       // Optimistically assume that an unresolved using decl will
     330                 :       // overload; if it doesn't, we'll have to diagnose during
     331                 :       // template instantiation.
     332                 :     } else {
     333                 :       // (C++ 13p1):
     334                 :       //   Only function declarations can be overloaded; object and type
     335                 :       //   declarations cannot be overloaded.
     336                3:       Match = *I;
     337                3:       return Ovl_NonFunction;
     338                 :     }
     339                 :   }
     340                 : 
     341              625:   return Ovl_Overload;
     342                 : }
     343                 : 
     344             1827: bool Sema::IsOverload(FunctionDecl *New, FunctionDecl *Old) {
     345             1827:   FunctionTemplateDecl *OldTemplate = Old->getDescribedFunctionTemplate();
     346             1827:   FunctionTemplateDecl *NewTemplate = New->getDescribedFunctionTemplate();
     347                 : 
     348                 :   // C++ [temp.fct]p2:
     349                 :   //   A function template can be overloaded with other function templates
     350                 :   //   and with normal (non-template) functions.
                       72: branch 0 taken
                     1755: branch 1 taken
     351             1827:   if ((OldTemplate == 0) != (NewTemplate == 0))
     352               72:     return true;
     353                 : 
     354                 :   // Is the function New an overload of the function Old?
     355             1755:   QualType OldQType = Context.getCanonicalType(Old->getType());
     356             1755:   QualType NewQType = Context.getCanonicalType(New->getType());
     357                 : 
     358                 :   // Compare the signatures (C++ 1.3.10) of the two functions to
     359                 :   // determine whether they are overloads. If we find any mismatch
     360                 :   // in the signature, they are overloads.
     361                 : 
     362                 :   // If either of these functions is a K&R-style function (no
     363                 :   // prototype), then we consider them to have matching signatures.
                     1755: branch 2 taken
                        0: branch 3 not taken
                        0: branch 6 not taken
                     1755: branch 7 taken
                        0: branch 8 not taken
                     1755: branch 9 taken
     364             1755:   if (isa<FunctionNoProtoType>(OldQType.getTypePtr()) ||
     365                 :       isa<FunctionNoProtoType>(NewQType.getTypePtr()))
     366                0:     return false;
     367                 : 
     368             1755:   FunctionProtoType* OldType = cast<FunctionProtoType>(OldQType);
     369             1755:   FunctionProtoType* NewType = cast<FunctionProtoType>(NewQType);
     370                 : 
     371                 :   // The signature of a function includes the types of its
     372                 :   // parameters (C++ 1.3.10), which includes the presence or absence
     373                 :   // of the ellipsis; see C++ DR 357).
                     1145: branch 1 taken
                      610: branch 2 taken
                      776: branch 5 taken
                      369: branch 6 taken
                      772: branch 9 taken
                        4: branch 10 taken
                      668: branch 15 taken
                      104: branch 16 taken
                     1041: branch 17 taken
                      714: branch 18 taken
     374             1755:   if (OldQType != NewQType &&
     375                 :       (OldType->getNumArgs() != NewType->getNumArgs() ||
     376                 :        OldType->isVariadic() != NewType->isVariadic() ||
     377                 :        !std::equal(OldType->arg_type_begin(), OldType->arg_type_end(),
     378                 :                    NewType->arg_type_begin())))
     379             1041:     return true;
     380                 : 
     381                 :   // C++ [temp.over.link]p4:
     382                 :   //   The signature of a function template consists of its function
     383                 :   //   signature, its return type and its template parameter list. The names
     384                 :   //   of the template parameters are significant only for establishing the
     385                 :   //   relationship between the template parameters and the rest of the
     386                 :   //   signature.
     387                 :   //
     388                 :   // We check the return type and template parameter lists for function
     389                 :   // templates first; the remaining checks follow.
                       54: branch 0 taken
                      660: branch 1 taken
                       43: branch 6 taken
                       11: branch 7 taken
                        7: branch 11 taken
                       36: branch 12 taken
                       18: branch 13 taken
                      696: branch 14 taken
     390              714:   if (NewTemplate &&
     391                 :       (!TemplateParameterListsAreEqual(NewTemplate->getTemplateParameters(),
     392                 :                                        OldTemplate->getTemplateParameters(),
     393                 :                                        false, TPL_TemplateMatch) ||
     394                 :        OldType->getResultType() != NewType->getResultType()))
     395               18:     return true;
     396                 : 
     397                 :   // If the function is a class member, its signature includes the
     398                 :   // cv-qualifiers (if any) on the function itself.
     399                 :   //
     400                 :   // As part of this, also check whether one of the member functions
     401                 :   // is static, in which case they are not overloads (C++
     402                 :   // 13.1p2). While not part of the definition of the signature,
     403                 :   // this check is important to determine whether these functions
     404                 :   // can be overloaded.
     405              696:   CXXMethodDecl* OldMethod = dyn_cast<CXXMethodDecl>(Old);
     406              696:   CXXMethodDecl* NewMethod = dyn_cast<CXXMethodDecl>(New);
                      552: branch 0 taken
                      144: branch 1 taken
                      552: branch 2 taken
                        0: branch 3 not taken
                      544: branch 5 taken
                        8: branch 6 taken
                      543: branch 8 taken
                        1: branch 9 taken
                       29: branch 12 taken
                      514: branch 13 taken
                       29: branch 14 taken
                      667: branch 15 taken
     407              696:   if (OldMethod && NewMethod &&
     408                 :       !OldMethod->isStatic() && !NewMethod->isStatic() &&
     409                 :       OldMethod->getTypeQualifiers() != NewMethod->getTypeQualifiers())
     410               29:     return true;
     411                 :   
     412                 :   // The signatures match; this is not an overload.
     413              667:   return false;
     414                 : }
     415                 : 
     416                 : /// TryImplicitConversion - Attempt to perform an implicit conversion
     417                 : /// from the given expression (Expr) to the given type (ToType). This
     418                 : /// function returns an implicit conversion sequence that can be used
     419                 : /// to perform the initialization. Given
     420                 : ///
     421                 : ///   void f(float f);
     422                 : ///   void g(int i) { f(i); }
     423                 : ///
     424                 : /// this routine would produce an implicit conversion sequence to
     425                 : /// describe the initialization of f from i, which will be a standard
     426                 : /// conversion sequence containing an lvalue-to-rvalue conversion (C++
     427                 : /// 4.1) followed by a floating-integral conversion (C++ 4.9).
     428                 : //
     429                 : /// Note that this routine only determines how the conversion can be
     430                 : /// performed; it does not actually perform the conversion. As such,
     431                 : /// it will not produce any diagnostics if no conversion is available,
     432                 : /// but will instead return an implicit conversion sequence of kind
     433                 : /// "BadConversion".
     434                 : ///
     435                 : /// If @p SuppressUserConversions, then user-defined conversions are
     436                 : /// not permitted.
     437                 : /// If @p AllowExplicit, then explicit user-defined conversions are
     438                 : /// permitted.
     439                 : /// If @p ForceRValue, then overloading is performed as if From was an rvalue,
     440                 : /// no matter its actual lvalueness.
     441                 : /// If @p UserCast, the implicit conversion is being done for a user-specified
     442                 : /// cast.
     443                 : ImplicitConversionSequence
     444                 : Sema::TryImplicitConversion(Expr* From, QualType ToType,
     445                 :                             bool SuppressUserConversions,
     446                 :                             bool AllowExplicit, bool ForceRValue,
     447                 :                             bool InOverloadResolution,
     448            47691:                             bool UserCast) {
     449            47691:   ImplicitConversionSequence ICS;
                    30880: branch 1 taken
                    16811: branch 2 taken
     450            47691:   if (IsStandardConversion(From, ToType, InOverloadResolution, ICS.Standard)) {
     451            30880:     ICS.setStandard();
     452            30880:     return ICS;
     453                 :   }
     454                 : 
                       19: branch 1 taken
                    16792: branch 2 taken
     455            16811:   if (!getLangOptions().CPlusPlus) {
     456               19:     ICS.setBad();
     457               19:     ICS.Bad.init(BadConversionSequence::no_conversion, From, ToType);
     458               19:     return ICS;
     459                 :   }
     460                 : 
     461            16792:   OverloadCandidateSet Conversions(From->getExprLoc());
     462                 :   OverloadingResult UserDefResult
     463                 :     = IsUserDefinedConversion(From, ToType, ICS.UserDefined, Conversions,
     464                 :                               !SuppressUserConversions, AllowExplicit,
     465            16792:                               ForceRValue, UserCast);
     466                 : 
                     5259: branch 0 taken
                    11533: branch 1 taken
     467            16792:   if (UserDefResult == OR_Success) {
     468             5259:     ICS.setUserDefined();
     469                 :     // C++ [over.ics.user]p4:
     470                 :     //   A conversion of an expression of class type to the same class
     471                 :     //   type is given Exact Match rank, and a conversion of an
     472                 :     //   expression of class type to a base class of that type is
     473                 :     //   given Conversion rank, in spite of the fact that a copy
     474                 :     //   constructor (i.e., a user-defined conversion function) is
     475                 :     //   called for those cases.
                      566: branch 0 taken
                     4693: branch 1 taken
     476             5259:     if (CXXConstructorDecl *Constructor
     477             5259:           = dyn_cast<CXXConstructorDecl>(ICS.UserDefined.ConversionFunction)) {
     478                 :       QualType FromCanon
     479              566:         = Context.getCanonicalType(From->getType().getUnqualifiedType());
     480              566:       QualType ToCanon = Context.getCanonicalType(ToType).getUnqualifiedType();
                      343: branch 1 taken
                      223: branch 2 taken
                       49: branch 4 taken
                      294: branch 5 taken
                       49: branch 7 taken
                        0: branch 8 not taken
                      343: branch 9 taken
                      223: branch 10 taken
     481              566:       if (Constructor->isCopyConstructor() &&
     482                 :           (FromCanon == ToCanon || IsDerivedFrom(FromCanon, ToCanon))) {
     483                 :         // Turn this into a "standard" conversion sequence, so that it
     484                 :         // gets ranked with standard conversion sequences.
     485              343:         ICS.setStandard();
     486              343:         ICS.Standard.setAsIdentityConversion();
     487              343:         ICS.Standard.setFromType(From->getType());
     488              343:         ICS.Standard.setAllToTypes(ToType);
     489              343:         ICS.Standard.CopyConstructor = Constructor;
                       49: branch 1 taken
                      294: branch 2 taken
     490              343:         if (ToCanon != FromCanon)
     491               49:           ICS.Standard.Second = ICK_Derived_To_Base;
     492                 :       }
     493                 :     }
     494                 : 
     495                 :     // C++ [over.best.ics]p4:
     496                 :     //   However, when considering the argument of a user-defined
     497                 :     //   conversion function that is a candidate by 13.3.1.3 when
     498                 :     //   invoked for the copying of the temporary in the second step
     499                 :     //   of a class copy-initialization, or by 13.3.1.4, 13.3.1.5, or
     500                 :     //   13.3.1.6 in all cases, only standard conversion sequences and
     501                 :     //   ellipsis conversion sequences are allowed.
                      169: branch 0 taken
                     5090: branch 1 taken
                       14: branch 3 taken
                      155: branch 4 taken
                       14: branch 5 taken
                     5245: branch 6 taken
     502             5259:     if (SuppressUserConversions && ICS.isUserDefined()) {
     503               14:       ICS.setBad();
     504               14:       ICS.Bad.init(BadConversionSequence::suppressed_user, From, ToType);
     505                 :     }
                       26: branch 0 taken
                    11507: branch 1 taken
                       25: branch 2 taken
                        1: branch 3 taken
     506            11558:   } else if (UserDefResult == OR_Ambiguous && !SuppressUserConversions) {
     507               25:     ICS.setAmbiguous();
     508               25:     ICS.Ambiguous.setFromType(From->getType());
     509               25:     ICS.Ambiguous.setToType(ToType);
                       60: branch 2 taken
                       25: branch 3 taken
     510               85:     for (OverloadCandidateSet::iterator Cand = Conversions.begin();
     511                 :          Cand != Conversions.end(); ++Cand)
                       50: branch 0 taken
                       10: branch 1 taken
     512               60:       if (Cand->Viable)
     513               50:         ICS.Ambiguous.addConversion(Cand->Function);
     514                 :   } else {
     515            11508:     ICS.setBad();
     516            11508:     ICS.Bad.init(BadConversionSequence::no_conversion, From, ToType);
     517                 :   }
     518                 : 
     519            16792:   return ICS;
     520                 : }
     521                 : 
     522                 : /// \brief Determine whether the conversion from FromType to ToType is a valid 
     523                 : /// conversion that strips "noreturn" off the nested function type.
     524                 : static bool IsNoReturnConversion(ASTContext &Context, QualType FromType, 
     525             4050:                                  QualType ToType, QualType &ResultTy) {
                        0: branch 1 not taken
                     4050: branch 2 taken
     526             4050:   if (Context.hasSameUnqualifiedType(FromType, ToType))
     527                0:     return false;
     528                 :   
     529                 :   // Strip the noreturn off the type we're converting from; noreturn can
     530                 :   // safely be removed.
     531             4050:   FromType = Context.getNoReturnType(FromType, false);
                     4040: branch 1 taken
                       10: branch 2 taken
     532             4050:   if (!Context.hasSameUnqualifiedType(FromType, ToType))
     533             4040:     return false;
     534                 : 
     535               10:   ResultTy = FromType;
     536               10:   return true;
     537                 : }
     538                 :   
     539                 : /// IsStandardConversion - Determines whether there is a standard
     540                 : /// conversion sequence (C++ [conv], C++ [over.ics.scs]) from the
     541                 : /// expression From to the type ToType. Standard conversion sequences
     542                 : /// only consider non-class types; for conversions that involve class
     543                 : /// types, use TryImplicitConversion. If a conversion exists, SCS will
     544                 : /// contain the standard conversion sequence required to perform this
     545                 : /// conversion and this routine will return true. Otherwise, this
     546                 : /// routine will return false and the value of SCS is unspecified.
     547                 : bool
     548                 : Sema::IsStandardConversion(Expr* From, QualType ToType,
     549                 :                            bool InOverloadResolution,
     550            47737:                            StandardConversionSequence &SCS) {
     551            47737:   QualType FromType = From->getType();
     552                 : 
     553                 :   // Standard conversions (C++ [conv])
     554            47737:   SCS.setAsIdentityConversion();
     555            47737:   SCS.Deprecated = false;
     556            47737:   SCS.IncompatibleObjC = false;
     557            47737:   SCS.setFromType(FromType);
     558            47737:   SCS.CopyConstructor = 0;
     559                 : 
     560                 :   // There are no standard conversions for class types in C++, so
     561                 :   // abort early. When overloading in C, however, we do permit
                    34818: branch 2 taken
                    12919: branch 3 taken
                      272: branch 6 taken
                    34546: branch 7 taken
                    13191: branch 8 taken
                    34546: branch 9 taken
     562            47737:   if (FromType->isRecordType() || ToType->isRecordType()) {
                    13187: branch 1 taken
                        4: branch 2 taken
     563            13191:     if (getLangOptions().CPlusPlus)
     564            13187:       return false;
     565                 : 
     566                 :     // When we're overloading in C, we allow, as standard conversions,
     567                 :   }
     568                 : 
     569                 :   // The first conversion can be an lvalue-to-rvalue conversion,
     570                 :   // array-to-pointer conversion, or function-to-pointer conversion
     571                 :   // (C++ 4p1).
     572                 : 
     573                 :   // Lvalue-to-rvalue conversion (C++ 4.1):
     574                 :   //   An lvalue (3.10) of a non-function, non-array type T can be
     575                 :   //   converted to an rvalue.
     576            34550:   Expr::isLvalueResult argIsLvalue = From->isLvalue(Context);
                     6849: branch 0 taken
                    27701: branch 1 taken
                     6798: branch 4 taken
                       51: branch 5 taken
                     6010: branch 8 taken
                      788: branch 9 taken
                     5899: branch 12 taken
                      111: branch 13 taken
                     5899: branch 14 taken
                    28651: branch 15 taken
     577            34550:   if (argIsLvalue == Expr::LV_Valid &&
     578                 :       !FromType->isFunctionType() && !FromType->isArrayType() &&
     579                 :       Context.getCanonicalType(FromType) != Context.OverloadTy) {
     580             5899:     SCS.First = ICK_Lvalue_To_Rvalue;
     581                 : 
     582                 :     // If T is a non-class type, the type of the rvalue is the
     583                 :     // cv-unqualified version of T. Otherwise, the type of the rvalue
     584                 :     // is T (C++ 4.1p1). C++ can't get here with class types; in C, we
     585                 :     // just strip the qualifiers because they don't matter.
     586             5899:     FromType = FromType.getUnqualifiedType();
                      788: branch 2 taken
                    27863: branch 3 taken
     587            28651:   } else if (FromType->isArrayType()) {
     588                 :     // Array-to-pointer conversion (C++ 4.2)
     589              788:     SCS.First = ICK_Array_To_Pointer;
     590                 : 
     591                 :     // An lvalue or rvalue of type "array of N T" or "array of unknown
     592                 :     // bound of T" can be converted to an rvalue of type "pointer to
     593                 :     // T" (C++ 4.2p1).
     594              788:     FromType = Context.getArrayDecayedType(FromType);
     595                 : 
                       21: branch 1 taken
                      767: branch 2 taken
     596              788:     if (IsStringLiteralToNonConstPointerConversion(From, ToType)) {
     597                 :       // This conversion is deprecated. (C++ D.4).
     598               21:       SCS.Deprecated = true;
     599                 : 
     600                 :       // For the purpose of ranking in overload resolution
     601                 :       // (13.3.3.1.1), this conversion is considered an
     602                 :       // array-to-pointer conversion followed by a qualification
     603                 :       // conversion (4.4). (C++ 4.2p2)
     604               21:       SCS.Second = ICK_Identity;
     605               21:       SCS.Third = ICK_Qualification;
     606               21:       SCS.setAllToTypes(FromType);
     607               21:       return true;
     608                 :     }
                       51: branch 2 taken
                    27812: branch 3 taken
                       51: branch 4 taken
                        0: branch 5 not taken
                       51: branch 6 taken
                    27812: branch 7 taken
     609            27863:   } else if (FromType->isFunctionType() && argIsLvalue == Expr::LV_Valid) {
     610                 :     // Function-to-pointer conversion (C++ 4.3).
     611               51:     SCS.First = ICK_Function_To_Pointer;
     612                 : 
     613                 :     // An lvalue of function type T can be converted to an rvalue of
     614                 :     // type "pointer to T." The result is a pointer to the
     615                 :     // function. (C++ 4.3p1).
     616               51:     FromType = Context.getPointerType(FromType);
                      225: branch 0 taken
                    27587: branch 1 taken
     617            27812:   } else if (FunctionDecl *Fn
     618            27812:                = ResolveAddressOfOverloadedFunction(From, ToType, false)) {
     619                 :     // Address of overloaded function (C++ [over.over]).
     620              225:     SCS.First = ICK_Function_To_Pointer;
     621                 : 
     622                 :     // We were able to resolve the address of the overloaded function,
     623                 :     // so we can convert to the type of that function.
     624              225:     FromType = Fn->getType();
                        0: branch 2 not taken
                      225: branch 3 taken
     625              225:     if (ToType->isLValueReferenceType())
     626                0:       FromType = Context.getLValueReferenceType(FromType);
                        0: branch 2 not taken
                      225: branch 3 taken
     627              225:     else if (ToType->isRValueReferenceType())
     628                0:       FromType = Context.getRValueReferenceType(FromType);
                       26: branch 2 taken
                      199: branch 3 taken
     629              225:     else if (ToType->isMemberPointerType()) {
     630                 :       // Resolve address only succeeds if both sides are member pointers,
     631                 :       // but it doesn't have to be the same class. See DR 247.
     632                 :       // Note that this means that the type of &Derived::fn can be
     633                 :       // Ret (Base::*)(Args) if the fn overload actually found is from the
     634                 :       // base class, even if it was brought into the derived class via a
     635                 :       // using declaration. The standard isn't clear on this issue at all.
     636               26:       CXXMethodDecl *M = cast<CXXMethodDecl>(Fn);
     637                 :       FromType = Context.getMemberPointerType(FromType,
     638               26:                     Context.getTypeDeclType(M->getParent()).getTypePtr());
     639                 :     } else
     640              199:       FromType = Context.getPointerType(FromType);
     641                 :   } else {
     642                 :     // We don't require any conversions for the first step.
     643            27587:     SCS.First = ICK_Identity;
     644                 :   }
     645            34529:   SCS.setToType(0, FromType);
     646                 : 
     647                 :   // The second conversion can be an integral promotion, floating
     648                 :   // point promotion, integral conversion, floating point conversion,
     649                 :   // floating-integral conversion, pointer conversion,
     650                 :   // pointer-to-member conversion, or boolean conversion (C++ 4p1).
     651                 :   // For overloading in C, this can also be a "compatible-type"
     652                 :   // conversion.
     653            34529:   bool IncompatibleObjC = false;
                    10987: branch 1 taken
                    23542: branch 2 taken
     654            34529:   if (Context.hasSameUnqualifiedType(FromType, ToType)) {
     655                 :     // The unqualified versions of the types are the same: there's no
     656                 :     // conversion to do.
     657            10987:     SCS.Second = ICK_Identity;
                     1502: branch 1 taken
                    22040: branch 2 taken
     658            23542:   } else if (IsIntegralPromotion(From, FromType, ToType)) {
     659                 :     // Integral promotion (C++ 4.5).
     660             1502:     SCS.Second = ICK_Integral_Promotion;
     661             1502:     FromType = ToType.getUnqualifiedType();
                       36: branch 1 taken
                    22004: branch 2 taken
     662            22040:   } else if (IsFloatingPointPromotion(FromType, ToType)) {
     663                 :     // Floating point promotion (C++ 4.6).
     664               36:     SCS.Second = ICK_Floating_Promotion;
     665               36:     FromType = ToType.getUnqualifiedType();
                       15: branch 1 taken
                    21989: branch 2 taken
     666            22004:   } else if (IsComplexPromotion(FromType, ToType)) {
     667                 :     // Complex promotion (Clang extension)
     668               15:     SCS.Second = ICK_Complex_Promotion;
     669               15:     FromType = ToType.getUnqualifiedType();
                     4596: branch 2 taken
                    17393: branch 3 taken
                        0: branch 6 not taken
                     4596: branch 7 taken
                    11117: branch 10 taken
                     6276: branch 11 taken
                    11059: branch 14 taken
                       58: branch 15 taken
                    11059: branch 16 taken
                    10930: branch 17 taken
     670            21989:   } else if ((FromType->isIntegralType() || FromType->isEnumeralType()) &&
     671                 :            (ToType->isIntegralType() && !ToType->isEnumeralType())) {
     672                 :     // Integral conversions (C++ 4.7).
     673            11059:     SCS.Second = ICK_Integral_Conversion;
     674            11059:     FromType = ToType.getUnqualifiedType();
                      441: branch 2 taken
                    10489: branch 3 taken
                      168: branch 6 taken
                      273: branch 7 taken
                      168: branch 8 taken
                    10762: branch 9 taken
     675            10930:   } else if (FromType->isFloatingType() && ToType->isFloatingType()) {
     676                 :     // Floating point conversions (C++ 4.8).
     677              168:     SCS.Second = ICK_Floating_Conversion;
     678              168:     FromType = ToType.getUnqualifiedType();
                        4: branch 2 taken
                    10758: branch 3 taken
                        0: branch 6 not taken
                        4: branch 7 taken
                        0: branch 8 not taken
                    10762: branch 9 taken
     679            10762:   } else if (FromType->isComplexType() && ToType->isComplexType()) {
     680                 :     // Complex conversions (C99 6.3.1.6)
     681                0:     SCS.Second = ICK_Complex_Conversion;
     682                0:     FromType = ToType.getUnqualifiedType();
                      273: branch 2 taken
                    10489: branch 3 taken
                      245: branch 6 taken
                       28: branch 7 taken
                      243: branch 10 taken
                        2: branch 11 taken
                        3: branch 14 taken
                      240: branch 15 taken
                     4188: branch 18 taken
                     6334: branch 19 taken
                        0: branch 22 not taken
                     4188: branch 23 taken
                     5655: branch 26 taken
                      679: branch 27 taken
                     5895: branch 28 taken
                     4867: branch 29 taken
     683            10762:   } else if ((FromType->isFloatingType() &&
     684                 :               ToType->isIntegralType() && (!ToType->isBooleanType() &&
     685                 :                                            !ToType->isEnumeralType())) ||
     686                 :              ((FromType->isIntegralType() || FromType->isEnumeralType()) &&
     687                 :               ToType->isFloatingType())) {
     688                 :     // Floating-integral conversions (C++ 4.9).
     689             5895:     SCS.Second = ICK_Floating_Integral;
     690             5895:     FromType = ToType.getUnqualifiedType();
                        3: branch 2 taken
                     4864: branch 3 taken
                        2: branch 6 taken
                        1: branch 7 taken
                        1: branch 10 taken
                     4865: branch 11 taken
                        1: branch 14 taken
                        0: branch 15 not taken
                        2: branch 16 taken
                     4865: branch 17 taken
     691             4867:   } else if ((FromType->isComplexType() && ToType->isArithmeticType()) ||
     692                 :              (ToType->isComplexType() && FromType->isArithmeticType())) {
     693                 :     // Complex-real conversions (C99 6.3.1.7)
     694                2:     SCS.Second = ICK_Complex_Real;
     695                2:     FromType = ToType.getUnqualifiedType();
                      823: branch 1 taken
                     4042: branch 2 taken
     696             4865:   } else if (IsPointerConversion(From, FromType, ToType, InOverloadResolution,
     697                 :                                  FromType, IncompatibleObjC)) {
     698                 :     // Pointer conversions (C++ 4.10).
     699              823:     SCS.Second = ICK_Pointer_Conversion;
     700              823:     SCS.IncompatibleObjC = IncompatibleObjC;
                      153: branch 1 taken
                     3889: branch 2 taken
     701             4042:   } else if (IsMemberPointerConversion(From, FromType, ToType, 
     702                 :                                        InOverloadResolution, FromType)) {
     703                 :     // Pointer to member conversions (4.11).
     704              153:     SCS.Second = ICK_Pointer_Member;
                       61: branch 2 taken
                     3828: branch 3 taken
                       57: branch 6 taken
                        4: branch 7 taken
                       57: branch 10 taken
                        0: branch 11 not taken
                       14: branch 14 taken
                       43: branch 15 taken
                       11: branch 18 taken
                        3: branch 19 taken
                        2: branch 22 taken
                        9: branch 23 taken
                        2: branch 26 taken
                        0: branch 27 not taken
                       61: branch 28 taken
                     3828: branch 29 taken
     705             3889:   } else if (ToType->isBooleanType() &&
     706                 :              (FromType->isArithmeticType() ||
     707                 :               FromType->isEnumeralType() ||
     708                 :               FromType->isAnyPointerType() ||
     709                 :               FromType->isBlockPointerType() ||
     710                 :               FromType->isMemberPointerType() ||
     711                 :               FromType->isNullPtrType())) {
     712                 :     // Boolean conversions (C++ 4.12).
     713               61:     SCS.Second = ICK_Boolean_Conversion;
     714               61:     FromType = Context.BoolTy;
                       19: branch 1 taken
                     3809: branch 2 taken
                        0: branch 4 not taken
                       19: branch 5 taken
                        0: branch 6 not taken
                     3828: branch 7 taken
     715             3828:   } else if (!getLangOptions().CPlusPlus &&
     716                 :              Context.typesAreCompatible(ToType, FromType)) {
     717                 :     // Compatible conversions (Clang extension for C function overloading)
     718                0:     SCS.Second = ICK_Compatible_Conversion;
                        7: branch 1 taken
                     3821: branch 2 taken
     719             3828:   } else if (IsNoReturnConversion(Context, FromType, ToType, FromType)) {
     720                 :     // Treat a conversion that strips "noreturn" as an identity conversion.
     721                7:     SCS.Second = ICK_NoReturn_Adjustment;
     722                 :   } else {
     723                 :     // No second conversion required.
     724             3821:     SCS.Second = ICK_Identity;
     725                 :   }
     726            34529:   SCS.setToType(1, FromType);
     727                 : 
     728            34529:   QualType CanonFrom;
     729            34529:   QualType CanonTo;
     730                 :   // The third conversion can be a qualification conversion (C++ 4p1).
                      232: branch 1 taken
                    34297: branch 2 taken
     731            34529:   if (IsQualificationConversion(FromType, ToType)) {
     732              232:     SCS.Third = ICK_Qualification;
     733              232:     FromType = ToType;
     734              232:     CanonFrom = Context.getCanonicalType(FromType);
     735              232:     CanonTo = Context.getCanonicalType(ToType);
     736                 :   } else {
     737                 :     // No conversion required
     738            34297:     SCS.Third = ICK_Identity;
     739                 : 
     740                 :     // C++ [over.best.ics]p6:
     741                 :     //   [...] Any difference in top-level cv-qualification is
     742                 :     //   subsumed by the initialization itself and does not constitute
     743                 :     //   a conversion. [...]
     744            34297:     CanonFrom = Context.getCanonicalType(FromType);
     745            34297:     CanonTo = Context.getCanonicalType(ToType);
                    30673: branch 3 taken
                     3624: branch 4 taken
                      244: branch 7 taken
                    30429: branch 8 taken
                      244: branch 9 taken
                    34053: branch 10 taken
     746            34297:     if (CanonFrom.getLocalUnqualifiedType() 
     747                 :                                        == CanonTo.getLocalUnqualifiedType() &&
     748                 :         CanonFrom.getLocalCVRQualifiers() != CanonTo.getLocalCVRQualifiers()) {
     749              244:       FromType = ToType;
     750              244:       CanonFrom = CanonTo;
     751                 :     }
     752                 :   }
     753            34529:   SCS.setToType(2, FromType);
     754                 : 
     755                 :   // If we have not converted the argument type to the parameter type,
     756                 :   // this is a bad conversion sequence.
                     3624: branch 1 taken
                    30905: branch 2 taken
     757            34529:   if (CanonFrom != CanonTo)
     758             3624:     return false;
     759                 : 
     760            30905:   return true;
     761                 : }
     762                 : 
     763                 : /// IsIntegralPromotion - Determines whether the conversion from the
     764                 : /// expression From (whose potentially-adjusted type is FromType) to
     765                 : /// ToType is an integral promotion (C++ 4.5). If so, returns true and
     766                 : /// sets PromotedType to the promoted type.
     767            24046: bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) {
     768            24046:   const BuiltinType *To = ToType->getAs<BuiltinType>();
     769                 :   // All integers are built-in.
                     2205: branch 0 taken
                    21841: branch 1 taken
     770            24046:   if (!To) {
     771             2205:     return false;
     772                 :   }
     773                 : 
     774                 :   // An rvalue of type char, signed char, unsigned char, short int, or
     775                 :   // unsigned short int can be converted to an rvalue of type int if
     776                 :   // int can represent all the values of the source type; otherwise,
     777                 :   // the source rvalue can be converted to an rvalue of type unsigned
     778                 :   // int (C++ 4.5p1).
                    12154: branch 2 taken
                     9687: branch 3 taken
                     9521: branch 6 taken
                     2633: branch 7 taken
                     2093: branch 10 taken
                     7428: branch 11 taken
                     2093: branch 12 taken
                    19748: branch 13 taken
     779            21841:   if (FromType->isPromotableIntegerType() && !FromType->isBooleanType() &&
     780                 :       !FromType->isEnumeralType()) {
                      659: branch 2 taken
                     1434: branch 3 taken
                      659: branch 6 taken
                        0: branch 7 not taken
                      658: branch 10 taken
                        1: branch 11 taken
                     2092: branch 12 taken
                        1: branch 13 taken
     781             2093:     if (// We can promote any signed, promotable integer type to an int
     782                 :         (FromType->isSignedIntegerType() ||
     783                 :          // We can promote any unsigned integer type whose size is
     784                 :          // less than int to an int.
     785                 :          (!FromType->isSignedIntegerType() &&
     786                 :           Context.getTypeSize(FromType) < Context.getTypeSize(ToType)))) {
     787             2092:       return To->getKind() == BuiltinType::Int;
     788                 :     }
     789                 : 
     790                1:     return To->getKind() == BuiltinType::UInt;
     791                 :   }
     792                 : 
     793                 :   // An rvalue of type wchar_t (3.9.1) or an enumeration type (7.2)
     794                 :   // can be converted to an rvalue of the first of the following types
     795                 :   // that can represent all the values of its underlying type: int,
     796                 :   // unsigned int, long, or unsigned long (C++ 4.5p2).
     797                 : 
     798                 :   // We pre-calculate the promotion type for enum types.
                     7446: branch 2 taken
                    12302: branch 3 taken
     799            19748:   if (const EnumType *FromEnumType = FromType->getAs<EnumType>())
                     5208: branch 2 taken
                     2238: branch 3 taken
     800             7446:     if (ToType->isIntegerType())
     801                 :       return Context.hasSameUnqualifiedType(ToType,
     802             5208:                                 FromEnumType->getDecl()->getPromotionType());
     803                 : 
                        0: branch 2 not taken
                    14540: branch 3 taken
                        0: branch 6 not taken
                        0: branch 7 not taken
                        0: branch 8 not taken
                    14540: branch 9 taken
     804            14540:   if (FromType->isWideCharType() && ToType->isIntegerType()) {
     805                 :     // Determine whether the type we're converting from is signed or
     806                 :     // unsigned.
     807                 :     bool FromIsSigned;
     808                0:     uint64_t FromSize = Context.getTypeSize(FromType);
     809                 :     
     810                 :     // FIXME: Is wchar_t signed or unsigned? We assume it's signed for now.
     811                0:     FromIsSigned = true;
     812                 : 
     813                 :     // The types we'll try to promote to, in the appropriate
     814                 :     // order. Try each of these types.
     815                 :     QualType PromoteTypes[6] = {
     816                 :       Context.IntTy, Context.UnsignedIntTy,
     817                 :       Context.LongTy, Context.UnsignedLongTy ,
     818                 :       Context.LongLongTy, Context.UnsignedLongLongTy
     819                0:     };
                        0: branch 0 not taken
                        0: branch 1 not taken
     820                0:     for (int Idx = 0; Idx < 6; ++Idx) {
     821                0:       uint64_t ToSize = Context.getTypeSize(PromoteTypes[Idx]);
                        0: branch 0 not taken
                        0: branch 1 not taken
                        0: branch 2 not taken
                        0: branch 3 not taken
                        0: branch 6 not taken
                        0: branch 7 not taken
                        0: branch 8 not taken
                        0: branch 9 not taken
     822                0:       if (FromSize < ToSize ||
     823                 :           (FromSize == ToSize &&
     824                 :            FromIsSigned == PromoteTypes[Idx]->isSignedIntegerType())) {
     825                 :         // We found the type that we can promote to. If this is the
     826                 :         // type we wanted, we have a promotion. Otherwise, no
     827                 :         // promotion.
     828                0:         return Context.hasSameUnqualifiedType(ToType, PromoteTypes[Idx]);
     829                 :       }
     830                 :     }
     831                 :   }
     832                 : 
     833                 :   // An rvalue for an integral bit-field (9.6) can be converted to an
     834                 :   // rvalue of type int if int can represent all the values of the
     835                 :   // bit-field; otherwise, it can be converted to unsigned int if
     836                 :   // unsigned int can represent all the values of the bit-field. If
     837                 :   // the bit-field is larger yet, no integral promotion applies to
     838                 :   // it. If the bit-field has an enumerated type, it is treated as any
     839                 :   // other value of that type for promotion purposes (C++ 4.5p3).
     840                 :   // FIXME: We should delay checking of bit-fields until we actually perform the
     841                 :   // conversion.
     842                 :   using llvm::APSInt;
                    14534: branch 0 taken
                        6: branch 1 taken
     843            14540:   if (From)
                        2: branch 1 taken
                    14532: branch 2 taken
     844            14534:     if (FieldDecl *MemberDecl = From->getBitField()) {
     845                2:       APSInt BitWidth;
                        2: branch 2 taken
                        0: branch 3 not taken
                        2: branch 6 taken
                        0: branch 7 not taken
                        2: branch 10 taken
                        0: branch 11 not taken
                        2: branch 12 taken
                        0: branch 13 not taken
     846                2:       if (FromType->isIntegralType() && !FromType->isEnumeralType() &&
     847                 :           MemberDecl->getBitWidth()->isIntegerConstantExpr(BitWidth, Context)) {
     848                2:         APSInt ToSize(BitWidth.getBitWidth(), BitWidth.isUnsigned());
     849                2:         ToSize = Context.getTypeSize(ToType);
     850                 : 
     851                 :         // Are we promoting to an int from a bitfield that fits in an int?
                        0: branch 1 not taken
                        2: branch 2 taken
                        0: branch 5 not taken
                        0: branch 6 not taken
                        0: branch 8 not taken
                        0: branch 9 not taken
                        2: branch 10 taken
                        0: branch 11 not taken
     852                2:         if (BitWidth < ToSize ||
     853                 :             (FromType->isSignedIntegerType() && BitWidth <= ToSize)) {
     854                2:           return To->getKind() == BuiltinType::Int;
     855                 :         }
     856                 : 
     857                 :         // Are we promoting to an unsigned int from an unsigned bitfield
     858                 :         // that fits into an unsigned int?
                        0: branch 2 not taken
                        0: branch 3 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
                        0: branch 7 not taken
                        0: branch 8 not taken
     859                0:         if (FromType->isUnsignedIntegerType() && BitWidth <= ToSize) {
     860                0:           return To->getKind() == BuiltinType::UInt;
     861                 :         }
     862                 : 
     863                0:         return false;
                        0: branch 1 not taken
                        2: branch 2 taken
     864                2:       }
     865                 :     }
     866                 : 
     867                 :   // An rvalue of type bool can be converted to an rvalue of type int,
     868                 :   // with false becoming zero and true becoming one (C++ 4.5p4).
                     2633: branch 2 taken
                    11905: branch 3 taken
                      328: branch 5 taken
                     2305: branch 6 taken
                      328: branch 7 taken
                    14210: branch 8 taken
     869            14538:   if (FromType->isBooleanType() && To->getKind() == BuiltinType::Int) {
     870              328:     return true;
     871                 :   }
     872                 : 
     873            14210:   return false;
     874                 : }
     875                 : 
     876                 : /// IsFloatingPointPromotion - Determines whether the conversion from
     877                 : /// FromType to ToType is a floating point promotion (C++ 4.6). If so,
     878                 : /// returns true and sets PromotedType to the promoted type.
     879            22063: bool Sema::IsFloatingPointPromotion(QualType FromType, QualType ToType) {
     880                 :   /// An rvalue of type float can be converted to an rvalue of type
     881                 :   /// double. (C++ 4.6p1).
                    11493: branch 2 taken
                    10570: branch 3 taken
     882            22063:   if (const BuiltinType *FromBuiltin = FromType->getAs<BuiltinType>())
                    10756: branch 2 taken
                      737: branch 3 taken
     883            11493:     if (const BuiltinType *ToBuiltin = ToType->getAs<BuiltinType>()) {
                      183: branch 1 taken
                    10573: branch 2 taken
                       45: branch 4 taken
                      138: branch 5 taken
                       45: branch 6 taken
                    10711: branch 7 taken
     884            10756:       if (FromBuiltin->getKind() == BuiltinType::Float &&
     885                 :           ToBuiltin->getKind() == BuiltinType::Double)
     886               45:         return true;
     887                 : 
     888                 :       // C99 6.3.1.5p1:
     889                 :       //   When a float is promoted to double or long double, or a
     890                 :       //   double is promoted to long double [...].
                       20: branch 1 taken
                    10691: branch 2 taken
                       17: branch 4 taken
                        3: branch 5 taken
                       10: branch 7 taken
                        7: branch 8 taken
                        2: branch 10 taken
                       11: branch 11 taken
                        2: branch 12 taken
                    10709: branch 13 taken
     891            10711:       if (!getLangOptions().CPlusPlus &&
     892                 :           (FromBuiltin->getKind() == BuiltinType::Float ||
     893                 :            FromBuiltin->getKind() == BuiltinType::Double) &&
     894                 :           (ToBuiltin->getKind() == BuiltinType::LongDouble))
     895                2:         return true;
     896                 :     }
     897                 : 
     898            22016:   return false;
     899                 : }
     900                 : 
     901                 : /// \brief Determine if a conversion is a complex promotion.
     902                 : ///
     903                 : /// A complex promotion is defined as a complex -> complex conversion
     904                 : /// where the conversion between the underlying real types is a
     905                 : /// floating-point or integral promotion.
     906            22004: bool Sema::IsComplexPromotion(QualType FromType, QualType ToType) {
     907            22004:   const ComplexType *FromComplex = FromType->getAs<ComplexType>();
                    21955: branch 0 taken
                       49: branch 1 taken
     908            22004:   if (!FromComplex)
     909            21955:     return false;
     910                 : 
     911               49:   const ComplexType *ToComplex = ToType->getAs<ComplexType>();
                       26: branch 0 taken
                       23: branch 1 taken
     912               49:   if (!ToComplex)
     913               26:     return false;
     914                 : 
     915                 :   return IsFloatingPointPromotion(FromComplex->getElementType(),
     916                 :                                   ToComplex->getElementType()) ||
     917                 :     IsIntegralPromotion(0, FromComplex->getElementType(),
                       12: branch 3 taken
                       11: branch 4 taken
                        4: branch 8 taken
                        8: branch 9 taken
     918               23:                         ToComplex->getElementType());
     919                 : }
     920                 : 
     921                 : /// BuildSimilarlyQualifiedPointerType - In a pointer conversion from
     922                 : /// the pointer type FromPtr to a pointer to type ToPointee, with the
     923                 : /// same type qualifiers as FromPtr has on its pointee type. ToType,
     924                 : /// if non-empty, will be a pointer to ToType that may or may not have
     925                 : /// the right set of qualifiers on its pointee.
     926                 : static QualType
     927                 : BuildSimilarlyQualifiedPointerType(const PointerType *FromPtr,
     928                 :                                    QualType ToPointee, QualType ToType,
     929              222:                                    ASTContext &Context) {
     930              222:   QualType CanonFromPointee = Context.getCanonicalType(FromPtr->getPointeeType());
     931              222:   QualType CanonToPointee = Context.getCanonicalType(ToPointee);
     932              222:   Qualifiers Quals = CanonFromPointee.getQualifiers();
     933                 : 
     934                 :   // Exact qualifier match -> return the pointer type we're converting to.
                      193: branch 2 taken
                       29: branch 3 taken
     935              222:   if (CanonToPointee.getLocalQualifiers() == Quals) {
     936                 :     // ToType is exactly what we need. Return it.
                      193: branch 1 taken
                        0: branch 2 not taken
     937              193:     if (!ToType.isNull())
     938              193:       return ToType;
     939                 : 
     940                 :     // Build a pointer to ToPointee. It has the right qualifiers
     941                 :     // already.
     942                0:     return Context.getPointerType(ToPointee);
     943                 :   }
     944                 : 
     945                 :   // Just build a canonical type that has the right qualifiers.
     946                 :   return Context.getPointerType(
     947                 :          Context.getQualifiedType(CanonToPointee.getLocalUnqualifiedType(), 
     948               29:                                   Quals));
     949                 : }
     950                 : 
     951                 : /// BuildSimilarlyQualifiedObjCObjectPointerType - In a pointer conversion from
     952                 : /// the FromType, which is an objective-c pointer, to ToType, which may or may
     953                 : /// not have the right set of qualifiers.
     954                 : static QualType
     955                 : BuildSimilarlyQualifiedObjCObjectPointerType(QualType FromType,
     956                 :                                              QualType ToType,
     957               14:                                              ASTContext &Context) {
     958               14:   QualType CanonFromType = Context.getCanonicalType(FromType);
     959               14:   QualType CanonToType = Context.getCanonicalType(ToType);
     960               14:   Qualifiers Quals = CanonFromType.getQualifiers();
     961                 :     
     962                 :   // Exact qualifier match -> return the pointer type we're converting to.
                       14: branch 2 taken
                        0: branch 3 not taken
     963               14:   if (CanonToType.getLocalQualifiers() == Quals)
     964               14:     return ToType;
     965                 :   
     966                 :   // Just build a canonical type that has the right qualifiers.
     967                0:   return Context.getQualifiedType(CanonToType.getLocalUnqualifiedType(), Quals);
     968                 : }
     969                 :   
     970                 : static bool isNullPointerConstantForConversion(Expr *Expr,
     971                 :                                                bool InOverloadResolution,
     972             1351:                                                ASTContext &Context) {
     973                 :   // Handle value-dependent integral null pointer constants correctly.
     974                 :   // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903
                        2: branch 1 taken
                     1349: branch 2 taken
                        2: branch 4 taken
                        0: branch 5 not taken
                        1: branch 9 taken
                        1: branch 10 taken
                        1: branch 11 taken
                     1350: branch 12 taken
     975             1351:   if (Expr->isValueDependent() && !Expr->isTypeDependent() &&
     976                 :       Expr->getType()->isIntegralType())
     977                1:     return !InOverloadResolution;
     978                 : 
     979                 :   return Expr->isNullPointerConstant(Context,
     980                 :                     InOverloadResolution? Expr::NPC_ValueDependentIsNotNull
                      180: branch 0 taken
                     1170: branch 1 taken
     981             1350:                                         : Expr::NPC_ValueDependentIsNull);
     982                 : }
     983                 : 
     984                 : /// IsPointerConversion - Determines whether the conversion of the
     985                 : /// expression From, which has the (possibly adjusted) type FromType,
     986                 : /// can be converted to the type ToType via a pointer conversion (C++
     987                 : /// 4.10). If so, returns true and places the converted type (that
     988                 : /// might differ from ToType in its cv-qualifiers at some level) into
     989                 : /// ConvertedType.
     990                 : ///
     991                 : /// This routine also supports conversions to and from block pointers
     992                 : /// and conversions with Objective-C's 'id', 'id<protocols...>', and
     993                 : /// pointers to interfaces. FIXME: Once we've determined the
     994                 : /// appropriate overloading rules for Objective-C, we may want to
     995                 : /// split the Objective-C checks into a different routine; however,
     996                 : /// GCC seems to consider all of these conversions to be pointer
     997                 : /// conversions, so for now they live here. IncompatibleObjC will be
     998                 : /// set if the conversion is an allowed Objective-C conversion that
     999                 : /// should result in a warning.
    1000                 : bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
    1001                 :                                bool InOverloadResolution,
    1002                 :                                QualType& ConvertedType,
    1003             4865:                                bool &IncompatibleObjC) {
    1004             4865:   IncompatibleObjC = false;
                       88: branch 1 taken
                     4777: branch 2 taken
    1005             4865:   if (isObjCPointerConversion(FromType, ToType, ConvertedType, IncompatibleObjC))
    1006               88:     return true;
    1007                 : 
    1008                 :   // Conversion from a null pointer constant to any Objective-C pointer type.
                       26: branch 2 taken
                     4751: branch 3 taken
                       11: branch 5 taken
                       15: branch 6 taken
                       11: branch 7 taken
                     4766: branch 8 taken
    1009             4777:   if (ToType->isObjCObjectPointerType() &&
    1010                 :       isNullPointerConstantForConversion(From, InOverloadResolution, Context)) {
    1011               11:     ConvertedType = ToType;
    1012               11:     return true;
    1013                 :   }
    1014                 : 
    1015                 :   // Blocks: Block pointers can be converted to void*.
                       10: branch 2 taken
                     4756: branch 3 taken
                        5: branch 6 taken
                        5: branch 7 taken
                        5: branch 13 taken
                        0: branch 14 not taken
                        5: branch 15 taken
                     4761: branch 16 taken
    1016             4766:   if (FromType->isBlockPointerType() && ToType->isPointerType() &&
    1017                 :       ToType->getAs<PointerType>()->getPointeeType()->isVoidType()) {
    1018                5:     ConvertedType = ToType;
    1019                5:     return true;
    1020                 :   }
    1021                 :   // Blocks: A null pointer constant can be converted to a block
    1022                 :   // pointer type.
                        6: branch 2 taken
                     4755: branch 3 taken
                        0: branch 5 not taken
                        6: branch 6 taken
                        0: branch 7 not taken
                     4761: branch 8 taken
    1023             4761:   if (ToType->isBlockPointerType() &&
    1024                 :       isNullPointerConstantForConversion(From, InOverloadResolution, Context)) {
    1025                0:     ConvertedType = ToType;
    1026                0:     return true;
    1027                 :   }
    1028                 : 
    1029                 :   // If the left-hand-side is nullptr_t, the right side can be a null
    1030                 :   // pointer constant.
                        1: branch 2 taken
                     4760: branch 3 taken
                        1: branch 5 taken
                        0: branch 6 not taken
                        1: branch 7 taken
                     4760: branch 8 taken
    1031             4761:   if (ToType->isNullPtrType() &&
    1032                 :       isNullPointerConstantForConversion(From, InOverloadResolution, Context)) {
    1033                1:     ConvertedType = ToType;
    1034                1:     return true;
    1035                 :   }
    1036                 : 
    1037             4760:   const PointerType* ToTypePtr = ToType->getAs<PointerType>();
                     3442: branch 0 taken
                     1318: branch 1 taken
    1038             4760:   if (!ToTypePtr)
    1039             3442:     return false;
    1040                 : 
    1041                 :   // A null pointer constant can be converted to a pointer type (C++ 4.10p1).
                      482: branch 1 taken
                      836: branch 2 taken
    1042             1318:   if (isNullPointerConstantForConversion(From, InOverloadResolution, Context)) {
    1043              482:     ConvertedType = ToType;
    1044              482:     return true;
    1045                 :   }
    1046                 : 
    1047                 :   // Beyond this point, both types need to be pointers 
    1048                 :   // , including objective-c pointers.
    1049              836:   QualType ToPointeeType = ToTypePtr->getPointeeType();
                       18: branch 2 taken
                      818: branch 3 taken
                       14: branch 6 taken
                        4: branch 7 taken
                       14: branch 8 taken
                      822: branch 9 taken
    1050              836:   if (FromType->isObjCObjectPointerType() && ToPointeeType->isVoidType()) {
    1051                 :     ConvertedType = BuildSimilarlyQualifiedObjCObjectPointerType(FromType,
    1052               14:                                                        ToType, Context);
    1053               14:     return true;
    1054                 :     
    1055                 :   }
    1056              822:   const PointerType *FromTypePtr = FromType->getAs<PointerType>();
                       83: branch 0 taken
                      739: branch 1 taken
    1057              822:   if (!FromTypePtr)
    1058               83:     return false;
    1059                 : 
    1060              739:   QualType FromPointeeType = FromTypePtr->getPointeeType();
    1061                 : 
    1062                 :   // An rvalue of type "pointer to cv T," where T is an object type,
    1063                 :   // can be converted to an rvalue of type "pointer to cv void" (C++
    1064                 :   // 4.10p2).
                      542: branch 2 taken
                      197: branch 3 taken
                      100: branch 6 taken
                      442: branch 7 taken
                      100: branch 8 taken
                      639: branch 9 taken
    1065              739:   if (FromPointeeType->isObjectType() && ToPointeeType->isVoidType()) {
    1066                 :     ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr,
    1067                 :                                                        ToPointeeType,
    1068              100:                                                        ToType, Context);
    1069              100:     return true;
    1070                 :   }
    1071                 : 
    1072                 :   // When we're overloading in C, we allow a special kind of pointer
    1073                 :   // conversion for compatible-but-not-identical pointee types.
                        3: branch 1 taken
                      636: branch 2 taken
                        1: branch 4 taken
                        2: branch 5 taken
                        1: branch 6 taken
                      638: branch 7 taken
    1074              639:   if (!getLangOptions().CPlusPlus &&
    1075                 :       Context.typesAreCompatible(FromPointeeType, ToPointeeType)) {
    1076                 :     ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr,
    1077                 :                                                        ToPointeeType,
    1078                1:                                                        ToType, Context);
    1079                1:     return true;
    1080                 :   }
    1081                 : 
    1082                 :   // C++ [conv.ptr]p3:
    1083                 :   //
    1084                 :   //   An rvalue of type "pointer to cv D," where D is a class type,
    1085                 :   //   can be converted to an rvalue of type "pointer to cv B," where
    1086                 :   //   B is a base class (clause 10) of D. If B is an inaccessible
    1087                 :   //   (clause 11) or ambiguous (10.2) base class of D, a program that
    1088                 :   //   necessitates this conversion is ill-formed. The result of the
    1089                 :   //   conversion is a pointer to the base class sub-object of the
    1090                 :   //   derived class object. The null pointer value is converted to
    1091                 :   //   the null pointer value of the destination type.
    1092                 :   //
    1093                 :   // Note that we do not check for ambiguity or inaccessibility
    1094                 :   // here. That is handled by CheckPointerConversion.
                      636: branch 1 taken
                        2: branch 2 taken
                      278: branch 5 taken
                      358: branch 6 taken
                      256: branch 9 taken
                       22: branch 10 taken
                      247: branch 17 taken
                        9: branch 18 taken
                      121: branch 20 taken
                      126: branch 21 taken
                      256: branch 22 taken
                      382: branch 23 taken
                      256: branch 25 taken
                      382: branch 26 taken
                      256: branch 28 taken
                      382: branch 29 taken
                      121: branch 31 taken
                      517: branch 32 taken
    1095              638:   if (getLangOptions().CPlusPlus &&
    1096                 :       FromPointeeType->isRecordType() && ToPointeeType->isRecordType() &&
    1097                 :       !RequireCompleteType(From->getLocStart(), FromPointeeType, PDiag()) &&
    1098                 :       IsDerivedFrom(FromPointeeType, ToPointeeType)) {
    1099                 :     ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr,
    1100                 :                                                        ToPointeeType,
    1101              121:                                                        ToType, Context);
    1102              121:     return true;
    1103                 :   }
    1104                 : 
    1105              517:   return false;
    1106                 : }
    1107                 : 
    1108                 : /// isObjCPointerConversion - Determines whether this is an
    1109                 : /// Objective-C pointer conversion. Subroutine of IsPointerConversion,
    1110                 : /// with the same arguments and return values.
    1111                 : bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType,
    1112                 :                                    QualType& ConvertedType,
    1113             4878:                                    bool &IncompatibleObjC) {
                     4705: branch 1 taken
                      173: branch 2 taken
    1114             4878:   if (!getLangOptions().ObjC1)
    1115             4705:     return false;
    1116                 :  
    1117                 :   // First, we handle all conversions on ObjC object pointer types.
    1118              173:   const ObjCObjectPointerType* ToObjCPtr = ToType->getAs<ObjCObjectPointerType>();
    1119                 :   const ObjCObjectPointerType *FromObjCPtr =
    1120              173:     FromType->getAs<ObjCObjectPointerType>();
    1121                 : 
                      112: branch 0 taken
                       61: branch 1 taken
                       89: branch 2 taken
                       23: branch 3 taken
    1122              173:   if (ToObjCPtr && FromObjCPtr) {
    1123                 :     // Objective C++: We're able to convert between "id" or "Class" and a
    1124                 :     // pointer to any interface (in both directions).
                       31: branch 1 taken
                       58: branch 2 taken
                        7: branch 4 taken
                       24: branch 5 taken
                        7: branch 6 taken
                       82: branch 7 taken
    1125               89:     if (ToObjCPtr->isObjCBuiltinType() && FromObjCPtr->isObjCBuiltinType()) {
    1126                7:       ConvertedType = ToType;
    1127                7:       return true;
    1128                 :     }
    1129                 :     // Conversions with Objective-C's id<...>.
                       72: branch 1 taken
                       10: branch 2 taken
                       29: branch 4 taken
                       43: branch 5 taken
                       34: branch 7 taken
                        5: branch 8 taken
                       34: branch 9 taken
                       48: branch 10 taken
    1130               82:     if ((FromObjCPtr->isObjCQualifiedIdType() ||
    1131                 :          ToObjCPtr->isObjCQualifiedIdType()) &&
    1132                 :         Context.ObjCQualifiedIdTypesAreCompatible(ToType, FromType,
    1133                 :                                                   /*compare=*/false)) {
    1134               34:       ConvertedType = ToType;
    1135               34:       return true;
    1136                 :     }
    1137                 :     // Objective C++: We're able to convert from a pointer to an
    1138                 :     // interface to a pointer to a different interface.
                       37: branch 1 taken
                       11: branch 2 taken
    1139               48:     if (Context.canAssignObjCInterfaces(ToObjCPtr, FromObjCPtr)) {
    1140               37:       ConvertedType = ToType;
    1141               37:       return true;
    1142                 :     }
    1143                 : 
                        6: branch 1 taken
                        5: branch 2 taken
    1144               11:     if (Context.canAssignObjCInterfaces(FromObjCPtr, ToObjCPtr)) {
    1145                 :       // Okay: this is some kind of implicit downcast of Objective-C
    1146                 :       // interfaces, which is permitted. However, we're going to
    1147                 :       // complain about it.
    1148                6:       IncompatibleObjC = true;
    1149                6:       ConvertedType = FromType;
    1150                6:       return true;
    1151                 :     }
    1152                 :   }
    1153                 :   // Beyond this point, both types need to be C pointers or block pointers.
    1154               89:   QualType ToPointeeType;
                       40: branch 2 taken
                       49: branch 3 taken
    1155               89:   if (const PointerType *ToCPtr = ToType->getAs<PointerType>())
    1156               40:     ToPointeeType = ToCPtr->getPointeeType();
                       11: branch 0 taken
                       38: branch 1 taken
    1157               49:   else if (const BlockPointerType *ToBlockPtr = 
    1158               49:             ToType->getAs<BlockPointerType>()) {
    1159                 :     // Objective C++: We're able to convert from a pointer to any object
    1160                 :     // to a block pointer type.
                        3: branch 0 taken
                        8: branch 1 taken
                        2: branch 3 taken
                        1: branch 4 taken
                        2: branch 5 taken
                        9: branch 6 taken
    1161               11:     if (FromObjCPtr && FromObjCPtr->isObjCBuiltinType()) {
    1162                2:       ConvertedType = ToType;
    1163                2:       return true;
    1164                 :     }
    1165                9:     ToPointeeType = ToBlockPtr->getPointeeType();
    1166                 :   }
                        6: branch 2 taken
                       32: branch 3 taken
                        3: branch 4 taken
                        3: branch 5 taken
                        2: branch 7 taken
                        1: branch 8 taken
                        2: branch 9 taken
                       36: branch 10 taken
    1167               38:   else if (FromType->getAs<BlockPointerType>() && 
    1168                 :            ToObjCPtr && ToObjCPtr->isObjCBuiltinType()) {
    1169                 :     // Objective C++: We're able to convert from a block pointer type to a 
    1170                 :     // pointer to any object.
    1171                2:     ConvertedType = ToType;
    1172                2:     return true;
    1173                 :   }
    1174                 :   else
    1175               36:     return false;
    1176                 : 
    1177               49:   QualType FromPointeeType;
                       20: branch 2 taken
                       29: branch 3 taken
    1178               49:   if (const PointerType *FromCPtr = FromType->getAs<PointerType>())
    1179               20:     FromPointeeType = FromCPtr->getPointeeType();
                        6: branch 2 taken
                       23: branch 3 taken
    1180               29:   else if (const BlockPointerType *FromBlockPtr = FromType->getAs<BlockPointerType>())
    1181                6:     FromPointeeType = FromBlockPtr->getPointeeType();
    1182                 :   else
    1183               23:     return false;
    1184                 : 
    1185                 :   // If we have pointers to pointers, recursively check whether this
    1186                 :   // is an Objective-C conversion.
                        1: branch 2 taken
                       25: branch 3 taken
                        0: branch 6 not taken
                        1: branch 7 taken
                        0: branch 9 not taken
                        0: branch 10 not taken
                        0: branch 11 not taken
                       26: branch 12 taken
    1187               26:   if (FromPointeeType->isPointerType() && ToPointeeType->isPointerType() &&
    1188                 :       isObjCPointerConversion(FromPointeeType, ToPointeeType, ConvertedType,
    1189                 :                               IncompatibleObjC)) {
    1190                 :     // We always complain about this conversion.
    1191                0:     IncompatibleObjC = true;
    1192                0:     ConvertedType = ToType;
    1193                0:     return true;
    1194                 :   }
    1195                 :   // Allow conversion of pointee being objective-c pointer to another one;
    1196                 :   // as in I* to id.
                        6: branch 2 taken
                       20: branch 3 taken
                        5: branch 6 taken
                        1: branch 7 taken
                        5: branch 9 taken
                        0: branch 10 not taken
                        5: branch 11 taken
                       21: branch 12 taken
    1197               26:   if (FromPointeeType->getAs<ObjCObjectPointerType>() &&
    1198                 :       ToPointeeType->getAs<ObjCObjectPointerType>() &&
    1199                 :       isObjCPointerConversion(FromPointeeType, ToPointeeType, ConvertedType,
    1200                 :                               IncompatibleObjC)) {
    1201                5:     ConvertedType = ToType;
    1202                5:     return true;
    1203                 :   }
    1204                 :   
    1205                 :   // If we have pointers to functions or blocks, check whether the only
    1206                 :   // differences in the argument and result types are in Objective-C
    1207                 :   // pointer conversions. If so, we permit the conversion (but
    1208                 :   // complain about it).
    1209                 :   const FunctionProtoType *FromFunctionType
    1210               21:     = FromPointeeType->getAs<FunctionProtoType>();
    1211                 :   const FunctionProtoType *ToFunctionType
    1212               21:     = ToPointeeType->getAs<FunctionProtoType>();
                       12: branch 0 taken
                        9: branch 1 taken
                       10: branch 2 taken
                        2: branch 3 taken
    1213               21:   if (FromFunctionType && ToFunctionType) {
    1214                 :     // If the function types are exactly the same, this isn't an
    1215                 :     // Objective-C pointer conversion.
                        0: branch 3 not taken
                       10: branch 4 taken
    1216               10:     if (Context.getCanonicalType(FromPointeeType)
    1217                 :           == Context.getCanonicalType(ToPointeeType))
    1218                0:       return false;
    1219                 : 
    1220                 :     // Perform the quick checks that will tell us whether these
    1221                 :     // function types are obviously different.
                        8: branch 2 taken
                        2: branch 3 taken
                        8: branch 6 taken
                        0: branch 7 not taken
                        0: branch 10 not taken
                        8: branch 11 taken
                        2: branch 12 taken
                        8: branch 13 taken
    1222               10:     if (FromFunctionType->getNumArgs() != ToFunctionType->getNumArgs() ||
    1223                 :         FromFunctionType->isVariadic() != ToFunctionType->isVariadic() ||
    1224                 :         FromFunctionType->getTypeQuals() != ToFunctionType->getTypeQuals())
    1225                2:       return false;
    1226                 : 
    1227                8:     bool HasObjCConversion = false;
                        6: branch 5 taken
                        2: branch 6 taken
    1228                8:     if (Context.getCanonicalType(FromFunctionType->getResultType())
    1229                 :           == Context.getCanonicalType(ToFunctionType->getResultType())) {
    1230                 :       // Okay, the types match exactly. Nothing to do.
                        6: branch 3 taken
                        0: branch 4 not taken
    1231                6:     } else if (isObjCPointerConversion(FromFunctionType->getResultType(),
    1232                 :                                        ToFunctionType->getResultType(),
    1233                 :                                        ConvertedType, IncompatibleObjC)) {
    1234                 :       // Okay, we have an Objective-C pointer conversion.
    1235                6:       HasObjCConversion = true;
    1236                 :     } else {
    1237                 :       // Function types are too different. Abort.
    1238                0:       return false;
    1239                 :     }
    1240                 : 
    1241                 :     // Check argument types.
                        2: branch 1 taken
                        8: branch 2 taken
    1242               10:     for (unsigned ArgIdx = 0, NumArgs = FromFunctionType->getNumArgs();
    1243                 :          ArgIdx != NumArgs; ++ArgIdx) {
    1244                2:       QualType FromArgType = FromFunctionType->getArgType(ArgIdx);
    1245                2:       QualType ToArgType = ToFunctionType->getArgType(ArgIdx);
                        2: branch 3 taken
                        0: branch 4 not taken
    1246                2:       if (Context.getCanonicalType(FromArgType)
    1247                 :             == Context.getCanonicalType(ToArgType)) {
    1248                 :         // Okay, the types match exactly. Nothing to do.
                        2: branch 1 taken
                        0: branch 2 not taken
    1249                2:       } else if (isObjCPointerConversion(FromArgType, ToArgType,
    1250                 :                                          ConvertedType, IncompatibleObjC)) {
    1251                 :         // Okay, we have an Objective-C pointer conversion.
    1252                2:         HasObjCConversion = true;
    1253                 :       } else {
    1254                 :         // Argument types are too different. Abort.
    1255                0:         return false;
    1256                 :       }
    1257                 :     }
    1258                 : 
                        8: branch 0 taken
                        0: branch 1 not taken
    1259                8:     if (HasObjCConversion) {
    1260                 :       // We had an Objective-C conversion. Allow this pointer
    1261                 :       // conversion, but complain about it.
    1262                8:       ConvertedType = ToType;
    1263                8:       IncompatibleObjC = true;
    1264                8:       return true;
    1265                 :     }
    1266                 :   }
    1267                 : 
    1268               11:   return false;
    1269                 : }
    1270                 : 
    1271                 : /// CheckPointerConversion - Check the pointer conversion from the
    1272                 : /// expression From to the type ToType. This routine checks for
    1273                 : /// ambiguous or inaccessible derived-to-base pointer
    1274                 : /// conversions for which IsPointerConversion has already returned
    1275                 : /// true. It returns true and produces a diagnostic if there was an
    1276                 : /// error, or returns false otherwise.
    1277                 : bool Sema::CheckPointerConversion(Expr *From, QualType ToType,
    1278                 :                                   CastExpr::CastKind &Kind,
    1279              510:                                   bool IgnoreBaseAccess) {
    1280              510:   QualType FromType = From->getType();
    1281                 : 
                      127: branch 2 taken
                      383: branch 3 taken
    1282              510:   if (const PointerType *FromPtrType = FromType->getAs<PointerType>())
                      127: branch 2 taken
                        0: branch 3 not taken
    1283              127:     if (const PointerType *ToPtrType = ToType->getAs<PointerType>()) {
    1284              127:       QualType FromPointeeType = FromPtrType->getPointeeType(),
    1285              127:                ToPointeeType   = ToPtrType->getPointeeType();
    1286                 : 
                       79: branch 2 taken
                       48: branch 3 taken
                       68: branch 6 taken
                       11: branch 7 taken
                       68: branch 8 taken
                       59: branch 9 taken
    1287              127:       if (FromPointeeType->isRecordType() &&
    1288                 :           ToPointeeType->isRecordType()) {
    1289                 :         // We must have a derived-to-base conversion. Check an
    1290                 :         // ambiguous or inaccessible conversion.
                        8: branch 3 taken
                       60: branch 4 taken
    1291               68:         if (CheckDerivedToBaseConversion(FromPointeeType, ToPointeeType,
    1292                 :                                          From->getExprLoc(),
    1293                 :                                          From->getSourceRange(),
    1294                 :                                          IgnoreBaseAccess))
    1295                8:           return true;
    1296                 :         
    1297                 :         // The conversion was successful.
    1298               60:         Kind = CastExpr::CK_DerivedToBase;
    1299                 :       }
    1300                 :     }
                       32: branch 0 taken
                      470: branch 1 taken
    1301              502:   if (const ObjCObjectPointerType *FromPtrType =
    1302              502:         FromType->getAs<ObjCObjectPointerType>())
                       26: branch 0 taken
                        6: branch 1 taken
    1303               32:     if (const ObjCObjectPointerType *ToPtrType =
    1304               32:           ToType->getAs<ObjCObjectPointerType>()) {
    1305                 :       // Objective-C++ conversions are always okay.
    1306                 :       // FIXME: We should have a different class of conversions for the
    1307                 :       // Objective-C++ implicit conversions.
                       11: branch 1 taken
                       15: branch 2 taken
                        6: branch 4 taken
                        5: branch 5 taken
                       21: branch 6 taken
                        5: branch 7 taken
    1308               26:       if (FromPtrType->isObjCBuiltinType() || ToPtrType->isObjCBuiltinType())
    1309               21:         return false;
    1310                 : 
    1311                 :   }
    1312              481:   return false;
    1313                 : }
    1314                 : 
    1315                 : /// IsMemberPointerConversion - Determines whether the conversion of the
    1316                 : /// expression From, which has the (possibly adjusted) type FromType, can be
    1317                 : /// converted to the type ToType via a member pointer conversion (C++ 4.11).
    1318                 : /// If so, returns true and places the converted type (that might differ from
    1319                 : /// ToType in its cv-qualifiers at some level) into ConvertedType.
    1320                 : bool Sema::IsMemberPointerConversion(Expr *From, QualType FromType,
    1321                 :                                      QualType ToType, 
    1322                 :                                      bool InOverloadResolution,
    1323             4042:                                      QualType &ConvertedType) {
    1324             4042:   const MemberPointerType *ToTypePtr = ToType->getAs<MemberPointerType>();
                     3796: branch 0 taken
                      246: branch 1 taken
    1325             4042:   if (!ToTypePtr)
    1326             3796:     return false;
    1327                 : 
    1328                 :   // A null pointer constant can be converted to a member pointer (C++ 4.11p1)
                       24: branch 0 taken
                      222: branch 1 taken
                       77: branch 3 taken
                      169: branch 4 taken
    1329              246:   if (From->isNullPointerConstant(Context,
    1330                 :                     InOverloadResolution? Expr::NPC_ValueDependentIsNotNull
    1331                 :                                         : Expr::NPC_ValueDependentIsNull)) {
    1332               77:     ConvertedType = ToType;
    1333               77:     return true;
    1334                 :   }
    1335                 : 
    1336                 :   // Otherwise, both types have to be member pointers.
    1337              169:   const MemberPointerType *FromTypePtr = FromType->getAs<MemberPointerType>();
                        1: branch 0 taken
                      168: branch 1 taken
    1338              169:   if (!FromTypePtr)
    1339                1:     return false;
    1340                 : 
    1341                 :   // A pointer to member of B can be converted to a pointer to member of D,
    1342                 :   // where D is derived from B (C++ 4.11p2).
    1343              168:   QualType FromClass(FromTypePtr->getClass(), 0);
    1344              168:   QualType ToClass(ToTypePtr->getClass(), 0);
    1345                 :   // FIXME: What happens when these are dependent? Is this function even called?
    1346                 : 
                       76: branch 1 taken
                       92: branch 2 taken
    1347              168:   if (IsDerivedFrom(ToClass, FromClass)) {
    1348                 :     ConvertedType = Context.getMemberPointerType(FromTypePtr->getPointeeType(),
    1349               76:                                                  ToClass.getTypePtr());
    1350               76:     return true;
    1351                 :   }
    1352                 : 
    1353               92:   return false;
    1354                 : }
    1355                 :   
    1356                 : /// CheckMemberPointerConversion - Check the member pointer conversion from the
    1357                 : /// expression From to the type ToType. This routine checks for ambiguous or
    1358                 : /// virtual (FIXME: or inaccessible) base-to-derived member pointer conversions
    1359                 : /// for which IsMemberPointerConversion has already returned true. It returns
    1360                 : /// true and produces a diagnostic if there was an error, or returns false
    1361                 : /// otherwise.
    1362                 : bool Sema::CheckMemberPointerConversion(Expr *From, QualType ToType,
    1363                 :                                         CastExpr::CastKind &Kind,
    1364               82:                                         bool IgnoreBaseAccess) {
    1365                 :   (void)IgnoreBaseAccess;
    1366               82:   QualType FromType = From->getType();
    1367               82:   const MemberPointerType *FromPtrType = FromType->getAs<MemberPointerType>();
                       45: branch 0 taken
                       37: branch 1 taken
    1368               82:   if (!FromPtrType) {
    1369                 :     // This must be a null pointer to member pointer conversion
    1370                 :     assert(From->isNullPointerConstant(Context, 
    1371                 :                                        Expr::NPC_ValueDependentIsNull) &&
                       45: branch 1 taken
                        0: branch 2 not taken
    1372               45:            "Expr must be null pointer constant!");
    1373               45:     Kind = CastExpr::CK_NullToMemberPointer;
    1374               45:     return false;
    1375                 :   }
    1376                 : 
    1377               37:   const MemberPointerType *ToPtrType = ToType->getAs<MemberPointerType>();
    1378                 :   assert(ToPtrType && "No member pointer cast has a target type "
                        0: branch 0 not taken
                       37: branch 1 taken
    1379               37:                       "that is not a member pointer.");
    1380                 : 
    1381               37:   QualType FromClass = QualType(FromPtrType->getClass(), 0);
    1382               37:   QualType ToClass   = QualType(ToPtrType->getClass(), 0);
    1383                 : 
    1384                 :   // FIXME: What about dependent types?
                       37: branch 2 taken
                        0: branch 3 not taken
    1385               37:   assert(FromClass->isRecordType() && "Pointer into non-class.");
                       37: branch 2 taken
                        0: branch 3 not taken
    1386               37:   assert(ToClass->isRecordType() && "Pointer into non-class.");
    1387                 : 
    1388                 :   CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/false,
    1389               37:                      /*DetectVirtual=*/true);
    1390               37:   bool DerivationOkay = IsDerivedFrom(ToClass, FromClass, Paths);
    1391                 :   assert(DerivationOkay &&
                        0: branch 0 not taken
                       37: branch 1 taken
    1392               37:          "Should not have been called if derivation isn't OK.");
    1393                 :   (void)DerivationOkay;
    1394                 : 
                        5: branch 4 taken
                       32: branch 5 taken
    1395               37:   if (Paths.isAmbiguous(Context.getCanonicalType(FromClass).
    1396                 :                                   getUnqualifiedType())) {
    1397                 :     // Derivation is ambiguous. Redo the check to find the exact paths.
    1398                5:     Paths.clear();
    1399                5:     Paths.setRecordingPaths(true);
    1400                5:     bool StillOkay = IsDerivedFrom(ToClass, FromClass, Paths);
                        0: branch 0 not taken
                        5: branch 1 taken
    1401                5:     assert(StillOkay && "Derivation changed due to quantum fluctuation.");
    1402                 :     (void)StillOkay;
    1403                 : 
    1404                5:     std::string PathDisplayStr = getAmbiguousPathsDisplayString(Paths);
    1405                 :     Diag(From->getExprLoc(), diag::err_ambiguous_memptr_conv)
    1406                5:       << 0 << FromClass << ToClass << PathDisplayStr << From->getSourceRange();
    1407                5:     return true;
    1408                 :   }
    1409                 : 
                        3: branch 1 taken
                       29: branch 2 taken
    1410               32:   if (const RecordType *VBase = Paths.getDetectedVirtual()) {
    1411                 :     Diag(From->getExprLoc(), diag::err_memptr_conv_via_virtual)
    1412                 :       << FromClass << ToClass << QualType(VBase, 0)
    1413                3:       << From->getSourceRange();
    1414                3:     return true;
    1415                 :   }
    1416                 : 
    1417                 :   // Must be a base to derived member conversion.
    1418               29:   Kind = CastExpr::CK_BaseToDerivedMemberPointer;
    1419               29:   return false;
    1420                 : }
    1421                 : 
    1422                 : /// IsQualificationConversion - Determines whether the conversion from
    1423                 : /// an rvalue of type FromType to ToType is a qualification conversion
    1424                 : /// (C++ 4.4).
    1425                 : bool
    1426            34558: Sema::IsQualificationConversion(QualType FromType, QualType ToType) {
    1427            34558:   FromType = Context.getCanonicalType(FromType);
    1428            34558:   ToType = Context.getCanonicalType(ToType);
    1429                 : 
    1430                 :   // If FromType and ToType are the same type, this is not a
    1431                 :   // qualification conversion.
                    30688: branch 3 taken
                     3870: branch 4 taken
    1432            34558:   if (FromType.getUnqualifiedType() == ToType.getUnqualifiedType())
    1433            30688:     return false;
    1434                 : 
    1435                 :   // (C++ 4.4p4):
    1436                 :   //   A conversion can add cv-qualifiers at levels other than the first
    1437                 :   //   in multi-level pointers, subject to the following rules: [...]
    1438             3870:   bool PreviousToQualsIncludeConst = true;
    1439             3870:   bool UnwrappedAnyPointer = false;
                      678: branch 1 taken
                     3803: branch 2 taken
    1440             8351:   while (UnwrapSimilarPointerTypes(FromType, ToType)) {
    1441                 :     // Within each iteration of the loop, we check the qualifiers to
    1442                 :     // determine if this still looks like a qualification
    1443                 :     // conversion. Then, if all is well, we unwrap one more level of
    1444                 :     // pointers or pointers-to-members and do it all again
    1445                 :     // until there are no more pointers or pointers-to-members left to
    1446                 :     // unwrap.
    1447              678:     UnwrappedAnyPointer = true;
    1448                 : 
    1449                 :     //   -- for every j > 0, if const is in cv 1,j then const is in cv
    1450                 :     //      2,j, and similarly for volatile.
                       63: branch 1 taken
                      615: branch 2 taken
    1451              678:     if (!ToType.isAtLeastAsQualifiedAs(FromType))
    1452               63:       return false;
    1453                 : 
    1454                 :     //   -- if the cv 1,j and cv 2,j are different, then const is in
    1455                 :     //      every cv for 0 < k < j.
                      352: branch 2 taken
                      263: branch 3 taken
                        4: branch 4 taken
                      348: branch 5 taken
                        4: branch 6 taken
                      611: branch 7 taken
    1456              615:     if (FromType.getCVRQualifiers() != ToType.getCVRQualifiers()
    1457                 :         && !PreviousToQualsIncludeConst)
    1458                4:       return false;
    1459                 : 
    1460                 :     // Keep track of whether all prior cv-qualifiers in the "to" type
    1461                 :     // include const.
    1462                 :     PreviousToQualsIncludeConst
                      603: branch 0 taken
                        8: branch 1 taken
                      338: branch 3 taken
                      265: branch 4 taken
    1463              611:       = PreviousToQualsIncludeConst && ToType.isConstQualified();
    1464                 :   }
    1465                 : 
    1466                 :   // We are left with FromType and ToType being the pointee types
    1467                 :   // after unwrapping the original FromType and ToType the same number
    1468                 :   // of types. If we unwrapped any pointers, and if FromType and
    1469                 :   // ToType have the same unqualified type (since we checked
    1470                 :   // qualifiers above), then this is a qualification conversion.
                      564: branch 0 taken
                     3239: branch 1 taken
                      241: branch 3 taken
                      323: branch 4 taken
    1471             3803:   return UnwrappedAnyPointer && Context.hasSameUnqualifiedType(FromType,ToType);
    1472                 : }
    1473                 : 
    1474                 : /// Determines whether there is a user-defined conversion sequence
    1475                 : /// (C++ [over.ics.user]) that converts expression From to the type
    1476                 : /// ToType. If such a conversion exists, User will contain the
    1477                 : /// user-defined conversion sequence that performs such a conversion
    1478                 : /// and this routine will return true. Otherwise, this routine returns
    1479                 : /// false and User is unspecified.
    1480                 : ///
    1481                 : /// \param AllowConversionFunctions true if the conversion should
    1482                 : /// consider conversion functions at all. If false, only constructors
    1483                 : /// will be considered.
    1484                 : ///
    1485                 : /// \param AllowExplicit  true if the conversion should consider C++0x
    1486                 : /// "explicit" conversion functions as well as non-explicit conversion
    1487                 : /// functions (C++0x [class.conv.fct]p2).
    1488                 : ///
    1489                 : /// \param ForceRValue  true if the expression should be treated as an rvalue
    1490                 : /// for overload resolution.
    1491                 : /// \param UserCast true if looking for user defined conversion for a static
    1492                 : /// cast.
    1493                 : OverloadingResult Sema::IsUserDefinedConversion(Expr *From, QualType ToType,
    1494                 :                                           UserDefinedConversionSequence& User,
    1495                 :                                             OverloadCandidateSet& CandidateSet,
    1496                 :                                                 bool AllowConversionFunctions,
    1497                 :                                                 bool AllowExplicit, 
    1498                 :                                                 bool ForceRValue,
    1499            16799:                                                 bool UserCast) {
                      887: branch 2 taken
                    15912: branch 3 taken
    1500            16799:   if (const RecordType *ToRecordType = ToType->getAs<RecordType>()) {
                      886: branch 9 taken
                        1: branch 10 taken
    1501              887:     if (RequireCompleteType(From->getLocStart(), ToType, PDiag())) {
    1502                 :       // We're not going to find any constructors.
                      886: branch 0 taken
                        0: branch 1 not taken
    1503              886:     } else if (CXXRecordDecl *ToRecordDecl
    1504              886:                  = dyn_cast<CXXRecordDecl>(ToRecordType->getDecl())) {
    1505                 :       // C++ [over.match.ctor]p1:
    1506                 :       //   When objects of class type are direct-initialized (8.5), or
    1507                 :       //   copy-initialized from an expression of the same or a
    1508                 :       //   derived class type (8.5), overload resolution selects the
    1509                 :       //   constructor. [...] For copy-initialization, the candidate
    1510                 :       //   functions are all the converting constructors (12.3.1) of
    1511                 :       //   that class. The argument list is the expression-list within
    1512                 :       //   the parentheses of the initializer.
    1513              886:       bool SuppressUserConversions = !UserCast;
                      588: branch 2 taken
                      298: branch 3 taken
                       54: branch 6 taken
                      534: branch 7 taken
                      352: branch 8 taken
                      534: branch 9 taken
    1514              886:       if (Context.hasSameUnqualifiedType(ToType, From->getType()) ||
    1515                 :           IsDerivedFrom(From->getType(), ToType)) {
    1516              352:         SuppressUserConversions = false;
    1517              352:         AllowConversionFunctions = false;
    1518                 :       }
    1519                 :           
    1520                 :       DeclarationName ConstructorName
    1521                 :         = Context.DeclarationNames.getCXXConstructorName(
    1522              886:                           Context.getCanonicalType(ToType).getUnqualifiedType());
    1523                 :       DeclContext::lookup_iterator Con, ConEnd;
                     1902: branch 0 taken
                      886: branch 1 taken
    1524             2788:       for (llvm::tie(Con, ConEnd)
    1525              886:              = ToRecordDecl->lookup(ConstructorName);
    1526                 :            Con != ConEnd; ++Con) {
    1527                 :         // Find the constructor (which may be a template).
    1528             1902:         CXXConstructorDecl *Constructor = 0;
    1529                 :         FunctionTemplateDecl *ConstructorTmpl
    1530             1902:           = dyn_cast<FunctionTemplateDecl>(*Con);
                       49: branch 0 taken
                     1853: branch 1 taken
    1531             1902:         if (ConstructorTmpl)
    1532                 :           Constructor
    1533               49:             = cast<CXXConstructorDecl>(ConstructorTmpl->getTemplatedDecl());
    1534                 :         else
    1535             1853:           Constructor = cast<CXXConstructorDecl>(*Con);
    1536                 :         
                     1901: branch 1 taken
                        1: branch 2 taken
                     1234: branch 4 taken
                      667: branch 5 taken
                     1234: branch 6 taken
                      668: branch 7 taken
    1537             1902:         if (!Constructor->isInvalidDecl() &&
    1538                 :             Constructor->isConvertingConstructor(AllowExplicit)) {
                       25: branch 0 taken
                     1209: branch 1 taken
    1539             1234:           if (ConstructorTmpl)
    1540                 :             AddTemplateOverloadCandidate(ConstructorTmpl,
    1541                 :                                          ConstructorTmpl->getAccess(),
    1542                 :                                          /*ExplicitArgs*/ 0,
    1543                 :                                          &From, 1, CandidateSet, 
    1544               25:                                          SuppressUserConversions, ForceRValue);
    1545                 :           else
    1546                 :             // Allow one user-defined conversion when user specifies a
    1547                 :             // From->ToType conversion via an static cast (c-style, etc).
    1548                 :             AddOverloadCandidate(Constructor, Constructor->getAccess(),
    1549                 :                                  &From, 1, CandidateSet,
    1550             1209:                                  SuppressUserConversions, ForceRValue);
    1551                 :         }
    1552                 :       }
    1553                 :     }
    1554                 :   }
    1555                 : 
                    13320: branch 0 taken
                     3479: branch 1 taken
    1556            16799:   if (!AllowConversionFunctions) {
    1557                 :     // Don't allow any conversion functions to enter the overload set.
                    13233: branch 12 taken
                       87: branch 13 taken
    1558            13320:   } else if (RequireCompleteType(From->getLocStart(), From->getType(),
    1559                 :                                  PDiag(0)
    1560                 :                                    << From->getSourceRange())) {
    1561                 :     // No conversion functions from incomplete types.
                    12017: branch 0 taken
                     1216: branch 1 taken
    1562            13233:   } else if (const RecordType *FromRecordType
    1563            13233:                = From->getType()->getAs<RecordType>()) {
                    12017: branch 0 taken
                        0: branch 1 not taken
    1564            12017:     if (CXXRecordDecl *FromRecordDecl
    1565            12017:          = dyn_cast<CXXRecordDecl>(FromRecordType->getDecl())) {
    1566                 :       // Add all of the conversion functions as candidates.
    1567                 :       const UnresolvedSetImpl *Conversions
    1568            12017:         = FromRecordDecl->getVisibleConversionFunctions();
                     7792: branch 3 taken
                    12017: branch 4 taken
    1569            31826:       for (UnresolvedSetImpl::iterator I = Conversions->begin(),
    1570            12017:              E = Conversions->end(); I != E; ++I) {
    1571             7792:         NamedDecl *D = *I;
    1572             7792:         CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(D->getDeclContext());
                        0: branch 1 not taken
                     7792: branch 2 taken
    1573             7792:         if (isa<UsingShadowDecl>(D))
    1574                0:           D = cast<UsingShadowDecl>(D)->getTargetDecl();
    1575                 : 
    1576                 :         CXXConversionDecl *Conv;
    1577                 :         FunctionTemplateDecl *ConvTemplate;
                       93: branch 2 taken
                     7699: branch 3 taken
    1578             7792:         if ((ConvTemplate = dyn_cast<FunctionTemplateDecl>(*I)))
    1579               93:           Conv = dyn_cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl());
    1580                 :         else
    1581             7699:           Conv = dyn_cast<CXXConversionDecl>(*I);
    1582                 : 
                     7710: branch 0 taken
                       82: branch 1 taken
                     7707: branch 3 taken
                        3: branch 4 taken
                     7789: branch 5 taken
                        3: branch 6 taken
    1583             7792:         if (AllowExplicit || !Conv->isExplicit()) {
                       93: branch 0 taken
                     7696: branch 1 taken
    1584             7789:           if (ConvTemplate)
    1585                 :             AddTemplateConversionCandidate(ConvTemplate, I.getAccess(),
    1586                 :                                            ActingContext, From, ToType,
    1587               93:                                            CandidateSet);
    1588                 :           else
    1589                 :             AddConversionCandidate(Conv, I.getAccess(), ActingContext,
    1590             7696:                                    From, ToType, CandidateSet);
    1591                 :         }
    1592                 :       }
    1593                 :     }
    1594                 :   }
    1595                 : 
    1596                 :   OverloadCandidateSet::iterator Best;
                     5259: branch 2 taken
                    11514: branch 3 taken
                        0: branch 4 not taken
                       26: branch 5 taken
                        0: branch 6 not taken
    1597            16799:   switch (BestViableFunction(CandidateSet, From->getLocStart(), Best)) {
    1598                 :     case OR_Success:
    1599                 :       // Record the standard conversion we used and the conversion function.
                      566: branch 0 taken
                     4693: branch 1 taken
    1600             5259:       if (CXXConstructorDecl *Constructor
    1601             5259:             = dyn_cast<CXXConstructorDecl>(Best->Function)) {
    1602                 :         // C++ [over.ics.user]p1:
    1603                 :         //   If the user-defined conversion is specified by a
    1604                 :         //   constructor (12.3.1), the initial standard conversion
    1605                 :         //   sequence converts the source type to the type required by
    1606                 :         //   the argument of the constructor.
    1607                 :         //
    1608              566:         QualType ThisType = Constructor->getThisType(Context);
                        6: branch 2 taken
                      560: branch 3 taken
    1609              566:         if (Best->Conversions[0].isEllipsis())
    1610                6:           User.EllipsisConversion = true;
    1611                 :         else {
    1612              560:           User.Before = Best->Conversions[0].Standard;
    1613              560:           User.EllipsisConversion = false;
    1614                 :         }
    1615              566:         User.ConversionFunction = Constructor;
    1616              566:         User.After.setAsIdentityConversion();
    1617                 :         User.After.setFromType(
    1618              566:           ThisType->getAs<PointerType>()->getPointeeType());
    1619              566:         User.After.setAllToTypes(ToType);
    1620              566:         return OR_Success;
                     4693: branch 0 taken
                        0: branch 1 not taken
    1621             4693:       } else if (CXXConversionDecl *Conversion
    1622             4693:                    = dyn_cast<CXXConversionDecl>(Best->Function)) {
    1623                 :         // C++ [over.ics.user]p1:
    1624                 :         //
    1625                 :         //   [...] If the user-defined conversion is specified by a
    1626                 :         //   conversion function (12.3.2), the initial standard
    1627                 :         //   conversion sequence converts the source type to the
    1628                 :         //   implicit object parameter of the conversion function.
    1629             4693:         User.Before = Best->Conversions[0].Standard;
    1630             4693:         User.ConversionFunction = Conversion;
    1631             4693:         User.EllipsisConversion = false;
    1632                 : 
    1633                 :         // C++ [over.ics.user]p2:
    1634                 :         //   The second standard conversion sequence converts the
    1635                 :         //   result of the user-defined conversion to the target type
    1636                 :         //   for the sequence. Since an implicit conversion sequence
    1637                 :         //   is an initialization, the special rules for
    1638                 :         //   initialization by user-defined conversion apply when
    1639                 :         //   selecting the best user-defined conversion for a
    1640                 :         //   user-defined conversion sequence (see 13.3.3 and
    1641                 :         //   13.3.3.1).
    1642             4693:         User.After = Best->FinalConversion;
    1643             4693:         return OR_Success;
    1644                 :       } else {
    1645                0:         assert(false && "Not a constructor or conversion function?");
    1646                 :         return OR_No_Viable_Function;
    1647                 :       }
    1648                 : 
    1649                 :     case OR_No_Viable_Function:
    1650            11514:       return OR_No_Viable_Function;
    1651                 :     case OR_Deleted:
    1652                 :       // No conversion here! We're done.
    1653                0:       return OR_Deleted;
    1654                 : 
    1655                 :     case OR_Ambiguous:
    1656               26:       return OR_Ambiguous;
    1657                 :     }
    1658                 : 
    1659                0:   return OR_No_Viable_Function;
    1660                 : }
    1661                 :   
    1662                 : bool
    1663                7: Sema::DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType) {
    1664                7:   ImplicitConversionSequence ICS;
    1665                7:   OverloadCandidateSet CandidateSet(From->getExprLoc());
    1666                 :   OverloadingResult OvResult = 
    1667                 :     IsUserDefinedConversion(From, ToType, ICS.UserDefined,
    1668                7:                             CandidateSet, true, false, false);
                        0: branch 0 not taken
                        7: branch 1 taken
    1669                7:   if (OvResult == OR_Ambiguous)
    1670                 :     Diag(From->getSourceRange().getBegin(),
    1671                 :          diag::err_typecheck_ambiguous_condition)
    1672                0:           << From->getType() << ToType << From->getSourceRange();
                        7: branch 0 taken
                        0: branch 1 not taken
                        0: branch 3 not taken
                        7: branch 4 taken
                        0: branch 5 not taken
                        7: branch 6 taken
    1673                7:   else if (OvResult == OR_No_Viable_Function && !CandidateSet.empty())
    1674                 :     Diag(From->getSourceRange().getBegin(),
    1675                 :          diag::err_typecheck_nonviable_condition)
    1676                0:     << From->getType() << ToType << From->getSourceRange();
    1677                 :   else
    1678                7:     return false;
    1679                0:   PrintOverloadCandidates(CandidateSet, OCD_AllCandidates, &From, 1);
    1680                0:   return true;  
    1681                 : }
    1682                 : 
    1683                 : /// CompareImplicitConversionSequences - Compare two implicit
    1684                 : /// conversion sequences to determine whether one is better than the
    1685                 : /// other or if they are indistinguishable (C++ 13.3.3.2).
    1686                 : ImplicitConversionSequence::CompareKind
    1687                 : Sema::CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1,
    1688            53648:                                          const ImplicitConversionSequence& ICS2)
    1689                 : {
    1690                 :   // (C++ 13.3.3.2p2): When comparing the basic forms of implicit
    1691                 :   // conversion sequences (as defined in 13.3.3.1)
    1692                 :   //   -- a standard conversion sequence (13.3.3.1.1) is a better
    1693                 :   //      conversion sequence than a user-defined conversion sequence or
    1694                 :   //      an ellipsis conversion sequence, and
    1695                 :   //   -- a user-defined conversion sequence (13.3.3.1.2) is a better
    1696                 :   //      conversion sequence than an ellipsis conversion sequence
    1697                 :   //      (13.3.3.1.3).
    1698                 :   //
    1699                 :   // C++0x [over.best.ics]p10:
    1700                 :   //   For the purpose of ranking implicit conversion sequences as
    1701                 :   //   described in 13.3.3.2, the ambiguous conversion sequence is
    1702                 :   //   treated as a user-defined sequence that is indistinguishable
    1703                 :   //   from any other user-defined conversion sequence.
                     3336: branch 2 taken
                    50312: branch 3 taken
    1704            53648:   if (ICS1.getKind() < ICS2.getKind()) {
                       33: branch 1 taken
                     3303: branch 2 taken
                       25: branch 4 taken
                        8: branch 5 taken
                     3328: branch 6 taken
                        8: branch 7 taken
    1705             3336:     if (!(ICS1.isUserDefined() && ICS2.isAmbiguous()))
    1706             3328:       return ImplicitConversionSequence::Better;
                     1751: branch 2 taken
                    48561: branch 3 taken
    1707            50312:   } else if (ICS2.getKind() < ICS1.getKind()) {
                       25: branch 1 taken
                     1726: branch 2 taken
                       16: branch 4 taken
                        9: branch 5 taken
                     1742: branch 6 taken
                        9: branch 7 taken
    1708             1751:     if (!(ICS2.isUserDefined() && ICS1.isAmbiguous()))
    1709             1742:       return ImplicitConversionSequence::Worse;
    1710                 :   }
    1711                 : 
                    48543: branch 1 taken
                       35: branch 2 taken
                        8: branch 4 taken
                    48535: branch 5 taken
                       43: branch 6 taken
                    48535: branch 7 taken
    1712            48578:   if (ICS1.isAmbiguous() || ICS2.isAmbiguous())
    1713               43:     return ImplicitConversionSequence::Indistinguishable;
    1714                 : 
    1715                 :   // Two implicit conversion sequences of the same form are
    1716                 :   // indistinguishable conversion sequences unless one of the
    1717                 :   // following rules apply: (C++ 13.3.3.2p3):
                    25808: branch 1 taken
                    22727: branch 2 taken
    1718            48535:   if (ICS1.isStandard())
    1719            25808:     return CompareStandardConversionSequences(ICS1.Standard, ICS2.Standard);
                     3442: branch 1 taken
                    19285: branch 2 taken
    1720            22727:   else if (ICS1.isUserDefined()) {
    1721                 :     // User-defined conversion sequence U1 is a better conversion
    1722                 :     // sequence than another user-defined conversion sequence U2 if
    1723                 :     // they contain the same user-defined conversion function or
    1724                 :     // constructor and if the second standard conversion sequence of
    1725                 :     // U1 is better than the second standard conversion sequence of
    1726                 :     // U2 (C++ 13.3.3.2p3).
                     2679: branch 0 taken
                      763: branch 1 taken
    1727             3442:     if (ICS1.UserDefined.ConversionFunction ==
    1728                 :           ICS2.UserDefined.ConversionFunction)
    1729                 :       return CompareStandardConversionSequences(ICS1.UserDefined.After,
    1730             2679:                                                 ICS2.UserDefined.After);
    1731                 :   }
    1732                 : 
    1733            20048:   return ImplicitConversionSequence::Indistinguishable;
    1734                 : }
    1735                 : 
    1736                 : // Per 13.3.3.2p3, compare the given standard conversion sequences to
    1737                 : // determine if one is a proper subset of the other.
    1738                 : static ImplicitConversionSequence::CompareKind
    1739                 : compareStandardConversionSubsets(ASTContext &Context,
    1740                 :                                  const StandardConversionSequence& SCS1,
    1741            28627:                                  const StandardConversionSequence& SCS2) {
    1742                 :   ImplicitConversionSequence::CompareKind Result
    1743            28627:     = ImplicitConversionSequence::Indistinguishable;
    1744                 : 
                    21845: branch 0 taken
                     6782: branch 1 taken
    1745            28627:   if (SCS1.Second != SCS2.Second) {
                     5378: branch 0 taken
                    16467: branch 1 taken
    1746            21845:     if (SCS1.Second == ICK_Identity)
    1747             5378:       Result = ImplicitConversionSequence::Better;
                     2835: branch 0 taken
                    13632: branch 1 taken
    1748            16467:     else if (SCS2.Second == ICK_Identity)
    1749             2835:       Result = ImplicitConversionSequence::Worse;
    1750                 :     else
    1751            13632:       return ImplicitConversionSequence::Indistinguishable;
                     2496: branch 3 taken
                     4286: branch 4 taken
    1752             6782:   } else if (!Context.hasSameType(SCS1.getToType(1), SCS2.getToType(1)))
    1753             2496:     return ImplicitConversionSequence::Indistinguishable;
    1754                 : 
                    12331: branch 0 taken
                      168: branch 1 taken
    1755            12499:   if (SCS1.Third == SCS2.Third) {
    1756                 :     return Context.hasSameType(SCS1.getToType(2), SCS2.getToType(2))? Result
                     4099: branch 3 taken
                     8232: branch 4 taken
    1757            12331:                              : ImplicitConversionSequence::Indistinguishable;
    1758                 :   }
    1759                 : 
                      100: branch 0 taken
                       68: branch 1 taken
    1760              168:   if (SCS1.Third == ICK_Identity)
    1761                 :     return Result == ImplicitConversionSequence::Worse
    1762                 :              ? ImplicitConversionSequence::Indistinguishable
                        0: branch 0 not taken
                      100: branch 1 taken
    1763              100:              : ImplicitConversionSequence::Better;
    1764                 : 
                       68: branch 0 taken
                        0: branch 1 not taken
    1765               68:   if (SCS2.Third == ICK_Identity)
    1766                 :     return Result == ImplicitConversionSequence::Better
    1767                 :              ? ImplicitConversionSequence::Indistinguishable
                       64: branch 0 taken
                        4: branch 1 taken
    1768               68:              : ImplicitConversionSequence::Worse;
    1769                 :        
    1770                0:   return ImplicitConversionSequence::Indistinguishable;
    1771                 : }
    1772                 : 
    1773                 : /// CompareStandardConversionSequences - Compare two standard
    1774                 : /// conversion sequences to determine whether one is better than the
    1775                 : /// other or if they are indistinguishable (C++ 13.3.3.2p3).
    1776                 : ImplicitConversionSequence::CompareKind
    1777                 : Sema::CompareStandardConversionSequences(const StandardConversionSequence& SCS1,
    1778            28627:                                          const StandardConversionSequence& SCS2)
    1779                 : {
    1780                 :   // Standard conversion sequence S1 is a better conversion sequence
    1781                 :   // than standard conversion sequence S2 if (C++ 13.3.3.2p3):
    1782                 : 
    1783                 :   //  -- S1 is a proper subsequence of S2 (comparing the conversion
    1784                 :   //     sequences in the canonical form defined by 13.3.3.1.1,
    1785                 :   //     excluding any Lvalue Transformation; the identity conversion
    1786                 :   //     sequence is considered to be a subsequence of any
    1787                 :   //     non-identity conversion sequence) or, if not that,
                      196: branch 0 taken
                    28431: branch 1 taken
    1788            28627:   if (ImplicitConversionSequence::CompareKind CK
    1789            28627:         = compareStandardConversionSubsets(Context, SCS1, SCS2))
    1790              196:     return CK;
    1791                 : 
    1792                 :   //  -- the rank of S1 is better than the rank of S2 (by the rules
    1793                 :   //     defined below), or, if not that,
    1794            28431:   ImplicitConversionRank Rank1 = SCS1.getRank();
    1795            28431:   ImplicitConversionRank Rank2 = SCS2.getRank();
                    12997: branch 0 taken
                    15434: branch 1 taken
    1796            28431:   if (Rank1 < Rank2)
    1797            12997:     return ImplicitConversionSequence::Better;
                     7068: branch 0 taken
                     8366: branch 1 taken
    1798            15434:   else if (Rank2 < Rank1)
    1799             7068:     return ImplicitConversionSequence::Worse;
    1800                 : 
    1801                 :   // (C++ 13.3.3.2p4): Two conversion sequences with the same rank
    1802                 :   // are indistinguishable unless one of the following rules
    1803                 :   // applies:
    1804                 : 
    1805                 :   //   A conversion that is not a conversion of a pointer, or
    1806                 :   //   pointer to member, to bool is better than another conversion
    1807                 :   //   that is such a conversion.
                        2: branch 2 taken
                     8364: branch 3 taken
    1808             8366:   if (SCS1.isPointerConversionToBool() != SCS2.isPointerConversionToBool())
    1809                 :     return SCS2.isPointerConversionToBool()
    1810                 :              ? ImplicitConversionSequence::Better
                        2: branch 1 taken
                        0: branch 2 not taken
    1811                2:              : ImplicitConversionSequence::Worse;
    1812                 : 
    1813                 :   // C++ [over.ics.rank]p4b2:
    1814                 :   //
    1815                 :   //   If class B is derived directly or indirectly from class A,
    1816                 :   //   conversion of B* to A* is better than conversion of B* to
    1817                 :   //   void*, and conversion of A* to void* is better than conversion
    1818                 :   //   of B* to void*.
    1819                 :   bool SCS1ConvertsToVoid
    1820             8364:     = SCS1.isPointerConversionToVoidPointer(Context);
    1821                 :   bool SCS2ConvertsToVoid
    1822             8364:     = SCS2.isPointerConversionToVoidPointer(Context);
                        6: branch 0 taken
                     8358: branch 1 taken
    1823             8364:   if (SCS1ConvertsToVoid != SCS2ConvertsToVoid) {
    1824                 :     // Exactly one of the conversion sequences is a conversion to
    1825                 :     // a void pointer; it's the worse conversion.
    1826                 :     return SCS2ConvertsToVoid ? ImplicitConversionSequence::Better
                        5: branch 0 taken
                        1: branch 1 taken
    1827                6:                               : ImplicitConversionSequence::Worse;
                     8358: branch 0 taken
                        0: branch 1 not taken
                     8358: branch 2 taken
                        0: branch 3 not taken
    1828            16674:   } else if (!SCS1ConvertsToVoid && !SCS2ConvertsToVoid) {
    1829                 :     // Neither conversion sequence converts to a void pointer; compare
    1830                 :     // their derived-to-base conversions.
                       42: branch 0 taken
                     8316: branch 1 taken
    1831             8358:     if (ImplicitConversionSequence::CompareKind DerivedCK
    1832             8358:           = CompareDerivedToBaseConversions(SCS1, SCS2))
    1833               42:       return DerivedCK;
                        0: branch 0 not taken
                        0: branch 1 not taken
                        0: branch 2 not taken
                        0: branch 3 not taken
    1834                0:   } else if (SCS1ConvertsToVoid && SCS2ConvertsToVoid) {
    1835                 :     // Both conversion sequences are conversions to void
    1836                 :     // pointers. Compare the source types to determine if there's an
    1837                 :     // inheritance relationship in their sources.
    1838                0:     QualType FromType1 = SCS1.getFromType();
    1839                0:     QualType FromType2 = SCS2.getFromType();
    1840                 : 
    1841                 :     // Adjust the types we're converting from via the array-to-pointer
    1842                 :     // conversion, if we need to.
                        0: branch 0 not taken
                        0: branch 1 not taken
    1843                0:     if (SCS1.First == ICK_Array_To_Pointer)
    1844                0:       FromType1 = Context.getArrayDecayedType(FromType1);
                        0: branch 0 not taken
                        0: branch 1 not taken
    1845                0:     if (SCS2.First == ICK_Array_To_Pointer)
    1846                0:       FromType2 = Context.getArrayDecayedType(FromType2);
    1847                 : 
    1848                 :     QualType FromPointee1
    1849                0:       = FromType1->getAs<PointerType>()->getPointeeType().getUnqualifiedType();
    1850                 :     QualType FromPointee2
    1851                0:       = FromType2->getAs<PointerType>()->getPointeeType().getUnqualifiedType();
    1852                 : 
                        0: branch 1 not taken
                        0: branch 2 not taken
    1853                0:     if (IsDerivedFrom(FromPointee2, FromPointee1))
    1854                0:       return ImplicitConversionSequence::Better;
                        0: branch 1 not taken
                        0: branch 2 not taken
    1855                0:     else if (IsDerivedFrom(FromPointee1, FromPointee2))
    1856                0:       return ImplicitConversionSequence::Worse;
    1857                 : 
    1858                 :     // Objective-C++: If one interface is more specific than the
    1859                 :     // other, it is the better one.
    1860                0:     const ObjCInterfaceType* FromIface1 = FromPointee1->getAs<ObjCInterfaceType>();
    1861                0:     const ObjCInterfaceType* FromIface2 = FromPointee2->getAs<ObjCInterfaceType>();
                        0: branch 0 not taken
                        0: branch 1 not taken
                        0: branch 2 not taken
                        0: branch 3 not taken
    1862                0:     if (FromIface1 && FromIface1) {
                        0: branch 1 not taken
                        0: branch 2 not taken
    1863                0:       if (Context.canAssignObjCInterfaces(FromIface2, FromIface1))
    1864                0:         return ImplicitConversionSequence::Better;
                        0: branch 1 not taken
                        0: branch 2 not taken
    1865                0:       else if (Context.canAssignObjCInterfaces(FromIface1, FromIface2))
    1866                0:         return ImplicitConversionSequence::Worse;
    1867                 :     }
    1868                 :   }
    1869                 : 
    1870                 :   // Compare based on qualification conversions (C++ 13.3.3.2p3,
    1871                 :   // bullet 3).
                       32: branch 0 taken
                     8284: branch 1 taken
    1872             8316:   if (ImplicitConversionSequence::CompareKind QualCK
    1873             8316:         = CompareQualificationConversions(SCS1, SCS2))
    1874               32:     return QualCK;
    1875                 : 
                      551: branch 0 taken
                     7733: branch 1 taken
                      549: branch 2 taken
                        2: branch 3 taken
    1876             8284:   if (SCS1.ReferenceBinding && SCS2.ReferenceBinding) {
    1877                 :     // C++0x [over.ics.rank]p3b4:
    1878                 :     //   -- S1 and S2 are reference bindings (8.5.3) and neither refers to an
    1879                 :     //      implicit object parameter of a non-static member function declared
    1880                 :     //      without a ref-qualifier, and S1 binds an rvalue reference to an
    1881                 :     //      rvalue and S2 binds an lvalue reference.
    1882                 :     // FIXME: We don't know if we're dealing with the implicit object parameter,
    1883                 :     // or if the member function in this case has a ref qualifier.
    1884                 :     // (Of course, we don't have ref qualifiers yet.)
                        2: branch 0 taken
                      547: branch 1 taken
    1885              549:     if (SCS1.RRefBinding != SCS2.RRefBinding)
    1886                 :       return SCS1.RRefBinding ? ImplicitConversionSequence::Better
                        1: branch 0 taken
                        1: branch 1 taken
    1887                2:                               : ImplicitConversionSequence::Worse;
    1888                 : 
    1889                 :     // C++ [over.ics.rank]p3b4:
    1890                 :     //   -- S1 and S2 are reference bindings (8.5.3), and the types to
    1891                 :     //      which the references refer are the same type except for
    1892                 :     //      top-level cv-qualifiers, and the type to which the reference
    1893                 :     //      initialized by S2 refers is more cv-qualified than the type
    1894                 :     //      to which the reference initialized by S1 refers.
    1895              547:     QualType T1 = SCS1.getToType(2);
    1896              547:     QualType T2 = SCS2.getToType(2);
    1897              547:     T1 = Context.getCanonicalType(T1);
    1898              547:     T2 = Context.getCanonicalType(T2);
    1899              547:     Qualifiers T1Quals, T2Quals;
    1900              547:     QualType UnqualT1 = Context.getUnqualifiedArrayType(T1, T1Quals);
    1901              547:     QualType UnqualT2 = Context.getUnqualifiedArrayType(T2, T2Quals);
                      467: branch 1 taken
                       80: branch 2 taken
    1902              547:     if (UnqualT1 == UnqualT2) {
    1903                 :       // If the type is an array type, promote the element qualifiers to the type
    1904                 :       // for comparison.
                        0: branch 1 not taken
                      467: branch 2 taken
                        0: branch 4 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
                      467: branch 7 taken
    1905              467:       if (isa<ArrayType>(T1) && T1Quals)
    1906                0:         T1 = Context.getQualifiedType(UnqualT1, T1Quals);
                        0: branch 1 not taken
                      467: branch 2 taken
                        0: branch 4 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
                      467: branch 7 taken
    1907              467:       if (isa<ArrayType>(T2) && T2Quals)
    1908                0:         T2 = Context.getQualifiedType(UnqualT2, T2Quals);
                      108: branch 1 taken
                      359: branch 2 taken
    1909              467:       if (T2.isMoreQualifiedThan(T1))
    1910              108:         return ImplicitConversionSequence::Better;
                       78: branch 1 taken
                      281: branch 2 taken
    1911              359:       else if (T1.isMoreQualifiedThan(T2))
    1912               78:         return ImplicitConversionSequence::Worse;
    1913                 :     }
    1914                 :   }
    1915                 : 
    1916             8096:   return ImplicitConversionSequence::Indistinguishable;
    1917                 : }
    1918                 : 
    1919                 : /// CompareQualificationConversions - Compares two standard conversion
    1920                 : /// sequences to determine whether they can be ranked based on their
    1921                 : /// qualification conversions (C++ 13.3.3.2p3 bullet 3).
    1922                 : ImplicitConversionSequence::CompareKind
    1923                 : Sema::CompareQualificationConversions(const StandardConversionSequence& SCS1,
    1924             8316:                                       const StandardConversionSequence& SCS2) {
    1925                 :   // C++ 13.3.3.2p3:
    1926                 :   //  -- S1 and S2 differ only in their qualification conversion and
    1927                 :   //     yield similar types T1 and T2 (C++ 4.4), respectively, and the
    1928                 :   //     cv-qualification signature of type T1 is a proper subset of
    1929                 :   //     the cv-qualification signature of type T2, and S1 is not the
    1930                 :   //     deprecated string literal array-to-pointer conversion (4.2).
                     8310: branch 0 taken
                        6: branch 1 taken
                     6564: branch 2 taken
                     1746: branch 3 taken
                     6560: branch 4 taken
                        4: branch 5 taken
                     6493: branch 6 taken
                       67: branch 7 taken
    1931             8316:   if (SCS1.First != SCS2.First || SCS1.Second != SCS2.Second ||
    1932                 :       SCS1.Third != SCS2.Third || SCS1.Third != ICK_Qualification)
    1933             8249:     return ImplicitConversionSequence::Indistinguishable;
    1934                 : 
    1935                 :   // FIXME: the example in the standard doesn't use a qualification
    1936                 :   // conversion (!)
    1937               67:   QualType T1 = SCS1.getToType(2);
    1938               67:   QualType T2 = SCS2.getToType(2);
    1939               67:   T1 = Context.getCanonicalType(T1);
    1940               67:   T2 = Context.getCanonicalType(T2);
    1941               67:   Qualifiers T1Quals, T2Quals;
    1942               67:   QualType UnqualT1 = Context.getUnqualifiedArrayType(T1, T1Quals);
    1943               67:   QualType UnqualT2 = Context.getUnqualifiedArrayType(T2, T2Quals);
    1944                 : 
    1945                 :   // If the types are the same, we won't learn anything by unwrapped
    1946                 :   // them.
                       16: branch 1 taken
                       51: branch 2 taken
    1947               67:   if (UnqualT1 == UnqualT2)
    1948               16:     return ImplicitConversionSequence::Indistinguishable;
    1949                 : 
    1950                 :   // If the type is an array type, promote the element qualifiers to the type
    1951                 :   // for comparison.
                        0: branch 1 not taken
                       51: branch 2 taken
                        0: branch 4 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
                       51: branch 7 taken
    1952               51:   if (isa<ArrayType>(T1) && T1Quals)
    1953                0:     T1 = Context.getQualifiedType(UnqualT1, T1Quals);
                        0: branch 1 not taken
                       51: branch 2 taken
                        0: branch 4 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
                       51: branch 7 taken
    1954               51:   if (isa<ArrayType>(T2) && T2Quals)
    1955                0:     T2 = Context.getQualifiedType(UnqualT2, T2Quals);
    1956                 : 
    1957                 :   ImplicitConversionSequence::CompareKind Result
    1958               51:     = ImplicitConversionSequence::Indistinguishable;
                       57: branch 1 taken
                        0: branch 2 not taken
    1959              108:   while (UnwrapSimilarPointerTypes(T1, T2)) {
    1960                 :     // Within each iteration of the loop, we check the qualifiers to
    1961                 :     // determine if this still looks like a qualification
    1962                 :     // conversion. Then, if all is well, we unwrap one more level of
    1963                 :     // pointers or pointers-to-members and do it all again
    1964                 :     // until there are no more pointers or pointers-to-members left
    1965                 :     // to unwrap. This essentially mimics what
    1966                 :     // IsQualificationConversion does, but here we're checking for a
    1967                 :     // strict subset of qualifiers.
                       55: branch 2 taken
                        2: branch 3 taken
    1968               57:     if (T1.getCVRQualifiers() == T2.getCVRQualifiers())
    1969                 :       // The qualifiers are the same, so this doesn't tell us anything
    1970                 :       // about how the sequences rank.
    1971                 :       ;
                       33: branch 1 taken
                       22: branch 2 taken
    1972               55:     else if (T2.isMoreQualifiedThan(T1)) {
    1973                 :       // T1 has fewer qualifiers, so it could be the better sequence.
                        2: branch 0 taken
                       31: branch 1 taken
    1974               33:       if (Result == ImplicitConversionSequence::Worse)
    1975                 :         // Neither has qualifiers that are a subset of the other's
    1976                 :         // qualifiers.
    1977                2:         return ImplicitConversionSequence::Indistinguishable;
    1978                 : 
    1979               31:       Result = ImplicitConversionSequence::Better;
                        7: branch 1 taken
                       15: branch 2 taken
    1980               22:     } else if (T1.isMoreQualifiedThan(T2)) {
    1981                 :       // T2 has fewer qualifiers, so it could be the better sequence.
                        2: branch 0 taken
                        5: branch 1 taken
    1982                7:       if (Result == ImplicitConversionSequence::Better)
    1983                 :         // Neither has qualifiers that are a subset of the other's
    1984                 :         // qualifiers.
    1985                2:         return ImplicitConversionSequence::Indistinguishable;
    1986                 : 
    1987                5:       Result = ImplicitConversionSequence::Worse;
    1988                 :     } else {
    1989                 :       // Qualifiers are disjoint.
    1990               15:       return ImplicitConversionSequence::Indistinguishable;
    1991                 :     }
    1992                 : 
    1993                 :     // If the types after this point are equivalent, we're done.
                       32: branch 1 taken
                        6: branch 2 taken
    1994               38:     if (Context.hasSameUnqualifiedType(T1, T2))
    1995               32:       break;
    1996                 :   }
    1997                 : 
    1998                 :   // Check that the winning standard conversion sequence isn't using
    1999                 :   // the deprecated string literal array to pointer conversion.
                       29: branch 0 taken
                        0: branch 1 not taken
                        3: branch 2 taken
                        0: branch 3 not taken
    2000               32:   switch (Result) {
    2001                 :   case ImplicitConversionSequence::Better:
                        0: branch 0 not taken
                       29: branch 1 taken
    2002               29:     if (SCS1.Deprecated)
    2003                0:       Result = ImplicitConversionSequence::Indistinguishable;
    2004               29:     break;
    2005                 : 
    2006                 :   case ImplicitConversionSequence::Indistinguishable:
    2007                0:     break;
    2008                 : 
    2009                 :   case ImplicitConversionSequence::Worse:
                        0: branch 0 not taken
                        3: branch 1 taken
    2010                3:     if (SCS2.Deprecated)
    2011                0:       Result = ImplicitConversionSequence::Indistinguishable;
    2012                 :     break;
    2013                 :   }
    2014                 : 
    2015               32:   return Result;
    2016                 : }
    2017                 : 
    2018                 : /// CompareDerivedToBaseConversions - Compares two standard conversion
    2019                 : /// sequences to determine whether they can be ranked based on their
    2020                 : /// various kinds of derived-to-base conversions (C++
    2021                 : /// [over.ics.rank]p4b3).  As part of these checks, we also look at
    2022                 : /// conversions between Objective-C interface types.
    2023                 : ImplicitConversionSequence::CompareKind
    2024                 : Sema::CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1,
    2025             8358:                                       const StandardConversionSequence& SCS2) {
    2026             8358:   QualType FromType1 = SCS1.getFromType();
    2027             8358:   QualType ToType1 = SCS1.getToType(1);
    2028             8358:   QualType FromType2 = SCS2.getFromType();
    2029             8358:   QualType ToType2 = SCS2.getToType(1);
    2030                 : 
    2031                 :   // Adjust the types we're converting from via the array-to-pointer
    2032                 :   // conversion, if we need to.
                        0: branch 0 not taken
                     8358: branch 1 taken
    2033             8358:   if (SCS1.First == ICK_Array_To_Pointer)
    2034                0:     FromType1 = Context.getArrayDecayedType(FromType1);
                        0: branch 0 not taken
                     8358: branch 1 taken
    2035             8358:   if (SCS2.First == ICK_Array_To_Pointer)
    2036                0:     FromType2 = Context.getArrayDecayedType(FromType2);
    2037                 : 
    2038                 :   // Canonicalize all of the types.
    2039             8358:   FromType1 = Context.getCanonicalType(FromType1);
    2040             8358:   ToType1 = Context.getCanonicalType(ToType1);
    2041             8358:   FromType2 = Context.getCanonicalType(FromType2);
    2042             8358:   ToType2 = Context.getCanonicalType(ToType2);
    2043                 : 
    2044                 :   // C++ [over.ics.rank]p4b3:
    2045                 :   //
    2046                 :   //   If class B is derived directly or indirectly from class A and
    2047                 :   //   class C is derived directly or indirectly from B,
    2048                 :   //
    2049                 :   // For Objective-C, we let A, B, and C also be Objective-C
    2050                 :   // interfaces.
    2051                 : 
    2052                 :   // Compare based on pointer conversions.
                       38: branch 0 taken
                     8320: branch 1 taken
                       36: branch 2 taken
                        2: branch 3 taken
                        8: branch 6 taken
                       28: branch 7 taken
                        8: branch 10 taken
                        0: branch 11 not taken
                        8: branch 14 taken
                        0: branch 15 not taken
                        8: branch 18 taken
                        0: branch 19 not taken
                        8: branch 20 taken
                     8350: branch 21 taken
    2053             8358:   if (SCS1.Second == ICK_Pointer_Conversion &&
    2054                 :       SCS2.Second == ICK_Pointer_Conversion &&
    2055                 :       /*FIXME: Remove if Objective-C id conversions get their own rank*/
    2056                 :       FromType1->isPointerType() && FromType2->isPointerType() &&
    2057                 :       ToType1->isPointerType() && ToType2->isPointerType()) {
    2058                 :     QualType FromPointee1
    2059                8:       = FromType1->getAs<PointerType>()->getPointeeType().getUnqualifiedType();
    2060                 :     QualType ToPointee1
    2061                8:       = ToType1->getAs<PointerType>()->getPointeeType().getUnqualifiedType();
    2062                 :     QualType FromPointee2
    2063                8:       = FromType2->getAs<PointerType>()->getPointeeType().getUnqualifiedType();
    2064                 :     QualType ToPointee2
    2065                8:       = ToType2->getAs<PointerType>()->getPointeeType().getUnqualifiedType();
    2066                 : 
    2067                8:     const ObjCInterfaceType* FromIface1 = FromPointee1->getAs<ObjCInterfaceType>();
    2068                8:     const ObjCInterfaceType* FromIface2 = FromPointee2->getAs<ObjCInterfaceType>();
    2069                8:     const ObjCInterfaceType* ToIface1 = ToPointee1->getAs<ObjCInterfaceType>();
    2070                8:     const ObjCInterfaceType* ToIface2 = ToPointee2->getAs<ObjCInterfaceType>();
    2071                 : 
    2072                 :     //   -- conversion of C* to B* is better than conversion of C* to A*,
                        8: branch 1 taken
                        0: branch 2 not taken
                        8: branch 4 taken
                        0: branch 5 not taken
                        8: branch 6 taken
                        0: branch 7 not taken
    2073                8:     if (FromPointee1 == FromPointee2 && ToPointee1 != ToPointee2) {
                        4: branch 1 taken
                        4: branch 2 taken
    2074                8:       if (IsDerivedFrom(ToPointee1, ToPointee2))
    2075                4:         return ImplicitConversionSequence::Better;
                        4: branch 1 taken
                        0: branch 2 not taken
    2076                4:       else if (IsDerivedFrom(ToPointee2, ToPointee1))
    2077                4:         return ImplicitConversionSequence::Worse;
    2078                 : 
                        0: branch 0 not taken
                        0: branch 1 not taken
                        0: branch 2 not taken
                        0: branch 3 not taken
    2079                0:       if (ToIface1 && ToIface2) {
                        0: branch 1 not taken
                        0: branch 2 not taken
    2080                0:         if (Context.canAssignObjCInterfaces(ToIface2, ToIface1))
    2081                0:           return ImplicitConversionSequence::Better;
                        0: branch 1 not taken
                        0: branch 2 not taken
    2082                0:         else if (Context.canAssignObjCInterfaces(ToIface1, ToIface2))
    2083                0:           return ImplicitConversionSequence::Worse;
    2084                 :       }
    2085                 :     }
    2086                 : 
    2087                 :     //   -- conversion of B* to A* is better than conversion of C* to A*,
                        0: branch 1 not taken
                        0: branch 2 not taken
                        0: branch 4 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
                        0: branch 7 not taken
    2088                0:     if (FromPointee1 != FromPointee2 && ToPointee1 == ToPointee2) {
                        0: branch 1 not taken
                        0: branch 2 not taken
    2089                0:       if (IsDerivedFrom(FromPointee2, FromPointee1))
    2090                0:         return ImplicitConversionSequence::Better;
                        0: branch 1 not taken
                        0: branch 2 not taken
    2091                0:       else if (IsDerivedFrom(FromPointee1, FromPointee2))
    2092                0:         return ImplicitConversionSequence::Worse;
    2093                 : 
                        0: branch 0 not taken
                        0: branch 1 not taken
                        0: branch 2 not taken
                        0: branch 3 not taken
    2094                0:       if (FromIface1 && FromIface2) {
                        0: branch 1 not taken
                        0: branch 2 not taken
    2095                0:         if (Context.canAssignObjCInterfaces(FromIface1, FromIface2))
    2096                0:           return ImplicitConversionSequence::Better;
                        0: branch 1 not taken
                        0: branch 2 not taken
    2097                0:         else if (Context.canAssignObjCInterfaces(FromIface2, FromIface1))
    2098                0:           return ImplicitConversionSequence::Worse;
    2099                 :       }
    2100                 :     }
    2101                 :   }
    2102                 : 
    2103                 :   // Compare based on reference bindings.
                      559: branch 0 taken
                     7791: branch 1 taken
                      557: branch 2 taken
                        2: branch 3 taken
                       27: branch 4 taken
                      530: branch 5 taken
    2104             8350:   if (SCS1.ReferenceBinding && SCS2.ReferenceBinding &&
    2105                 :       SCS1.Second == ICK_Derived_To_Base) {
    2106                 :     //   -- binding of an expression of type C to a reference of type
    2107                 :     //      B& is better than binding an expression of type C to a
    2108                 :     //      reference of type A&,
                       23: branch 1 taken
                        4: branch 2 taken
                       14: branch 4 taken
                        9: branch 5 taken
                       14: branch 6 taken
                       13: branch 7 taken
    2109               27:     if (Context.hasSameUnqualifiedType(FromType1, FromType2) &&
    2110                 :         !Context.hasSameUnqualifiedType(ToType1, ToType2)) {
                        2: branch 1 taken
                       12: branch 2 taken
    2111               14:       if (IsDerivedFrom(ToType1, ToType2))
    2112                2:         return ImplicitConversionSequence::Better;
                        2: branch 1 taken
                       10: branch 2 taken
    2113               12:       else if (IsDerivedFrom(ToType2, ToType1))
    2114                2:         return ImplicitConversionSequence::Worse;
    2115                 :     }
    2116                 : 
    2117                 :     //   -- binding of an expression of type B to a reference of type
    2118                 :     //      A& is better than binding an expression of type C to a
    2119                 :     //      reference of type A&,
                        4: branch 1 taken
                       19: branch 2 taken
                        4: branch 4 taken
                        0: branch 5 not taken
                        4: branch 6 taken
                       19: branch 7 taken
    2120               23:     if (!Context.hasSameUnqualifiedType(FromType1, FromType2) &&
    2121                 :         Context.hasSameUnqualifiedType(ToType1, ToType2)) {
                        2: branch 1 taken
                        2: branch 2 taken
    2122                4:       if (IsDerivedFrom(FromType2, FromType1))
    2123                2:         return ImplicitConversionSequence::Better;
                        2: branch 1 taken
                        0: branch 2 not taken
    2124                2:       else if (IsDerivedFrom(FromType1, FromType2))
    2125                2:         return ImplicitConversionSequence::Worse;
    2126                 :     }
    2127                 :   }
    2128                 :   
    2129                 :   // Ranking of member-pointer types.
                       25: branch 0 taken
                     8317: branch 1 taken
                       23: branch 2 taken
                        2: branch 3 taken
                       16: branch 6 taken
                        7: branch 7 taken
                       16: branch 10 taken
                        0: branch 11 not taken
                       16: branch 14 taken
                        0: branch 15 not taken
                       16: branch 18 taken
                        0: branch 19 not taken
                       16: branch 20 taken
                     8326: branch 21 taken
    2130             8342:   if (SCS1.Second == ICK_Pointer_Member && SCS2.Second == ICK_Pointer_Member &&
    2131                 :       FromType1->isMemberPointerType() && FromType2->isMemberPointerType() &&
    2132                 :       ToType1->isMemberPointerType() && ToType2->isMemberPointerType()) {
    2133                 :     const MemberPointerType * FromMemPointer1 = 
    2134               16:                                         FromType1->getAs<MemberPointerType>();
    2135                 :     const MemberPointerType * ToMemPointer1 = 
    2136               16:                                           ToType1->getAs<MemberPointerType>();
    2137                 :     const MemberPointerType * FromMemPointer2 = 
    2138               16:                                           FromType2->getAs<MemberPointerType>();
    2139                 :     const MemberPointerType * ToMemPointer2 = 
    2140               16:                                           ToType2->getAs<MemberPointerType>();
    2141               16:     const Type *FromPointeeType1 = FromMemPointer1->getClass();
    2142               16:     const Type *ToPointeeType1 = ToMemPointer1->getClass();
    2143               16:     const Type *FromPointeeType2 = FromMemPointer2->getClass();
    2144               16:     const Type *ToPointeeType2 = ToMemPointer2->getClass();
    2145               16:     QualType FromPointee1 = QualType(FromPointeeType1, 0).getUnqualifiedType();
    2146               16:     QualType ToPointee1 = QualType(ToPointeeType1, 0).getUnqualifiedType();
    2147               16:     QualType FromPointee2 = QualType(FromPointeeType2, 0).getUnqualifiedType();
    2148               16:     QualType ToPointee2 = QualType(ToPointeeType2, 0).getUnqualifiedType();
    2149                 :     // conversion of A::* to B::* is better than conversion of A::* to C::*,
                        4: branch 1 taken
                       12: branch 2 taken
                        4: branch 4 taken
                        0: branch 5 not taken
                        4: branch 6 taken
                       12: branch 7 taken
    2150               16:     if (FromPointee1 == FromPointee2 && ToPointee1 != ToPointee2) {
                        1: branch 1 taken
                        3: branch 2 taken
    2151                4:       if (IsDerivedFrom(ToPointee1, ToPointee2))
    2152                1:         return ImplicitConversionSequence::Worse;
                        3: branch 1 taken
                        0: branch 2 not taken
    2153                3:       else if (IsDerivedFrom(ToPointee2, ToPointee1))
    2154                3:         return ImplicitConversionSequence::Better;
    2155                 :     }
    2156                 :     // conversion of B::* to C::* is better than conversion of A::* to C::*
                       12: branch 1 taken
                        0: branch 2 not taken
                       12: branch 4 taken
                        0: branch 5 not taken
                       12: branch 6 taken
                        0: branch 7 not taken
    2157               12:     if (ToPointee1 == ToPointee2 && FromPointee1 != FromPointee2) {
                       12: branch 1 taken
                        0: branch 2 not taken
    2158               12:       if (IsDerivedFrom(FromPointee1, FromPointee2))
    2159               12:         return ImplicitConversionSequence::Better;
                        0: branch 1 not taken
                        0: branch 2 not taken
    2160                0:       else if (IsDerivedFrom(FromPointee2, FromPointee1))
    2161                0:         return ImplicitConversionSequence::Worse;
    2162                 :     }
    2163                 :   }
    2164                 :   
                       46: branch 0 taken
                     8280: branch 1 taken
                       46: branch 2 taken
                        0: branch 3 not taken
                       24: branch 4 taken
                       22: branch 5 taken
    2165             8326:   if (SCS1.CopyConstructor && SCS2.CopyConstructor &&
    2166                 :       SCS1.Second == ICK_Derived_To_Base) {
    2167                 :     //   -- conversion of C to B is better than conversion of C to A,
                        2: branch 1 taken
                       22: branch 2 taken
                        2: branch 4 taken
                        0: branch 5 not taken
                        2: branch 6 taken
                       22: branch 7 taken
    2168               24:     if (Context.hasSameUnqualifiedType(FromType1, FromType2) &&
    2169                 :         !Context.hasSameUnqualifiedType(ToType1, ToType2)) {
                        1: branch 1 taken
                        1: branch 2 taken
    2170                2:       if (IsDerivedFrom(ToType1, ToType2))
    2171                1:         return ImplicitConversionSequence::Better;
                        1: branch 1 taken
                        0: branch 2 not taken
    2172                1:       else if (IsDerivedFrom(ToType2, ToType1))
    2173                1:         return ImplicitConversionSequence::Worse;
    2174                 :     }
    2175                 : 
    2176                 :     //   -- conversion of B to A is better than conversion of C to A.
                       22: branch 1 taken
                        0: branch 2 not taken
                       22: branch 4 taken
                        0: branch 5 not taken
                       22: branch 6 taken
                        0: branch 7 not taken
    2177               22:     if (!Context.hasSameUnqualifiedType(FromType1, FromType2) &&
    2178                 :         Context.hasSameUnqualifiedType(ToType1, ToType2)) {
                        4: branch 1 taken
                       18: branch 2 taken
    2179               22:       if (IsDerivedFrom(FromType2, FromType1))
    2180                4:         return ImplicitConversionSequence::Better;
                        4: branch 1 taken
                       14: branch 2 taken
    2181               18:       else if (IsDerivedFrom(FromType1, FromType2))
    2182                4:         return ImplicitConversionSequence::Worse;
    2183                 :     }
    2184                 :   }
    2185                 : 
    2186             8316:   return ImplicitConversionSequence::Indistinguishable;
    2187                 : }
    2188                 : 
    2189                 : /// TryCopyInitialization - Try to copy-initialize a value of type
    2190                 : /// ToType from the expression From. Return the implicit conversion
    2191                 : /// sequence required to pass this argument, which may be a bad
    2192                 : /// conversion sequence (meaning that the argument cannot be passed to
    2193                 : /// a parameter of this type). If @p SuppressUserConversions, then we
    2194                 : /// do not permit any user-defined conversion sequences. If @p ForceRValue,
    2195                 : /// then we treat @p From as an rvalue, even if it is an lvalue.
    2196                 : ImplicitConversionSequence
    2197                 : Sema::TryCopyInitialization(Expr *From, QualType ToType,
    2198                 :                             bool SuppressUserConversions, bool ForceRValue,
    2199            56200:                             bool InOverloadResolution) {
                    20630: branch 2 taken
                    35570: branch 3 taken
    2200            56200:   if (ToType->isReferenceType()) {
    2201            20630:     ImplicitConversionSequence ICS;
    2202            20630:     ICS.Bad.init(BadConversionSequence::no_conversion, From, ToType);
    2203                 :     CheckReferenceInit(From, ToType,
    2204                 :                        /*FIXME:*/From->getLocStart(),
    2205                 :                        SuppressUserConversions,
    2206                 :                        /*AllowExplicit=*/false,
    2207                 :                        ForceRValue,
    2208            20630:                        &ICS);
    2209            20630:     return ICS;
    2210                 :   } else {
    2211                 :     return TryImplicitConversion(From, ToType,
    2212                 :                                  SuppressUserConversions,
    2213                 :                                  /*AllowExplicit=*/false,
    2214                 :                                  ForceRValue,
    2215            35570:                                  InOverloadResolution);
    2216                 :   }
    2217                 : }
    2218                 : 
    2219                 : /// PerformCopyInitialization - Copy-initialize an object of type @p ToType with
    2220                 : /// the expression @p From. Returns true (and emits a diagnostic) if there was
    2221                 : /// an error, returns false if the initialization succeeded. Elidable should
    2222                 : /// be true when the copy may be elided (C++ 12.8p15). Overload resolution works
    2223                 : /// differently in C++0x for this case.
    2224                 : bool Sema::PerformCopyInitialization(Expr *&From, QualType ToType,
    2225              225:                                      AssignmentAction Action, bool Elidable) {
                        0: branch 1 not taken
                      225: branch 2 taken
    2226              225:   if (!getLangOptions().CPlusPlus) {
    2227                 :     // In C, argument passing is the same as performing an assignment.
    2228                0:     QualType FromType = From->getType();
    2229                 : 
    2230                 :     AssignConvertType ConvTy =
    2231                0:       CheckSingleAssignmentConstraints(ToType, From);
                        0: branch 0 not taken
                        0: branch 1 not taken
                        0: branch 3 not taken
                        0: branch 4 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
    2232                0:     if (ConvTy != Compatible &&
    2233                 :         CheckTransparentUnionArgumentConstraints(ToType, From) == Compatible)
    2234                0:       ConvTy = Compatible;
    2235                 : 
    2236                 :     return DiagnoseAssignmentResult(ConvTy, From->getLocStart(), ToType,
    2237                0:                                     FromType, From, Action);
    2238                 :   }
    2239                 : 
                        0: branch 2 not taken
                      225: branch 3 taken
    2240              225:   if (ToType->isReferenceType())
    2241                 :     return CheckReferenceInit(From, ToType,
    2242                 :                               /*FIXME:*/From->getLocStart(),
    2243                 :                               /*SuppressUserConversions=*/false,
    2244                 :                               /*AllowExplicit=*/false,
    2245                0:                               /*ForceRValue=*/false);
    2246                 : 
                      225: branch 1 taken
                        0: branch 2 not taken
    2247              225:   if (!PerformImplicitConversion(From, ToType, Action,
    2248                 :                                  /*AllowExplicit=*/false, Elidable))
    2249              225:     return false;
                        0: branch 1 not taken
                        0: branch 2 not taken
    2250                0:   if (!DiagnoseMultipleUserDefinedConversion(From, ToType))
    2251                 :     return Diag(From->getSourceRange().getBegin(),
    2252                 :                 diag::err_typecheck_convert_incompatible)
    2253                0:       << ToType << From->getType() << Action << From->getSourceRange();
    2254                0:   return true;
    2255                 : }
    2256                 : 
    2257                 : /// TryObjectArgumentInitialization - Try to initialize the object
    2258                 : /// parameter of the given member function (@c Method) from the
    2259                 : /// expression @p From.
    2260                 : ImplicitConversionSequence
    2261                 : Sema::TryObjectArgumentInitialization(QualType OrigFromType,
    2262                 :                                       CXXMethodDecl *Method,
    2263            10909:                                       CXXRecordDecl *ActingContext) {
    2264            10909:   QualType ClassType = Context.getTypeDeclType(ActingContext);
    2265                 :   // [class.dtor]p2: A destructor can be invoked for a const, volatile or
    2266                 :   //                 const volatile object.
    2267                 :   unsigned Quals = isa<CXXDestructorDecl>(Method) ?
                        9: branch 1 taken
                    10900: branch 2 taken
    2268            10909:     Qualifiers::Const | Qualifiers::Volatile : Method->getTypeQualifiers();
    2269            10909:   QualType ImplicitParamType =  Context.getCVRQualifiedType(ClassType, Quals);
    2270                 : 
    2271                 :   // Set up the conversion sequence as a "bad" conversion, to allow us
    2272                 :   // to exit early.
    2273            10909:   ImplicitConversionSequence ICS;
    2274            10909:   ICS.Standard.setAsIdentityConversion();
    2275            10909:   ICS.setBad();
    2276                 : 
    2277                 :   // We need to have an object of class type.
    2278            10909:   QualType FromType = OrigFromType;
                      342: branch 2 taken
                    10567: branch 3 taken
    2279            10909:   if (const PointerType *PT = FromType->getAs<PointerType>())
    2280              342:     FromType = PT->getPointeeType();
    2281                 : 
                        0: branch 2 not taken
                    10909: branch 3 taken
    2282            10909:   assert(FromType->isRecordType());
    2283                 : 
    2284                 :   // The implicit object parameter is has the type "reference to cv X",
    2285                 :   // where X is the class of which the function is a member
    2286                 :   // (C++ [over.match.funcs]p4). However, when finding an implicit
    2287                 :   // conversion sequence for the argument, we are not allowed to
    2288                 :   // create temporaries or perform user-defined conversions
    2289                 :   // (C++ [over.match.funcs]p5). We perform a simplified version of
    2290                 :   // reference binding here, that allows class rvalues to bind to
    2291                 :   // non-constant references.
    2292                 : 
    2293                 :   // First check the qualifiers. We don't care about lvalue-vs-rvalue
    2294                 :   // with the implicit object parameter (C++ [over.match.funcs]p5).
    2295            10909:   QualType FromTypeCanon = Context.getCanonicalType(FromType);
                     1539: branch 2 taken
                     9370: branch 3 taken
                       55: branch 5 taken
                     1484: branch 6 taken
                       55: branch 7 taken
                    10854: branch 8 taken
    2296            10909:   if (ImplicitParamType.getCVRQualifiers() 
    2297                 :                                     != FromTypeCanon.getLocalCVRQualifiers() &&
    2298                 :       !ImplicitParamType.isAtLeastAsQualifiedAs(FromTypeCanon)) {
    2299                 :     ICS.Bad.init(BadConversionSequence::bad_qualifiers,
    2300               55:                  OrigFromType, ImplicitParamType);
    2301               55:     return ICS;
    2302                 :   }
    2303                 : 
    2304                 :   // Check that we have either the same type or a derived type. It
    2305                 :   // affects the conversion rank.
    2306            10854:   QualType ClassTypeCanon = Context.getCanonicalType(ClassType);
                    10489: branch 2 taken
                      365: branch 3 taken
    2307            10854:   if (ClassTypeCanon == FromTypeCanon.getLocalUnqualifiedType())
    2308            10489:     ICS.Standard.Second = ICK_Identity;
                      364: branch 1 taken
                        1: branch 2 taken
    2309              365:   else if (IsDerivedFrom(FromType, ClassType))
    2310              364:     ICS.Standard.Second = ICK_Derived_To_Base;
    2311                 :   else {
    2312                1:     ICS.Bad.init(BadConversionSequence::unrelated_class, FromType, ImplicitParamType);
    2313                1:     return ICS;
    2314                 :   }
    2315                 : 
    2316                 :   // Success. Mark this as a reference binding.
    2317            10853:   ICS.setStandard();
    2318            10853:   ICS.Standard.setFromType(FromType);
    2319            10853:   ICS.Standard.setAllToTypes(ImplicitParamType);
    2320            10853:   ICS.Standard.ReferenceBinding = true;
    2321            10853:   ICS.Standard.DirectBinding = true;
    2322            10853:   ICS.Standard.RRefBinding = false;
    2323            10853:   return ICS;
    2324                 : }
    2325                 : 
    2326                 : /// PerformObjectArgumentInitialization - Perform initialization of
    2327                 : /// the implicit object parameter for the given Method with the given
    2328                 : /// expression.
    2329                 : bool
    2330             1092: Sema::PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method) {
    2331             1092:   QualType FromRecordType, DestType;
    2332                 :   QualType ImplicitParamRecordType  =
    2333             1092:     Method->getThisType(Context)->getAs<PointerType>()->getPointeeType();
    2334                 : 
                      209: branch 3 taken
                      883: branch 4 taken
    2335             1092:   if (const PointerType *PT = From->getType()->getAs<PointerType>()) {
    2336              209:     FromRecordType = PT->getPointeeType();
    2337              209:     DestType = Method->getThisType(Context);
    2338                 :   } else {
    2339              883:     FromRecordType = From->getType();
    2340              883:     DestType = ImplicitParamRecordType;
    2341                 :   }
    2342                 : 
    2343                 :   // Note that we always use the true parent context when performing
    2344                 :   // the actual argument initialization.
    2345                 :   ImplicitConversionSequence ICS
    2346                 :     = TryObjectArgumentInitialization(From->getType(), Method,
    2347             1092:                                       Method->getParent());
                        1: branch 1 taken
                     1091: branch 2 taken
    2348             1092:   if (ICS.isBad())
    2349                 :     return Diag(From->getSourceRange().getBegin(),
    2350                 :                 diag::err_implicit_object_parameter_init)
    2351                1:        << ImplicitParamRecordType << FromRecordType << From->getSourceRange();
    2352                 : 
                       82: branch 0 taken
                     1009: branch 1 taken
                        0: branch 6 not taken
                       82: branch 7 taken
                        0: branch 8 not taken
                     1091: branch 9 taken
    2353             1091:   if (ICS.Standard.Second == ICK_Derived_To_Base &&
    2354                 :       CheckDerivedToBaseConversion(FromRecordType,
    2355                 :                                    ImplicitParamRecordType,
    2356                 :                                    From->getSourceRange().getBegin(),
    2357                 :                                    From->getSourceRange()))
    2358                0:     return true;
    2359                 : 
    2360                 :   ImpCastExprToType(From, DestType, CastExpr::CK_DerivedToBase,
    2361             1091:                     /*isLvalue=*/true);
    2362             1091:   return false;
    2363                 : }
    2364                 : 
    2365                 : /// TryContextuallyConvertToBool - Attempt to contextually convert the
    2366                 : /// expression From to bool (C++0x [conv]p3).
    2367              880: ImplicitConversionSequence Sema::TryContextuallyConvertToBool(Expr *From) {
    2368                 :   return TryImplicitConversion(From, Context.BoolTy,
    2369                 :                                // FIXME: Are these flags correct?
    2370                 :                                /*SuppressUserConversions=*/false,
    2371                 :                                /*AllowExplicit=*/true,
    2372                 :                                /*ForceRValue=*/false,
    2373              880:                                /*InOverloadResolution=*/false);
    2374                 : }
    2375                 : 
    2376                 : /// PerformContextuallyConvertToBool - Perform a contextual conversion
    2377                 : /// of the expression From to bool (C++0x [conv]p3).
    2378              850: bool Sema::PerformContextuallyConvertToBool(Expr *&From) {
    2379              850:   ImplicitConversionSequence ICS = TryContextuallyConvertToBool(From);
                      843: branch 1 taken
                        7: branch 2 taken
    2380              850:   if (!ICS.isBad())
    2381              843:     return PerformImplicitConversion(From, Context.BoolTy, ICS, AA_Converting);
    2382                 :   
                        7: branch 2 taken
                        0: branch 3 not taken
    2383                7:   if (!DiagnoseMultipleUserDefinedConversion(From, Context.BoolTy))
    2384                 :     return  Diag(From->getSourceRange().getBegin(),
    2385                 :                  diag::err_typecheck_bool_condition)
    2386                7:                   << From->getType() << From->getSourceRange();
    2387                0:   return true;
    2388                 : }
    2389                 : 
    2390                 : /// AddOverloadCandidate - Adds the given function to the set of
    2391                 : /// candidate functions, using the given function call arguments.  If
    2392                 : /// @p SuppressUserConversions, then don't allow user-defined
    2393                 : /// conversions via constructors or conversion operators.
    2394                 : /// If @p ForceRValue, treat all arguments as rvalues. This is a slightly
    2395                 : /// hacky way to implement the overloading rules for elidable copy
    2396                 : /// initialization in C++0x (C++0x 12.8p15).
    2397                 : ///
    2398                 : /// \para PartialOverloading true if we are performing "partial" overloading
    2399                 : /// based on an incomplete set of function arguments. This feature is used by
    2400                 : /// code completion.
    2401                 : void
    2402                 : Sema::AddOverloadCandidate(FunctionDecl *Function,
    2403                 :                            AccessSpecifier Access,
    2404                 :                            Expr **Args, unsigned NumArgs,
    2405                 :                            OverloadCandidateSet& CandidateSet,
    2406                 :                            bool SuppressUserConversions,
    2407                 :                            bool ForceRValue,
    2408             7413:                            bool PartialOverloading) {
    2409                 :   const FunctionProtoType* Proto
    2410             7413:     = dyn_cast<FunctionProtoType>(Function->getType()->getAs<FunctionType>());
                        0: branch 0 not taken
                     7413: branch 1 taken
    2411             7413:   assert(Proto && "Functions without a prototype cannot be overloaded");
    2412                 :   assert(!Function->getDescribedFunctionTemplate() &&
                     7413: branch 1 taken
                        0: branch 2 not taken
    2413             7413:          "Use AddTemplateOverloadCandidate for function templates");
    2414                 : 
                     5382: branch 1 taken
                     2031: branch 2 taken
    2415             7413:   if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Function)) {
                       34: branch 1 taken
                     5348: branch 2 taken
    2416             5382:     if (!isa<CXXConstructorDecl>(Method)) {
    2417                 :       // If we get here, it's because we're calling a member function
    2418                 :       // that is named without a member access expression (e.g.,
    2419                 :       // "this->f") that was either written explicitly or created
    2420                 :       // implicitly. This can happen with a qualified call to a member
    2421                 :       // function, e.g., X::f(). We use an empty type for the implied
    2422                 :       // object argument (C++ [over.call.func]p3), and the acting context
    2423                 :       // is irrelevant.
    2424                 :       AddMethodCandidate(Method, Access, Method->getParent(),
    2425                 :                          QualType(), Args, NumArgs, CandidateSet,
    2426               34:                          SuppressUserConversions, ForceRValue);
    2427               34:       return;
    2428                 :     }
    2429                 :     // We treat a constructor like a non-member function, since its object
    2430                 :     // argument doesn't participate in overload resolution.
    2431                 :   }
    2432                 : 
                        0: branch 1 not taken
                     7379: branch 2 taken
    2433             7379:   if (!CandidateSet.isNewCandidate(Function))
    2434                0:     return;
    2435                 : 
    2436                 :   // Overload resolution is always an unevaluated context.
    2437             7379:   EnterExpressionEvaluationContext Unevaluated(*this, Action::Unevaluated);
    2438                 : 
                     5348: branch 1 taken
                     2031: branch 2 taken
    2439             7379:   if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(Function)){
    2440                 :     // C++ [class.copy]p3:
    2441                 :     //   A member function template is never instantiated to perform the copy
    2442                 :     //   of a class object to an object of its class type.
    2443             5348:     QualType ClassType = Context.getTypeDeclType(Constructor->getParent());
                     2602: branch 0 taken
                     2746: branch 1 taken
                        7: branch 3 taken
                     2595: branch 4 taken
                        7: branch 7 taken
                        0: branch 8 not taken
                        7: branch 9 taken
                     5341: branch 10 taken
    2444             5348:     if (NumArgs == 1 && 
    2445                 :         Constructor->isCopyConstructorLikeSpecialization() &&
    2446                 :         Context.hasSameUnqualifiedType(ClassType, Args[0]->getType()))
    2447             1926:       return;
    2448                 :   }
    2449                 :   
    2450                 :   // Add this candidate
    2451             7372:   CandidateSet.push_back(OverloadCandidate());
    2452             7372:   OverloadCandidate& Candidate = CandidateSet.back();
    2453             7372:   Candidate.Function = Function;
    2454             7372:   Candidate.Access = Access;
    2455             7372:   Candidate.Viable = true;
    2456             7372:   Candidate.IsSurrogate = false;
    2457             7372:   Candidate.IgnoreObjectArgument = false;
    2458                 : 
    2459             7372:   unsigned NumArgsInProto = Proto->getNumArgs();
    2460                 : 
    2461                 :   // (C++ 13.3.2p2): A candidate function having fewer than m
    2462                 :   // parameters is viable only if it has an ellipsis in its parameter
    2463                 :   // list (8.3.5).
                       15: branch 0 taken
                     7357: branch 1 taken
                       14: branch 2 taken
                        1: branch 3 taken
                      827: branch 4 taken
                     6545: branch 5 taken
                      503: branch 7 taken
                      324: branch 8 taken
                      503: branch 9 taken
                     6869: branch 10 taken
    2464             7372:   if ((NumArgs + (PartialOverloading && NumArgs)) > NumArgsInProto && 
    2465                 :       !Proto->isVariadic()) {
    2466              503:     Candidate.Viable = false;
    2467              503:     Candidate.FailureKind = ovl_fail_too_many_arguments;
    2468                 :     return;
    2469                 :   }
    2470                 : 
    2471                 :   // (C++ 13.3.2p2): A candidate function having more than m parameters
    2472                 :   // is viable only if the (m+1)st parameter has a default argument
    2473                 :   // (8.3.6). For the purposes of overload resolution, the
    2474                 :   // parameter list is truncated on the right, so that there are
    2475                 :   // exactly m parameters.
    2476             6869:   unsigned MinRequiredArgs = Function->getMinRequiredArguments();
                     1425: branch 0 taken
                     5444: branch 1 taken
                     1416: branch 2 taken
                        9: branch 3 taken
    2477             6869:   if (NumArgs < MinRequiredArgs && !PartialOverloading) {
    2478                 :     // Not enough arguments.
    2479             1416:     Candidate.Viable = false;
    2480             1416:     Candidate.FailureKind = ovl_fail_too_few_arguments;
    2481                 :     return;
    2482                 :   }
    2483                 : 
    2484                 :   // Determine the implicit conversion sequences for each of the
    2485                 :   // arguments.
    2486             5453:   Candidate.Conversions.resize(NumArgs);
                     4851: branch 0 taken
                     4474: branch 1 taken
    2487             9325:   for (unsigned ArgIdx = 0; ArgIdx < NumArgs; ++ArgIdx) {
                     4280: branch 0 taken
                      571: branch 1 taken
    2488             4851:     if (ArgIdx < NumArgsInProto) {
    2489                 :       // (C++ 13.3.2p3): for F to be a viable function, there shall
    2490                 :       // exist for each argument an implicit conversion sequence
    2491                 :       // (13.3.3.1) that converts that argument to the corresponding
    2492                 :       // parameter of F.
    2493             4280:       QualType ParamType = Proto->getArgType(ArgIdx);
    2494                 :       Candidate.Conversions[ArgIdx]
    2495                 :         = TryCopyInitialization(Args[ArgIdx], ParamType,
    2496                 :                                 SuppressUserConversions, ForceRValue,
    2497             4280:                                 /*InOverloadResolution=*/true);
                      979: branch 2 taken
                     3301: branch 3 taken
    2498             4280:       if (Candidate.Conversions[ArgIdx].isBad()) {
    2499              979:         Candidate.Viable = false;
    2500              979:         Candidate.FailureKind = ovl_fail_bad_conversion;
    2501              979:         break;
    2502                 :       }
    2503                 :     } else {
    2504                 :       // (C++ 13.3.2p2): For the purposes of overload resolution, any
    2505                 :       // argument for which there is no corresponding parameter is
    2506                 :       // considered to ""match the ellipsis" (C+ 13.3.3.1.3).
    2507              571:       Candidate.Conversions[ArgIdx].setEllipsis();
    2508                 :     }
                     5453: branch 1 taken
                     1926: branch 2 taken
    2509             7379:   }
    2510                 : }
    2511                 : 
    2512                 : /// \brief Add all of the function declarations in the given function set to
    2513                 : /// the overload canddiate set.
    2514                 : void Sema::AddFunctionCandidates(const UnresolvedSetImpl &Fns,
    2515                 :                                  Expr **Args, unsigned NumArgs,
    2516                 :                                  OverloadCandidateSet& CandidateSet,
    2517              401:                                  bool SuppressUserConversions) {
                       65: branch 4 taken
                      401: branch 5 taken
    2518              466:   for (UnresolvedSetIterator F = Fns.begin(), E = Fns.end(); F != E; ++F) {
    2519                 :     // FIXME: using declarations
                       63: branch 2 taken
                        2: branch 3 taken
    2520               65:     if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*F)) {
                        1: branch 1 taken
                       62: branch 2 taken
                        1: branch 5 taken
                        0: branch 6 not taken
                        1: branch 7 taken
                       62: branch 8 taken
    2521               63:       if (isa<CXXMethodDecl>(FD) && !cast<CXXMethodDecl>(FD)->isStatic())
    2522                 :         AddMethodCandidate(cast<CXXMethodDecl>(FD), F.getAccess(),
    2523                 :                            cast<CXXMethodDecl>(FD)->getParent(),
    2524                 :                            Args[0]->getType(), Args + 1, NumArgs - 1, 
    2525                1:                            CandidateSet, SuppressUserConversions);
    2526                 :       else
    2527                 :         AddOverloadCandidate(FD, AS_none, Args, NumArgs, CandidateSet,
    2528               62:                              SuppressUserConversions);
    2529                 :     } else {
    2530                2:       FunctionTemplateDecl *FunTmpl = cast<FunctionTemplateDecl>(*F);
                        0: branch 2 not taken
                        2: branch 3 taken
                        0: branch 7 not taken
                        0: branch 8 not taken
                        0: branch 9 not taken
                        2: branch 10 taken
    2531                2:       if (isa<CXXMethodDecl>(FunTmpl->getTemplatedDecl()) &&
    2532                 :           !cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl())->isStatic())
    2533                 :         AddMethodTemplateCandidate(FunTmpl, F.getAccess(),
    2534                 :                               cast<CXXRecordDecl>(FunTmpl->getDeclContext()),
    2535                 :                                    /*FIXME: explicit args */ 0,
    2536                 :                                    Args[0]->getType(), Args + 1, NumArgs - 1,
    2537                 :                                    CandidateSet,
    2538                0:                                    SuppressUserConversions);
    2539                 :       else
    2540                 :         AddTemplateOverloadCandidate(FunTmpl, AS_none,
    2541                 :                                      /*FIXME: explicit args */ 0,
    2542                 :                                      Args, NumArgs, CandidateSet,
    2543                2:                                      SuppressUserConversions);
    2544                 :     }
    2545                 :   }
    2546              401: }
    2547                 : 
    2548                 : /// AddMethodCandidate - Adds a named decl (which is some kind of
    2549                 : /// method) as a method candidate to the given overload set.
    2550                 : void Sema::AddMethodCandidate(NamedDecl *Decl,
    2551                 :                               AccessSpecifier Access,
    2552                 :                               QualType ObjectType,
    2553                 :                               Expr **Args, unsigned NumArgs,
    2554                 :                               OverloadCandidateSet& CandidateSet,
    2555              297:                               bool SuppressUserConversions, bool ForceRValue) {
    2556              297:   CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(Decl->getDeclContext());
    2557                 : 
                        2: branch 1 taken
                      295: branch 2 taken
    2558              297:   if (isa<UsingShadowDecl>(Decl))
    2559                2:     Decl = cast<UsingShadowDecl>(Decl)->getTargetDecl();
    2560                 :   
                        5: branch 1 taken
                      292: branch 2 taken
    2561              297:   if (FunctionTemplateDecl *TD = dyn_cast<FunctionTemplateDecl>(Decl)) {
    2562                 :     assert(isa<CXXMethodDecl>(TD->getTemplatedDecl()) &&
                        5: branch 2 taken
                        0: branch 3 not taken
    2563                5:            "Expected a member function template");
    2564                 :     AddMethodTemplateCandidate(TD, Access, ActingContext, /*ExplicitArgs*/ 0,
    2565                 :                                ObjectType, Args, NumArgs,
    2566                 :                                CandidateSet,
    2567                 :                                SuppressUserConversions,
    2568                5:                                ForceRValue);
    2569                 :   } else {
    2570                 :     AddMethodCandidate(cast<CXXMethodDecl>(Decl), Access, ActingContext,
    2571                 :                        ObjectType, Args, NumArgs,
    2572              292:                        CandidateSet, SuppressUserConversions, ForceRValue);
    2573                 :   }
    2574              297: }
    2575                 : 
    2576                 : /// AddMethodCandidate - Adds the given C++ member function to the set
    2577                 : /// of candidate functions, using the given function call arguments
    2578                 : /// and the object argument (@c Object). For example, in a call
    2579                 : /// @c o.f(a1,a2), @c Object will contain @c o and @c Args will contain
    2580                 : /// both @c a1 and @c a2. If @p SuppressUserConversions, then don't
    2581                 : /// allow user-defined conversions via constructors or conversion
    2582                 : /// operators. If @p ForceRValue, treat all arguments as rvalues. This is
    2583                 : /// a slightly hacky way to implement the overloading rules for elidable copy
    2584                 : /// initialization in C++0x (C++0x 12.8p15).
    2585                 : void
    2586                 : Sema::AddMethodCandidate(CXXMethodDecl *Method, AccessSpecifier Access,
    2587                 :                          CXXRecordDecl *ActingContext, QualType ObjectType,
    2588                 :                          Expr **Args, unsigned NumArgs,
    2589                 :                          OverloadCandidateSet& CandidateSet,
    2590              692:                          bool SuppressUserConversions, bool ForceRValue) {
    2591                 :   const FunctionProtoType* Proto
    2592              692:     = dyn_cast<FunctionProtoType>(Method->getType()->getAs<FunctionType>());
                        0: branch 0 not taken
                      692: branch 1 taken
    2593              692:   assert(Proto && "Methods without a prototype cannot be overloaded");
    2594                 :   assert(!isa<CXXConstructorDecl>(Method) &&
                      692: branch 1 taken
                        0: branch 2 not taken
    2595              692:          "Use AddOverloadCandidate for constructors");
    2596                 : 
                        1: branch 1 taken
                      691: branch 2 taken
    2597              692:   if (!CandidateSet.isNewCandidate(Method))
    2598                1:     return;
    2599                 : 
    2600                 :   // Overload resolution is always an unevaluated context.
    2601              691:   EnterExpressionEvaluationContext Unevaluated(*this, Action::Unevaluated);
    2602                 : 
    2603                 :   // Add this candidate
    2604              691:   CandidateSet.push_back(OverloadCandidate());
    2605              691:   OverloadCandidate& Candidate = CandidateSet.back();
    2606              691:   Candidate.Function = Method;
    2607              691:   Candidate.Access = Access;
    2608              691:   Candidate.IsSurrogate = false;
    2609              691:   Candidate.IgnoreObjectArgument = false;
    2610                 : 
    2611              691:   unsigned NumArgsInProto = Proto->getNumArgs();
    2612                 : 
    2613                 :   // (C++ 13.3.2p2): A candidate function having fewer than m
    2614                 :   // parameters is viable only if it has an ellipsis in its parameter
    2615                 :   // list (8.3.5).
                       21: branch 0 taken
                      670: branch 1 taken
                       16: branch 3 taken
                        5: branch 4 taken
                       16: branch 5 taken
                      675: branch 6 taken
    2616              691:   if (NumArgs > NumArgsInProto && !Proto->isVariadic()) {
    2617               16:     Candidate.Viable = false;
    2618               16:     Candidate.FailureKind = ovl_fail_too_many_arguments;
    2619               83:     return;
    2620                 :   }
    2621                 : 
    2622                 :   // (C++ 13.3.2p2): A candidate function having more than m parameters
    2623                 :   // is viable only if the (m+1)st parameter has a default argument
    2624                 :   // (8.3.6). For the purposes of overload resolution, the
    2625                 :   // parameter list is truncated on the right, so that there are
    2626                 :   // exactly m parameters.
    2627              675:   unsigned MinRequiredArgs = Method->getMinRequiredArguments();
                       13: branch 0 taken
                      662: branch 1 taken
    2628              675:   if (NumArgs < MinRequiredArgs) {
    2629                 :     // Not enough arguments.
    2630               13:     Candidate.Viable = false;
    2631               13:     Candidate.FailureKind = ovl_fail_too_few_arguments;
    2632                 :     return;
    2633                 :   }
    2634                 : 
    2635              662:   Candidate.Viable = true;
    2636              662:   Candidate.Conversions.resize(NumArgs + 1);
    2637                 : 
                      619: branch 1 taken
                       43: branch 2 taken
                        8: branch 4 taken
                      611: branch 5 taken
                       51: branch 6 taken
                      611: branch 7 taken
    2638              662:   if (Method->isStatic() || ObjectType.isNull())
    2639                 :     // The implicit object argument is ignored.
    2640               51:     Candidate.IgnoreObjectArgument = true;
    2641                 :   else {
    2642                 :     // Determine the implicit conversion sequence for the object
    2643                 :     // parameter.
    2644                 :     Candidate.Conversions[0]
    2645              611:       = TryObjectArgumentInitialization(ObjectType, Method, ActingContext);
                       54: branch 2 taken
                      557: branch 3 taken
    2646              611:     if (Candidate.Conversions[0].isBad()) {
    2647               54:       Candidate.Viable = false;
    2648               54:       Candidate.FailureKind = ovl_fail_bad_conversion;
    2649                 :       return;
    2650                 :     }
    2651                 :   }
    2652                 : 
    2653                 :   // Determine the implicit conversion sequences for each of the
    2654                 :   // arguments.
                      511: branch 0 taken
                      509: branch 1 taken
    2655             1020:   for (unsigned ArgIdx = 0; ArgIdx < NumArgs; ++ArgIdx) {
                      505: branch 0 taken
                        6: branch 1 taken
    2656              511:     if (ArgIdx < NumArgsInProto) {
    2657                 :       // (C++ 13.3.2p3): for F to be a viable function, there shall
    2658                 :       // exist for each argument an implicit conversion sequence
    2659                 :       // (13.3.3.1) that converts that argument to the corresponding
    2660                 :       // parameter of F.
    2661              505:       QualType ParamType = Proto->getArgType(ArgIdx);
    2662                 :       Candidate.Conversions[ArgIdx + 1]
    2663                 :         = TryCopyInitialization(Args[ArgIdx], ParamType,
    2664                 :                                 SuppressUserConversions, ForceRValue,
    2665              505:                                 /*InOverloadResolution=*/true);
                       99: branch 2 taken
                      406: branch 3 taken
    2666              505:       if (Candidate.Conversions[ArgIdx + 1].isBad()) {
    2667               99:         Candidate.Viable = false;
    2668               99:         Candidate.FailureKind = ovl_fail_bad_conversion;
    2669               99:         break;
    2670                 :       }
    2671                 :     } else {
    2672                 :       // (C++ 13.3.2p2): For the purposes of overload resolution, any
    2673                 :       // argument for which there is no corresponding parameter is
    2674                 :       // considered to ""match the ellipsis" (C+ 13.3.3.1.3).
    2675                6:       Candidate.Conversions[ArgIdx + 1].setEllipsis();
    2676                 :     }
                      608: branch 1 taken
                       83: branch 2 taken
    2677              691:   }
    2678                 : }
    2679                 : 
    2680                 : /// \brief Add a C++ member function template as a candidate to the candidate
    2681                 : /// set, using template argument deduction to produce an appropriate member
    2682                 : /// function template specialization.
    2683                 : void
    2684                 : Sema::AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
    2685                 :                                  AccessSpecifier Access,
    2686                 :                                  CXXRecordDecl *ActingContext,
    2687                 :                         const TemplateArgumentListInfo *ExplicitTemplateArgs,
    2688                 :                                  QualType ObjectType,
    2689                 :                                  Expr **Args, unsigned NumArgs,
    2690                 :                                  OverloadCandidateSet& CandidateSet,
    2691                 :                                  bool SuppressUserConversions,
    2692              100:                                  bool ForceRValue) {
                        0: branch 1 not taken
                      100: branch 2 taken
    2693              100:   if (!CandidateSet.isNewCandidate(MethodTmpl))
    2694                0:     return;
    2695                 : 
    2696                 :   // C++ [over.match.funcs]p7:
    2697                 :   //   In each case where a candidate is a function template, candidate
    2698                 :   //   function template specializations are generated using template argument
    2699                 :   //   deduction (14.8.3, 14.8.2). Those candidates are then handled as
    2700                 :   //   candidate functions in the usual way.113) A given name can refer to one
    2701                 :   //   or more function templates and also to a set of overloaded non-template
    2702                 :   //   functions. In such a case, the candidate functions generated from each
    2703                 :   //   function template are combined with the set of non-template candidate
    2704                 :   //   functions.
    2705              100:   TemplateDeductionInfo Info(Context, CandidateSet.getLocation());
    2706              100:   FunctionDecl *Specialization = 0;
                       20: branch 0 taken
                       80: branch 1 taken
    2707              100:   if (TemplateDeductionResult Result
    2708                 :       = DeduceTemplateArguments(MethodTmpl, ExplicitTemplateArgs,
    2709              100:                                 Args, NumArgs, Specialization, Info)) {
    2710                 :         // FIXME: Record what happened with template argument deduction, so
    2711                 :         // that we can give the user a beautiful diagnostic.
    2712                 :         (void)Result;
    2713               20:         return;
    2714                 :       }
    2715                 : 
    2716                 :   // Add the function template specialization produced by template argument
    2717                 :   // deduction as a candidate.
                        0: branch 0 not taken
                       80: branch 1 taken
    2718               80:   assert(Specialization && "Missing member function template specialization?");
    2719                 :   assert(isa<CXXMethodDecl>(Specialization) &&
                       80: branch 1 taken
                        0: branch 2 not taken
    2720               80:          "Specialization is not a member function?");
    2721                 :   AddMethodCandidate(cast<CXXMethodDecl>(Specialization), Access,
    2722                 :                      ActingContext, ObjectType, Args, NumArgs,
                       80: branch 3 taken
                       20: branch 4 taken
    2723              180:                      CandidateSet, SuppressUserConversions, ForceRValue);
    2724                 : }
    2725                 : 
    2726                 : /// \brief Add a C++ function template specialization as a candidate
    2727                 : /// in the candidate set, using template argument deduction to produce
    2728                 : /// an appropriate function template specialization.
    2729                 : void
    2730                 : Sema::AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
    2731                 :                                    AccessSpecifier Access,
    2732                 :                         const TemplateArgumentListInfo *ExplicitTemplateArgs,
    2733                 :                                    Expr **Args, unsigned NumArgs,
    2734                 :                                    OverloadCandidateSet& CandidateSet,
    2735                 :                                    bool SuppressUserConversions,
    2736              378:                                    bool ForceRValue) {
                        4: branch 1 taken
                      374: branch 2 taken
    2737              378:   if (!CandidateSet.isNewCandidate(FunctionTemplate))
    2738                4:     return;
    2739                 : 
    2740                 :   // C++ [over.match.funcs]p7:
    2741                 :   //   In each case where a candidate is a function template, candidate
    2742                 :   //   function template specializations are generated using template argument
    2743                 :   //   deduction (14.8.3, 14.8.2). Those candidates are then handled as
    2744                 :   //   candidate functions in the usual way.113) A given name can refer to one
    2745                 :   //   or more function templates and also to a set of overloaded non-template
    2746                 :   //   functions. In such a case, the candidate functions generated from each
    2747                 :   //   function template are combined with the set of non-template candidate
    2748                 :   //   functions.
    2749              374:   TemplateDeductionInfo Info(Context, CandidateSet.getLocation());
    2750              374:   FunctionDecl *Specialization = 0;
                       42: branch 0 taken
                      332: branch 1 taken
    2751              374:   if (TemplateDeductionResult Result
    2752                 :         = DeduceTemplateArguments(FunctionTemplate, ExplicitTemplateArgs,
    2753              374:                                   Args, NumArgs, Specialization, Info)) {
    2754               42:     CandidateSet.push_back(OverloadCandidate());
    2755               42:     OverloadCandidate &Candidate = CandidateSet.back();
    2756               42:     Candidate.Function = FunctionTemplate->getTemplatedDecl();
    2757               42:     Candidate.Access = Access;
    2758               42:     Candidate.Viable = false;
    2759               42:     Candidate.FailureKind = ovl_fail_bad_deduction;
    2760               42:     Candidate.IsSurrogate = false;
    2761               42:     Candidate.IgnoreObjectArgument = false;
    2762                 : 
    2763                 :     // TODO: record more information about failed template arguments
    2764               42:     Candidate.DeductionFailure.Result = Result;
    2765               42:     Candidate.DeductionFailure.TemplateParameter = Info.Param.getOpaqueValue();
    2766               42:     return;
    2767                 :   }
    2768                 : 
    2769                 :   // Add the function template specialization produced by template argument
    2770                 :   // deduction as a candidate.
                        0: branch 0 not taken
                      332: branch 1 taken
    2771              332:   assert(Specialization && "Missing function template specialization?");
    2772                 :   AddOverloadCandidate(Specialization, Access, Args, NumArgs, CandidateSet,
                      332: branch 2 taken
                       42: branch 3 taken
    2773              332:                        SuppressUserConversions, ForceRValue);
    2774                 : }
    2775                 : 
    2776                 : /// AddConversionCandidate - Add a C++ conversion function as a
    2777                 : /// candidate in the candidate set (C++ [over.match.conv],
    2778                 : /// C++ [over.match.copy]). From is the expression we're converting from,
    2779                 : /// and ToType is the type that we're eventually trying to convert to
    2780                 : /// (which may or may not be the same type as the type that the
    2781                 : /// conversion function produces).
    2782                 : void
    2783                 : Sema::AddConversionCandidate(CXXConversionDecl *Conversion,
    2784                 :                              AccessSpecifier Access,
    2785                 :                              CXXRecordDecl *ActingContext,
    2786                 :                              Expr *From, QualType ToType,
    2787             9164:                              OverloadCandidateSet& CandidateSet) {
    2788                 :   assert(!Conversion->getDescribedFunctionTemplate() &&
                     9164: branch 1 taken
                        0: branch 2 not taken
    2789             9164:          "Conversion function templates use AddTemplateConversionCandidate");
    2790                 : 
                        0: branch 1 not taken
                     9164: branch 2 taken
    2791             9164:   if (!CandidateSet.isNewCandidate(Conversion))
    2792                0:     return;
    2793                 : 
    2794                 :   // Overload resolution is always an unevaluated context.
    2795             9164:   EnterExpressionEvaluationContext Unevaluated(*this, Action::Unevaluated);
    2796                 : 
    2797                 :   // Add this candidate
    2798             9164:   CandidateSet.push_back(OverloadCandidate());
    2799             9164:   OverloadCandidate& Candidate = CandidateSet.back();
    2800             9164:   Candidate.Function = Conversion;
    2801             9164:   Candidate.Access = Access;
    2802             9164:   Candidate.IsSurrogate = false;
    2803             9164:   Candidate.IgnoreObjectArgument = false;
    2804             9164:   Candidate.FinalConversion.setAsIdentityConversion();
    2805             9164:   Candidate.FinalConversion.setFromType(Conversion->getConversionType());
    2806             9164:   Candidate.FinalConversion.setAllToTypes(ToType);
    2807                 : 
    2808                 :   // Determine the implicit conversion sequence for the implicit
    2809                 :   // object parameter.
    2810             9164:   Candidate.Viable = true;
    2811             9164:   Candidate.Conversions.resize(1);
    2812                 :   Candidate.Conversions[0]
    2813                 :     = TryObjectArgumentInitialization(From->getType(), Conversion,
    2814             9164:                                       ActingContext);
    2815                 :   // Conversion functions to a different type in the base class is visible in 
    2816                 :   // the derived class.  So, a derived to base conversion should not participate
    2817                 :   // in overload resolution. 
                      245: branch 1 taken
                     8919: branch 2 taken
    2818             9164:   if (Candidate.Conversions[0].Standard.Second == ICK_Derived_To_Base)
    2819              245:     Candidate.Conversions[0].Standard.Second = ICK_Identity;
                        1: branch 2 taken
                     9163: branch 3 taken
    2820             9164:   if (Candidate.Conversions[0].isBad()) {
    2821                1:     Candidate.Viable = false;
    2822                1:     Candidate.FailureKind = ovl_fail_bad_conversion;
    2823                1:     return;
    2824                 :   }
    2825                 :   
    2826                 :   // We won't go through a user-define type conversion function to convert a 
    2827                 :   // derived to base as such conversions are given Conversion Rank. They only
    2828                 :   // go through a copy constructor. 13.3.3.1.2-p4 [over.ics.user]
    2829                 :   QualType FromCanon
    2830             9163:     = Context.getCanonicalType(From->getType().getUnqualifiedType());
    2831             9163:   QualType ToCanon = Context.getCanonicalType(ToType).getUnqualifiedType();
                     9163: branch 1 taken
                        0: branch 2 not taken
                        0: branch 4 not taken
                     9163: branch 5 taken
                        0: branch 6 not taken
                     9163: branch 7 taken
    2832             9163:   if (FromCanon == ToCanon || IsDerivedFrom(FromCanon, ToCanon)) {
    2833                0:     Candidate.Viable = false;
    2834                0:     Candidate.FailureKind = ovl_fail_trivial_conversion;
    2835                 :     return;
    2836                 :   }
    2837                 :   
    2838                 : 
    2839                 :   // To determine what the conversion from the result of calling the
    2840                 :   // conversion function to the type we're eventually trying to
    2841                 :   // convert to (ToType), we need to synthesize a call to the
    2842                 :   // conversion function and attempt copy initialization from it. This
    2843                 :   // makes sure that we get the right semantics with respect to
    2844                 :   // lvalues/rvalues and the type. Fortunately, we can allocate this
    2845                 :   // call on the stack and we don't need its arguments to be
    2846                 :   // well-formed.
    2847                 :   DeclRefExpr ConversionRef(Conversion, Conversion->getType(),
    2848             9163:                             From->getLocStart());
    2849                 :   ImplicitCastExpr ConversionFn(Context.getPointerType(Conversion->getType()),
    2850                 :                                 CastExpr::CK_FunctionToPointerDecay,
    2851             9163:                                 &ConversionRef, false);
    2852                 : 
    2853                 :   // Note that it is safe to allocate CallExpr on the stack here because
    2854                 :   // there are 0 arguments (i.e., nothing is allocated using ASTContext's
    2855                 :   // allocator).
    2856                 :   CallExpr Call(Context, &ConversionFn, 0, 0,
    2857                 :                 Conversion->getConversionType().getNonReferenceType(),
    2858             9163:                 From->getLocStart());
    2859                 :   ImplicitConversionSequence ICS =
    2860                 :     TryCopyInitialization(&Call, ToType,
    2861                 :                           /*SuppressUserConversions=*/true,
    2862                 :                           /*ForceRValue=*/false,
    2863             9163:                           /*InOverloadResolution=*/false);
    2864                 : 
                     4952: branch 1 taken
                     4211: branch 2 taken
                        0: branch 3 not taken
    2865             9163:   switch (ICS.getKind()) {
    2866                 :   case ImplicitConversionSequence::StandardConversion:
    2867             4952:     Candidate.FinalConversion = ICS.Standard;
    2868             4952:     break;
    2869                 : 
    2870                 :   case ImplicitConversionSequence::BadConversion:
    2871             4211:     Candidate.Viable = false;
    2872             4211:     Candidate.FailureKind = ovl_fail_bad_final_conversion;
    2873             4211:     break;
    2874                 : 
    2875                 :   default:
    2876                 :     assert(false &&
    2877                0:            "Can only end up with a standard conversion sequence or failure");
                     9163: branch 5 taken
                        1: branch 6 taken
    2878             9163:   }
    2879                 : }
    2880                 : 
    2881                 : /// \brief Adds a conversion function template specialization
    2882                 : /// candidate to the overload set, using template argument deduction
    2883                 : /// to deduce the template arguments of the conversion function
    2884                 : /// template from the type that we are converting to (C++
    2885                 : /// [temp.deduct.conv]).
    2886                 : void
    2887                 : Sema::AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
    2888                 :                                      AccessSpecifier Access,
    2889                 :                                      CXXRecordDecl *ActingDC,
    2890                 :                                      Expr *From, QualType ToType,
    2891              106:                                      OverloadCandidateSet &CandidateSet) {
    2892                 :   assert(isa<CXXConversionDecl>(FunctionTemplate->getTemplatedDecl()) &&
                      106: branch 2 taken
                        0: branch 3 not taken
    2893              106:          "Only conversion function templates permitted here");
    2894                 : 
                        0: branch 1 not taken
                      106: branch 2 taken
    2895              106:   if (!CandidateSet.isNewCandidate(FunctionTemplate))
    2896                0:     return;
    2897                 : 
    2898              106:   TemplateDeductionInfo Info(Context, CandidateSet.getLocation());
    2899              106:   CXXConversionDecl *Specialization = 0;
                        2: branch 0 taken
                      104: branch 1 taken