Overload.h revision 78dd67e78c50a7abdc7c358e5eac1770d5fea22a
1//===--- Overload.h - 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 defines the data structures and types used in C++ 11// overload resolution. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_CLANG_SEMA_OVERLOAD_H 16#define LLVM_CLANG_SEMA_OVERLOAD_H 17 18#include "clang/AST/Decl.h" 19#include "clang/AST/DeclTemplate.h" 20#include "clang/AST/Expr.h" 21#include "clang/AST/TemplateBase.h" 22#include "clang/AST/Type.h" 23#include "clang/AST/UnresolvedSet.h" 24#include "clang/Sema/SemaFixItUtils.h" 25#include "llvm/ADT/SmallPtrSet.h" 26#include "llvm/ADT/SmallVector.h" 27 28namespace clang { 29 class ASTContext; 30 class CXXConstructorDecl; 31 class CXXConversionDecl; 32 class FunctionDecl; 33 class Sema; 34 35 /// OverloadingResult - Capture the result of performing overload 36 /// resolution. 37 enum OverloadingResult { 38 OR_Success, ///< Overload resolution succeeded. 39 OR_No_Viable_Function, ///< No viable function found. 40 OR_Ambiguous, ///< Ambiguous candidates found. 41 OR_Deleted ///< Succeeded, but refers to a deleted function. 42 }; 43 44 enum OverloadCandidateDisplayKind { 45 /// Requests that all candidates be shown. Viable candidates will 46 /// be printed first. 47 OCD_AllCandidates, 48 49 /// Requests that only viable candidates be shown. 50 OCD_ViableCandidates 51 }; 52 53 /// ImplicitConversionKind - The kind of implicit conversion used to 54 /// convert an argument to a parameter's type. The enumerator values 55 /// match with Table 9 of (C++ 13.3.3.1.1) and are listed such that 56 /// better conversion kinds have smaller values. 57 enum ImplicitConversionKind { 58 ICK_Identity = 0, ///< Identity conversion (no conversion) 59 ICK_Lvalue_To_Rvalue, ///< Lvalue-to-rvalue conversion (C++ 4.1) 60 ICK_Array_To_Pointer, ///< Array-to-pointer conversion (C++ 4.2) 61 ICK_Function_To_Pointer, ///< Function-to-pointer (C++ 4.3) 62 ICK_NoReturn_Adjustment, ///< Removal of noreturn from a type (Clang) 63 ICK_Qualification, ///< Qualification conversions (C++ 4.4) 64 ICK_Integral_Promotion, ///< Integral promotions (C++ 4.5) 65 ICK_Floating_Promotion, ///< Floating point promotions (C++ 4.6) 66 ICK_Complex_Promotion, ///< Complex promotions (Clang extension) 67 ICK_Integral_Conversion, ///< Integral conversions (C++ 4.7) 68 ICK_Floating_Conversion, ///< Floating point conversions (C++ 4.8) 69 ICK_Complex_Conversion, ///< Complex conversions (C99 6.3.1.6) 70 ICK_Floating_Integral, ///< Floating-integral conversions (C++ 4.9) 71 ICK_Pointer_Conversion, ///< Pointer conversions (C++ 4.10) 72 ICK_Pointer_Member, ///< Pointer-to-member conversions (C++ 4.11) 73 ICK_Boolean_Conversion, ///< Boolean conversions (C++ 4.12) 74 ICK_Compatible_Conversion, ///< Conversions between compatible types in C99 75 ICK_Derived_To_Base, ///< Derived-to-base (C++ [over.best.ics]) 76 ICK_Vector_Conversion, ///< Vector conversions 77 ICK_Vector_Splat, ///< A vector splat from an arithmetic type 78 ICK_Complex_Real, ///< Complex-real conversions (C99 6.3.1.7) 79 ICK_Block_Pointer_Conversion, ///< Block Pointer conversions 80 ICK_TransparentUnionConversion, /// Transparent Union Conversions 81 ICK_Writeback_Conversion, ///< Objective-C ARC writeback conversion 82 ICK_Num_Conversion_Kinds ///< The number of conversion kinds 83 }; 84 85 /// ImplicitConversionCategory - The category of an implicit 86 /// conversion kind. The enumerator values match with Table 9 of 87 /// (C++ 13.3.3.1.1) and are listed such that better conversion 88 /// categories have smaller values. 89 enum ImplicitConversionCategory { 90 ICC_Identity = 0, ///< Identity 91 ICC_Lvalue_Transformation, ///< Lvalue transformation 92 ICC_Qualification_Adjustment, ///< Qualification adjustment 93 ICC_Promotion, ///< Promotion 94 ICC_Conversion ///< Conversion 95 }; 96 97 ImplicitConversionCategory 98 GetConversionCategory(ImplicitConversionKind Kind); 99 100 /// ImplicitConversionRank - The rank of an implicit conversion 101 /// kind. The enumerator values match with Table 9 of (C++ 102 /// 13.3.3.1.1) and are listed such that better conversion ranks 103 /// have smaller values. 104 enum ImplicitConversionRank { 105 ICR_Exact_Match = 0, ///< Exact Match 106 ICR_Promotion, ///< Promotion 107 ICR_Conversion, ///< Conversion 108 ICR_Complex_Real_Conversion, ///< Complex <-> Real conversion 109 ICR_Writeback_Conversion ///< ObjC ARC writeback conversion 110 }; 111 112 ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind); 113 114 /// StandardConversionSequence - represents a standard conversion 115 /// sequence (C++ 13.3.3.1.1). A standard conversion sequence 116 /// contains between zero and three conversions. If a particular 117 /// conversion is not needed, it will be set to the identity conversion 118 /// (ICK_Identity). Note that the three conversions are 119 /// specified as separate members (rather than in an array) so that 120 /// we can keep the size of a standard conversion sequence to a 121 /// single word. 122 class StandardConversionSequence { 123 public: 124 /// First -- The first conversion can be an lvalue-to-rvalue 125 /// conversion, array-to-pointer conversion, or 126 /// function-to-pointer conversion. 127 ImplicitConversionKind First : 8; 128 129 /// Second - The second conversion can be an integral promotion, 130 /// floating point promotion, integral conversion, floating point 131 /// conversion, floating-integral conversion, pointer conversion, 132 /// pointer-to-member conversion, or boolean conversion. 133 ImplicitConversionKind Second : 8; 134 135 /// Third - The third conversion can be a qualification conversion. 136 ImplicitConversionKind Third : 8; 137 138 /// \brief Whether this is the deprecated conversion of a 139 /// string literal to a pointer to non-const character data 140 /// (C++ 4.2p2). 141 unsigned DeprecatedStringLiteralToCharPtr : 1; 142 143 /// \brief Whether the qualification conversion involves a change in the 144 /// Objective-C lifetime (for automatic reference counting). 145 unsigned QualificationIncludesObjCLifetime : 1; 146 147 /// IncompatibleObjC - Whether this is an Objective-C conversion 148 /// that we should warn about (if we actually use it). 149 unsigned IncompatibleObjC : 1; 150 151 /// ReferenceBinding - True when this is a reference binding 152 /// (C++ [over.ics.ref]). 153 unsigned ReferenceBinding : 1; 154 155 /// DirectBinding - True when this is a reference binding that is a 156 /// direct binding (C++ [dcl.init.ref]). 157 unsigned DirectBinding : 1; 158 159 /// \brief Whether this is an lvalue reference binding (otherwise, it's 160 /// an rvalue reference binding). 161 unsigned IsLvalueReference : 1; 162 163 /// \brief Whether we're binding to a function lvalue. 164 unsigned BindsToFunctionLvalue : 1; 165 166 /// \brief Whether we're binding to an rvalue. 167 unsigned BindsToRvalue : 1; 168 169 /// \brief Whether this binds an implicit object argument to a 170 /// non-static member function without a ref-qualifier. 171 unsigned BindsImplicitObjectArgumentWithoutRefQualifier : 1; 172 173 /// \brief Whether this binds a reference to an object with a different 174 /// Objective-C lifetime qualifier. 175 unsigned ObjCLifetimeConversionBinding : 1; 176 177 /// FromType - The type that this conversion is converting 178 /// from. This is an opaque pointer that can be translated into a 179 /// QualType. 180 void *FromTypePtr; 181 182 /// ToType - The types that this conversion is converting to in 183 /// each step. This is an opaque pointer that can be translated 184 /// into a QualType. 185 void *ToTypePtrs[3]; 186 187 /// CopyConstructor - The copy constructor that is used to perform 188 /// this conversion, when the conversion is actually just the 189 /// initialization of an object via copy constructor. Such 190 /// conversions are either identity conversions or derived-to-base 191 /// conversions. 192 CXXConstructorDecl *CopyConstructor; 193 194 void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); } 195 void setToType(unsigned Idx, QualType T) { 196 assert(Idx < 3 && "To type index is out of range"); 197 ToTypePtrs[Idx] = T.getAsOpaquePtr(); 198 } 199 void setAllToTypes(QualType T) { 200 ToTypePtrs[0] = T.getAsOpaquePtr(); 201 ToTypePtrs[1] = ToTypePtrs[0]; 202 ToTypePtrs[2] = ToTypePtrs[0]; 203 } 204 205 QualType getFromType() const { 206 return QualType::getFromOpaquePtr(FromTypePtr); 207 } 208 QualType getToType(unsigned Idx) const { 209 assert(Idx < 3 && "To type index is out of range"); 210 return QualType::getFromOpaquePtr(ToTypePtrs[Idx]); 211 } 212 213 void setAsIdentityConversion(); 214 215 bool isIdentityConversion() const { 216 return Second == ICK_Identity && Third == ICK_Identity; 217 } 218 219 ImplicitConversionRank getRank() const; 220 bool isPointerConversionToBool() const; 221 bool isPointerConversionToVoidPointer(ASTContext& Context) const; 222 void DebugPrint() const; 223 }; 224 225 /// UserDefinedConversionSequence - Represents a user-defined 226 /// conversion sequence (C++ 13.3.3.1.2). 227 struct UserDefinedConversionSequence { 228 /// Before - Represents the standard conversion that occurs before 229 /// the actual user-defined conversion. (C++ 13.3.3.1.2p1): 230 /// 231 /// If the user-defined conversion is specified by a constructor 232 /// (12.3.1), the initial standard conversion sequence converts 233 /// the source type to the type required by the argument of the 234 /// constructor. If the user-defined conversion is specified by 235 /// a conversion function (12.3.2), the initial standard 236 /// conversion sequence converts the source type to the implicit 237 /// object parameter of the conversion function. 238 StandardConversionSequence Before; 239 240 /// EllipsisConversion - When this is true, it means user-defined 241 /// conversion sequence starts with a ... (elipsis) conversion, instead of 242 /// a standard conversion. In this case, 'Before' field must be ignored. 243 // FIXME. I much rather put this as the first field. But there seems to be 244 // a gcc code gen. bug which causes a crash in a test. Putting it here seems 245 // to work around the crash. 246 bool EllipsisConversion : 1; 247 248 /// After - Represents the standard conversion that occurs after 249 /// the actual user-defined conversion. 250 StandardConversionSequence After; 251 252 /// ConversionFunction - The function that will perform the 253 /// user-defined conversion. 254 FunctionDecl* ConversionFunction; 255 256 /// \brief The declaration that we found via name lookup, which might be 257 /// the same as \c ConversionFunction or it might be a using declaration 258 /// that refers to \c ConversionFunction. 259 DeclAccessPair FoundConversionFunction; 260 261 void DebugPrint() const; 262 }; 263 264 /// Represents an ambiguous user-defined conversion sequence. 265 struct AmbiguousConversionSequence { 266 typedef SmallVector<FunctionDecl*, 4> ConversionSet; 267 268 void *FromTypePtr; 269 void *ToTypePtr; 270 char Buffer[sizeof(ConversionSet)]; 271 272 QualType getFromType() const { 273 return QualType::getFromOpaquePtr(FromTypePtr); 274 } 275 QualType getToType() const { 276 return QualType::getFromOpaquePtr(ToTypePtr); 277 } 278 void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); } 279 void setToType(QualType T) { ToTypePtr = T.getAsOpaquePtr(); } 280 281 ConversionSet &conversions() { 282 return *reinterpret_cast<ConversionSet*>(Buffer); 283 } 284 285 const ConversionSet &conversions() const { 286 return *reinterpret_cast<const ConversionSet*>(Buffer); 287 } 288 289 void addConversion(FunctionDecl *D) { 290 conversions().push_back(D); 291 } 292 293 typedef ConversionSet::iterator iterator; 294 iterator begin() { return conversions().begin(); } 295 iterator end() { return conversions().end(); } 296 297 typedef ConversionSet::const_iterator const_iterator; 298 const_iterator begin() const { return conversions().begin(); } 299 const_iterator end() const { return conversions().end(); } 300 301 void construct(); 302 void destruct(); 303 void copyFrom(const AmbiguousConversionSequence &); 304 }; 305 306 /// BadConversionSequence - Records information about an invalid 307 /// conversion sequence. 308 struct BadConversionSequence { 309 enum FailureKind { 310 no_conversion, 311 unrelated_class, 312 suppressed_user, 313 bad_qualifiers, 314 lvalue_ref_to_rvalue, 315 rvalue_ref_to_lvalue 316 }; 317 318 // This can be null, e.g. for implicit object arguments. 319 Expr *FromExpr; 320 321 FailureKind Kind; 322 323 private: 324 // The type we're converting from (an opaque QualType). 325 void *FromTy; 326 327 // The type we're converting to (an opaque QualType). 328 void *ToTy; 329 330 public: 331 void init(FailureKind K, Expr *From, QualType To) { 332 init(K, From->getType(), To); 333 FromExpr = From; 334 } 335 void init(FailureKind K, QualType From, QualType To) { 336 Kind = K; 337 FromExpr = 0; 338 setFromType(From); 339 setToType(To); 340 } 341 342 QualType getFromType() const { return QualType::getFromOpaquePtr(FromTy); } 343 QualType getToType() const { return QualType::getFromOpaquePtr(ToTy); } 344 345 void setFromExpr(Expr *E) { 346 FromExpr = E; 347 setFromType(E->getType()); 348 } 349 void setFromType(QualType T) { FromTy = T.getAsOpaquePtr(); } 350 void setToType(QualType T) { ToTy = T.getAsOpaquePtr(); } 351 }; 352 353 /// ImplicitConversionSequence - Represents an implicit conversion 354 /// sequence, which may be a standard conversion sequence 355 /// (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2), 356 /// or an ellipsis conversion sequence (C++ 13.3.3.1.3). 357 class ImplicitConversionSequence { 358 public: 359 /// Kind - The kind of implicit conversion sequence. BadConversion 360 /// specifies that there is no conversion from the source type to 361 /// the target type. AmbiguousConversion represents the unique 362 /// ambiguous conversion (C++0x [over.best.ics]p10). 363 enum Kind { 364 StandardConversion = 0, 365 UserDefinedConversion, 366 AmbiguousConversion, 367 EllipsisConversion, 368 BadConversion 369 }; 370 371 private: 372 enum { 373 Uninitialized = BadConversion + 1 374 }; 375 376 /// ConversionKind - The kind of implicit conversion sequence. 377 unsigned ConversionKind; 378 379 void setKind(Kind K) { 380 destruct(); 381 ConversionKind = K; 382 } 383 384 void destruct() { 385 if (ConversionKind == AmbiguousConversion) Ambiguous.destruct(); 386 } 387 388 public: 389 union { 390 /// When ConversionKind == StandardConversion, provides the 391 /// details of the standard conversion sequence. 392 StandardConversionSequence Standard; 393 394 /// When ConversionKind == UserDefinedConversion, provides the 395 /// details of the user-defined conversion sequence. 396 UserDefinedConversionSequence UserDefined; 397 398 /// When ConversionKind == AmbiguousConversion, provides the 399 /// details of the ambiguous conversion. 400 AmbiguousConversionSequence Ambiguous; 401 402 /// When ConversionKind == BadConversion, provides the details 403 /// of the bad conversion. 404 BadConversionSequence Bad; 405 }; 406 407 ImplicitConversionSequence() : ConversionKind(Uninitialized) {} 408 ~ImplicitConversionSequence() { 409 destruct(); 410 } 411 ImplicitConversionSequence(const ImplicitConversionSequence &Other) 412 : ConversionKind(Other.ConversionKind) 413 { 414 switch (ConversionKind) { 415 case Uninitialized: break; 416 case StandardConversion: Standard = Other.Standard; break; 417 case UserDefinedConversion: UserDefined = Other.UserDefined; break; 418 case AmbiguousConversion: Ambiguous.copyFrom(Other.Ambiguous); break; 419 case EllipsisConversion: break; 420 case BadConversion: Bad = Other.Bad; break; 421 } 422 } 423 424 ImplicitConversionSequence & 425 operator=(const ImplicitConversionSequence &Other) { 426 destruct(); 427 new (this) ImplicitConversionSequence(Other); 428 return *this; 429 } 430 431 Kind getKind() const { 432 assert(isInitialized() && "querying uninitialized conversion"); 433 return Kind(ConversionKind); 434 } 435 436 /// \brief Return a ranking of the implicit conversion sequence 437 /// kind, where smaller ranks represent better conversion 438 /// sequences. 439 /// 440 /// In particular, this routine gives user-defined conversion 441 /// sequences and ambiguous conversion sequences the same rank, 442 /// per C++ [over.best.ics]p10. 443 unsigned getKindRank() const { 444 switch (getKind()) { 445 case StandardConversion: 446 return 0; 447 448 case UserDefinedConversion: 449 case AmbiguousConversion: 450 return 1; 451 452 case EllipsisConversion: 453 return 2; 454 455 case BadConversion: 456 return 3; 457 } 458 459 return 3; 460 } 461 462 bool isBad() const { return getKind() == BadConversion; } 463 bool isStandard() const { return getKind() == StandardConversion; } 464 bool isEllipsis() const { return getKind() == EllipsisConversion; } 465 bool isAmbiguous() const { return getKind() == AmbiguousConversion; } 466 bool isUserDefined() const { return getKind() == UserDefinedConversion; } 467 bool isFailure() const { return isBad() || isAmbiguous(); } 468 469 /// Determines whether this conversion sequence has been 470 /// initialized. Most operations should never need to query 471 /// uninitialized conversions and should assert as above. 472 bool isInitialized() const { return ConversionKind != Uninitialized; } 473 474 /// Sets this sequence as a bad conversion for an explicit argument. 475 void setBad(BadConversionSequence::FailureKind Failure, 476 Expr *FromExpr, QualType ToType) { 477 setKind(BadConversion); 478 Bad.init(Failure, FromExpr, ToType); 479 } 480 481 /// Sets this sequence as a bad conversion for an implicit argument. 482 void setBad(BadConversionSequence::FailureKind Failure, 483 QualType FromType, QualType ToType) { 484 setKind(BadConversion); 485 Bad.init(Failure, FromType, ToType); 486 } 487 488 void setStandard() { setKind(StandardConversion); } 489 void setEllipsis() { setKind(EllipsisConversion); } 490 void setUserDefined() { setKind(UserDefinedConversion); } 491 void setAmbiguous() { 492 if (ConversionKind == AmbiguousConversion) return; 493 ConversionKind = AmbiguousConversion; 494 Ambiguous.construct(); 495 } 496 497 // The result of a comparison between implicit conversion 498 // sequences. Use Sema::CompareImplicitConversionSequences to 499 // actually perform the comparison. 500 enum CompareKind { 501 Better = -1, 502 Indistinguishable = 0, 503 Worse = 1 504 }; 505 506 void DiagnoseAmbiguousConversion(Sema &S, 507 SourceLocation CaretLoc, 508 const PartialDiagnostic &PDiag) const; 509 510 void DebugPrint() const; 511 }; 512 513 enum OverloadFailureKind { 514 ovl_fail_too_many_arguments, 515 ovl_fail_too_few_arguments, 516 ovl_fail_bad_conversion, 517 ovl_fail_bad_deduction, 518 519 /// This conversion candidate was not considered because it 520 /// duplicates the work of a trivial or derived-to-base 521 /// conversion. 522 ovl_fail_trivial_conversion, 523 524 /// This conversion candidate is not viable because its result 525 /// type is not implicitly convertible to the desired type. 526 ovl_fail_bad_final_conversion, 527 528 /// This conversion function template specialization candidate is not 529 /// viable because the final conversion was not an exact match. 530 ovl_fail_final_conversion_not_exact, 531 532 /// (CUDA) This candidate was not viable because the callee 533 /// was not accessible from the caller's target (i.e. host->device, 534 /// global->host, device->host). 535 ovl_fail_bad_target 536 }; 537 538 /// OverloadCandidate - A single candidate in an overload set (C++ 13.3). 539 struct OverloadCandidate { 540 /// Function - The actual function that this candidate 541 /// represents. When NULL, this is a built-in candidate 542 /// (C++ [over.oper]) or a surrogate for a conversion to a 543 /// function pointer or reference (C++ [over.call.object]). 544 FunctionDecl *Function; 545 546 /// FoundDecl - The original declaration that was looked up / 547 /// invented / otherwise found, together with its access. 548 /// Might be a UsingShadowDecl or a FunctionTemplateDecl. 549 DeclAccessPair FoundDecl; 550 551 // BuiltinTypes - Provides the return and parameter types of a 552 // built-in overload candidate. Only valid when Function is NULL. 553 struct { 554 QualType ResultTy; 555 QualType ParamTypes[3]; 556 } BuiltinTypes; 557 558 /// Surrogate - The conversion function for which this candidate 559 /// is a surrogate, but only if IsSurrogate is true. 560 CXXConversionDecl *Surrogate; 561 562 /// Conversions - The conversion sequences used to convert the 563 /// function arguments to the function parameters. 564 SmallVector<ImplicitConversionSequence, 4> Conversions; 565 566 /// The FixIt hints which can be used to fix the Bad candidate. 567 ConversionFixItGenerator Fix; 568 569 /// Viable - True to indicate that this overload candidate is viable. 570 bool Viable; 571 572 /// IsSurrogate - True to indicate that this candidate is a 573 /// surrogate for a conversion to a function pointer or reference 574 /// (C++ [over.call.object]). 575 bool IsSurrogate; 576 577 /// IgnoreObjectArgument - True to indicate that the first 578 /// argument's conversion, which for this function represents the 579 /// implicit object argument, should be ignored. This will be true 580 /// when the candidate is a static member function (where the 581 /// implicit object argument is just a placeholder) or a 582 /// non-static member function when the call doesn't have an 583 /// object argument. 584 bool IgnoreObjectArgument; 585 586 /// FailureKind - The reason why this candidate is not viable. 587 /// Actually an OverloadFailureKind. 588 unsigned char FailureKind; 589 590 /// \brief The number of call arguments that were explicitly provided, 591 /// to be used while performing partial ordering of function templates. 592 unsigned ExplicitCallArguments; 593 594 /// A structure used to record information about a failed 595 /// template argument deduction. 596 struct DeductionFailureInfo { 597 // A Sema::TemplateDeductionResult. 598 unsigned Result; 599 600 /// \brief Opaque pointer containing additional data about 601 /// this deduction failure. 602 void *Data; 603 604 /// \brief Retrieve the template parameter this deduction failure 605 /// refers to, if any. 606 TemplateParameter getTemplateParameter(); 607 608 /// \brief Retrieve the template argument list associated with this 609 /// deduction failure, if any. 610 TemplateArgumentList *getTemplateArgumentList(); 611 612 /// \brief Return the first template argument this deduction failure 613 /// refers to, if any. 614 const TemplateArgument *getFirstArg(); 615 616 /// \brief Return the second template argument this deduction failure 617 /// refers to, if any. 618 const TemplateArgument *getSecondArg(); 619 620 /// \brief Free any memory associated with this deduction failure. 621 void Destroy(); 622 }; 623 624 union { 625 DeductionFailureInfo DeductionFailure; 626 627 /// FinalConversion - For a conversion function (where Function is 628 /// a CXXConversionDecl), the standard conversion that occurs 629 /// after the call to the overload candidate to convert the result 630 /// of calling the conversion function to the required type. 631 StandardConversionSequence FinalConversion; 632 }; 633 634 /// hasAmbiguousConversion - Returns whether this overload 635 /// candidate requires an ambiguous conversion or not. 636 bool hasAmbiguousConversion() const { 637 for (SmallVectorImpl<ImplicitConversionSequence>::const_iterator 638 I = Conversions.begin(), E = Conversions.end(); I != E; ++I) { 639 if (!I->isInitialized()) return false; 640 if (I->isAmbiguous()) return true; 641 } 642 return false; 643 } 644 645 bool TryToFixBadConversion(unsigned Idx, Sema &S) { 646 bool CanFix = Fix.tryToFixConversion( 647 Conversions[Idx].Bad.FromExpr, 648 Conversions[Idx].Bad.getFromType(), 649 Conversions[Idx].Bad.getToType(), S); 650 651 // If at least one conversion fails, the candidate cannot be fixed. 652 if (!CanFix) 653 Fix.clear(); 654 655 return CanFix; 656 } 657 }; 658 659 /// OverloadCandidateSet - A set of overload candidates, used in C++ 660 /// overload resolution (C++ 13.3). 661 class OverloadCandidateSet : public SmallVector<OverloadCandidate, 16> { 662 typedef SmallVector<OverloadCandidate, 16> inherited; 663 llvm::SmallPtrSet<Decl *, 16> Functions; 664 665 SourceLocation Loc; 666 667 OverloadCandidateSet(const OverloadCandidateSet &); 668 OverloadCandidateSet &operator=(const OverloadCandidateSet &); 669 670 public: 671 OverloadCandidateSet(SourceLocation Loc) : Loc(Loc) {} 672 673 SourceLocation getLocation() const { return Loc; } 674 675 /// \brief Determine when this overload candidate will be new to the 676 /// overload set. 677 bool isNewCandidate(Decl *F) { 678 return Functions.insert(F->getCanonicalDecl()); 679 } 680 681 /// \brief Clear out all of the candidates. 682 void clear(); 683 684 /// Find the best viable function on this overload set, if it exists. 685 OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, 686 OverloadCandidateSet::iterator& Best, 687 bool UserDefinedConversion = false); 688 689 void NoteCandidates(Sema &S, 690 OverloadCandidateDisplayKind OCD, 691 Expr **Args, unsigned NumArgs, 692 const char *Opc = 0, 693 SourceLocation Loc = SourceLocation()); 694 }; 695 696 bool isBetterOverloadCandidate(Sema &S, 697 const OverloadCandidate& Cand1, 698 const OverloadCandidate& Cand2, 699 SourceLocation Loc, 700 bool UserDefinedConversion = false); 701} // end namespace clang 702 703#endif // LLVM_CLANG_SEMA_OVERLOAD_H 704