1 //===--- Overload.h - C++ Overloading ---------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the data structures and types used in C++
11 // overload resolution.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_SEMA_OVERLOAD_H
16 #define LLVM_CLANG_SEMA_OVERLOAD_H
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 #include "llvm/Support/Allocator.h"
31 class CXXConstructorDecl;
32 class CXXConversionDecl;
36 /// OverloadingResult - Capture the result of performing overload
38 enum OverloadingResult {
39 OR_Success, ///< Overload resolution succeeded.
40 OR_No_Viable_Function, ///< No viable function found.
41 OR_Ambiguous, ///< Ambiguous candidates found.
42 OR_Deleted ///< Succeeded, but refers to a deleted function.
45 enum OverloadCandidateDisplayKind {
46 /// Requests that all candidates be shown. Viable candidates will
50 /// Requests that only viable candidates be shown.
54 /// ImplicitConversionKind - The kind of implicit conversion used to
55 /// convert an argument to a parameter's type. The enumerator values
56 /// match with Table 9 of (C++ 13.3.3.1.1) and are listed such that
57 /// better conversion kinds have smaller values.
58 enum ImplicitConversionKind {
59 ICK_Identity = 0, ///< Identity conversion (no conversion)
60 ICK_Lvalue_To_Rvalue, ///< Lvalue-to-rvalue conversion (C++ 4.1)
61 ICK_Array_To_Pointer, ///< Array-to-pointer conversion (C++ 4.2)
62 ICK_Function_To_Pointer, ///< Function-to-pointer (C++ 4.3)
63 ICK_NoReturn_Adjustment, ///< Removal of noreturn from a type (Clang)
64 ICK_Qualification, ///< Qualification conversions (C++ 4.4)
65 ICK_Integral_Promotion, ///< Integral promotions (C++ 4.5)
66 ICK_Floating_Promotion, ///< Floating point promotions (C++ 4.6)
67 ICK_Complex_Promotion, ///< Complex promotions (Clang extension)
68 ICK_Integral_Conversion, ///< Integral conversions (C++ 4.7)
69 ICK_Floating_Conversion, ///< Floating point conversions (C++ 4.8)
70 ICK_Complex_Conversion, ///< Complex conversions (C99 6.3.1.6)
71 ICK_Floating_Integral, ///< Floating-integral conversions (C++ 4.9)
72 ICK_Pointer_Conversion, ///< Pointer conversions (C++ 4.10)
73 ICK_Pointer_Member, ///< Pointer-to-member conversions (C++ 4.11)
74 ICK_Boolean_Conversion, ///< Boolean conversions (C++ 4.12)
75 ICK_Compatible_Conversion, ///< Conversions between compatible types in C99
76 ICK_Derived_To_Base, ///< Derived-to-base (C++ [over.best.ics])
77 ICK_Vector_Conversion, ///< Vector conversions
78 ICK_Vector_Splat, ///< A vector splat from an arithmetic type
79 ICK_Complex_Real, ///< Complex-real conversions (C99 6.3.1.7)
80 ICK_Block_Pointer_Conversion, ///< Block Pointer conversions
81 ICK_TransparentUnionConversion, ///< Transparent Union Conversions
82 ICK_Writeback_Conversion, ///< Objective-C ARC writeback conversion
83 ICK_Zero_Event_Conversion, ///< Zero constant to event (OpenCL1.2 6.12.10)
84 ICK_Num_Conversion_Kinds ///< The number of conversion kinds
87 /// ImplicitConversionCategory - The category of an implicit
88 /// conversion kind. The enumerator values match with Table 9 of
89 /// (C++ 13.3.3.1.1) and are listed such that better conversion
90 /// categories have smaller values.
91 enum ImplicitConversionCategory {
92 ICC_Identity = 0, ///< Identity
93 ICC_Lvalue_Transformation, ///< Lvalue transformation
94 ICC_Qualification_Adjustment, ///< Qualification adjustment
95 ICC_Promotion, ///< Promotion
96 ICC_Conversion ///< Conversion
99 ImplicitConversionCategory
100 GetConversionCategory(ImplicitConversionKind Kind);
102 /// ImplicitConversionRank - The rank of an implicit conversion
103 /// kind. The enumerator values match with Table 9 of (C++
104 /// 13.3.3.1.1) and are listed such that better conversion ranks
105 /// have smaller values.
106 enum ImplicitConversionRank {
107 ICR_Exact_Match = 0, ///< Exact Match
108 ICR_Promotion, ///< Promotion
109 ICR_Conversion, ///< Conversion
110 ICR_Complex_Real_Conversion, ///< Complex <-> Real conversion
111 ICR_Writeback_Conversion ///< ObjC ARC writeback conversion
114 ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind);
116 /// NarrowingKind - The kind of narrowing conversion being performed by a
117 /// standard conversion sequence according to C++11 [dcl.init.list]p7.
119 /// Not a narrowing conversion.
122 /// A narrowing conversion by virtue of the source and destination types.
125 /// A narrowing conversion, because a constant expression got narrowed.
126 NK_Constant_Narrowing,
128 /// A narrowing conversion, because a non-constant-expression variable might
129 /// have got narrowed.
130 NK_Variable_Narrowing
133 /// StandardConversionSequence - represents a standard conversion
134 /// sequence (C++ 13.3.3.1.1). A standard conversion sequence
135 /// contains between zero and three conversions. If a particular
136 /// conversion is not needed, it will be set to the identity conversion
137 /// (ICK_Identity). Note that the three conversions are
138 /// specified as separate members (rather than in an array) so that
139 /// we can keep the size of a standard conversion sequence to a
141 class StandardConversionSequence {
143 /// First -- The first conversion can be an lvalue-to-rvalue
144 /// conversion, array-to-pointer conversion, or
145 /// function-to-pointer conversion.
146 ImplicitConversionKind First : 8;
148 /// Second - The second conversion can be an integral promotion,
149 /// floating point promotion, integral conversion, floating point
150 /// conversion, floating-integral conversion, pointer conversion,
151 /// pointer-to-member conversion, or boolean conversion.
152 ImplicitConversionKind Second : 8;
154 /// Third - The third conversion can be a qualification conversion.
155 ImplicitConversionKind Third : 8;
157 /// \brief Whether this is the deprecated conversion of a
158 /// string literal to a pointer to non-const character data
160 unsigned DeprecatedStringLiteralToCharPtr : 1;
162 /// \brief Whether the qualification conversion involves a change in the
163 /// Objective-C lifetime (for automatic reference counting).
164 unsigned QualificationIncludesObjCLifetime : 1;
166 /// IncompatibleObjC - Whether this is an Objective-C conversion
167 /// that we should warn about (if we actually use it).
168 unsigned IncompatibleObjC : 1;
170 /// ReferenceBinding - True when this is a reference binding
171 /// (C++ [over.ics.ref]).
172 unsigned ReferenceBinding : 1;
174 /// DirectBinding - True when this is a reference binding that is a
175 /// direct binding (C++ [dcl.init.ref]).
176 unsigned DirectBinding : 1;
178 /// \brief Whether this is an lvalue reference binding (otherwise, it's
179 /// an rvalue reference binding).
180 unsigned IsLvalueReference : 1;
182 /// \brief Whether we're binding to a function lvalue.
183 unsigned BindsToFunctionLvalue : 1;
185 /// \brief Whether we're binding to an rvalue.
186 unsigned BindsToRvalue : 1;
188 /// \brief Whether this binds an implicit object argument to a
189 /// non-static member function without a ref-qualifier.
190 unsigned BindsImplicitObjectArgumentWithoutRefQualifier : 1;
192 /// \brief Whether this binds a reference to an object with a different
193 /// Objective-C lifetime qualifier.
194 unsigned ObjCLifetimeConversionBinding : 1;
196 /// FromType - The type that this conversion is converting
197 /// from. This is an opaque pointer that can be translated into a
201 /// ToType - The types that this conversion is converting to in
202 /// each step. This is an opaque pointer that can be translated
206 /// CopyConstructor - The copy constructor that is used to perform
207 /// this conversion, when the conversion is actually just the
208 /// initialization of an object via copy constructor. Such
209 /// conversions are either identity conversions or derived-to-base
211 CXXConstructorDecl *CopyConstructor;
213 void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
214 void setToType(unsigned Idx, QualType T) {
215 assert(Idx < 3 && "To type index is out of range");
216 ToTypePtrs[Idx] = T.getAsOpaquePtr();
218 void setAllToTypes(QualType T) {
219 ToTypePtrs[0] = T.getAsOpaquePtr();
220 ToTypePtrs[1] = ToTypePtrs[0];
221 ToTypePtrs[2] = ToTypePtrs[0];
224 QualType getFromType() const {
225 return QualType::getFromOpaquePtr(FromTypePtr);
227 QualType getToType(unsigned Idx) const {
228 assert(Idx < 3 && "To type index is out of range");
229 return QualType::getFromOpaquePtr(ToTypePtrs[Idx]);
232 void setAsIdentityConversion();
234 bool isIdentityConversion() const {
235 return Second == ICK_Identity && Third == ICK_Identity;
238 ImplicitConversionRank getRank() const;
239 NarrowingKind getNarrowingKind(ASTContext &Context, const Expr *Converted,
240 APValue &ConstantValue,
241 QualType &ConstantType) const;
242 bool isPointerConversionToBool() const;
243 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
244 void DebugPrint() const;
247 /// UserDefinedConversionSequence - Represents a user-defined
248 /// conversion sequence (C++ 13.3.3.1.2).
249 struct UserDefinedConversionSequence {
250 /// \brief Represents the standard conversion that occurs before
251 /// the actual user-defined conversion.
253 /// C++11 13.3.3.1.2p1:
254 /// If the user-defined conversion is specified by a constructor
255 /// (12.3.1), the initial standard conversion sequence converts
256 /// the source type to the type required by the argument of the
257 /// constructor. If the user-defined conversion is specified by
258 /// a conversion function (12.3.2), the initial standard
259 /// conversion sequence converts the source type to the implicit
260 /// object parameter of the conversion function.
261 StandardConversionSequence Before;
263 /// EllipsisConversion - When this is true, it means user-defined
264 /// conversion sequence starts with a ... (elipsis) conversion, instead of
265 /// a standard conversion. In this case, 'Before' field must be ignored.
266 // FIXME. I much rather put this as the first field. But there seems to be
267 // a gcc code gen. bug which causes a crash in a test. Putting it here seems
268 // to work around the crash.
269 bool EllipsisConversion : 1;
271 /// HadMultipleCandidates - When this is true, it means that the
272 /// conversion function was resolved from an overloaded set having
273 /// size greater than 1.
274 bool HadMultipleCandidates : 1;
276 /// After - Represents the standard conversion that occurs after
277 /// the actual user-defined conversion.
278 StandardConversionSequence After;
280 /// ConversionFunction - The function that will perform the
281 /// user-defined conversion. Null if the conversion is an
282 /// aggregate initialization from an initializer list.
283 FunctionDecl* ConversionFunction;
285 /// \brief The declaration that we found via name lookup, which might be
286 /// the same as \c ConversionFunction or it might be a using declaration
287 /// that refers to \c ConversionFunction.
288 DeclAccessPair FoundConversionFunction;
290 void DebugPrint() const;
293 /// Represents an ambiguous user-defined conversion sequence.
294 struct AmbiguousConversionSequence {
295 typedef SmallVector<FunctionDecl*, 4> ConversionSet;
299 char Buffer[sizeof(ConversionSet)];
301 QualType getFromType() const {
302 return QualType::getFromOpaquePtr(FromTypePtr);
304 QualType getToType() const {
305 return QualType::getFromOpaquePtr(ToTypePtr);
307 void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
308 void setToType(QualType T) { ToTypePtr = T.getAsOpaquePtr(); }
310 ConversionSet &conversions() {
311 return *reinterpret_cast<ConversionSet*>(Buffer);
314 const ConversionSet &conversions() const {
315 return *reinterpret_cast<const ConversionSet*>(Buffer);
318 void addConversion(FunctionDecl *D) {
319 conversions().push_back(D);
322 typedef ConversionSet::iterator iterator;
323 iterator begin() { return conversions().begin(); }
324 iterator end() { return conversions().end(); }
326 typedef ConversionSet::const_iterator const_iterator;
327 const_iterator begin() const { return conversions().begin(); }
328 const_iterator end() const { return conversions().end(); }
332 void copyFrom(const AmbiguousConversionSequence &);
335 /// BadConversionSequence - Records information about an invalid
336 /// conversion sequence.
337 struct BadConversionSequence {
343 lvalue_ref_to_rvalue,
347 // This can be null, e.g. for implicit object arguments.
353 // The type we're converting from (an opaque QualType).
356 // The type we're converting to (an opaque QualType).
360 void init(FailureKind K, Expr *From, QualType To) {
361 init(K, From->getType(), To);
364 void init(FailureKind K, QualType From, QualType To) {
371 QualType getFromType() const { return QualType::getFromOpaquePtr(FromTy); }
372 QualType getToType() const { return QualType::getFromOpaquePtr(ToTy); }
374 void setFromExpr(Expr *E) {
376 setFromType(E->getType());
378 void setFromType(QualType T) { FromTy = T.getAsOpaquePtr(); }
379 void setToType(QualType T) { ToTy = T.getAsOpaquePtr(); }
382 /// ImplicitConversionSequence - Represents an implicit conversion
383 /// sequence, which may be a standard conversion sequence
384 /// (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2),
385 /// or an ellipsis conversion sequence (C++ 13.3.3.1.3).
386 class ImplicitConversionSequence {
388 /// Kind - The kind of implicit conversion sequence. BadConversion
389 /// specifies that there is no conversion from the source type to
390 /// the target type. AmbiguousConversion represents the unique
391 /// ambiguous conversion (C++0x [over.best.ics]p10).
393 StandardConversion = 0,
394 UserDefinedConversion,
402 Uninitialized = BadConversion + 1
405 /// ConversionKind - The kind of implicit conversion sequence.
406 unsigned ConversionKind : 30;
408 /// \brief Whether the argument is an initializer list.
409 bool ListInitializationSequence : 1;
411 /// \brief Whether the target is really a std::initializer_list, and the
412 /// sequence only represents the worst element conversion.
413 bool StdInitializerListElement : 1;
415 void setKind(Kind K) {
421 if (ConversionKind == AmbiguousConversion) Ambiguous.destruct();
426 /// When ConversionKind == StandardConversion, provides the
427 /// details of the standard conversion sequence.
428 StandardConversionSequence Standard;
430 /// When ConversionKind == UserDefinedConversion, provides the
431 /// details of the user-defined conversion sequence.
432 UserDefinedConversionSequence UserDefined;
434 /// When ConversionKind == AmbiguousConversion, provides the
435 /// details of the ambiguous conversion.
436 AmbiguousConversionSequence Ambiguous;
438 /// When ConversionKind == BadConversion, provides the details
439 /// of the bad conversion.
440 BadConversionSequence Bad;
443 ImplicitConversionSequence()
444 : ConversionKind(Uninitialized), ListInitializationSequence(false),
445 StdInitializerListElement(false)
447 ~ImplicitConversionSequence() {
450 ImplicitConversionSequence(const ImplicitConversionSequence &Other)
451 : ConversionKind(Other.ConversionKind),
452 ListInitializationSequence(Other.ListInitializationSequence),
453 StdInitializerListElement(Other.StdInitializerListElement)
455 switch (ConversionKind) {
456 case Uninitialized: break;
457 case StandardConversion: Standard = Other.Standard; break;
458 case UserDefinedConversion: UserDefined = Other.UserDefined; break;
459 case AmbiguousConversion: Ambiguous.copyFrom(Other.Ambiguous); break;
460 case EllipsisConversion: break;
461 case BadConversion: Bad = Other.Bad; break;
465 ImplicitConversionSequence &
466 operator=(const ImplicitConversionSequence &Other) {
468 new (this) ImplicitConversionSequence(Other);
472 Kind getKind() const {
473 assert(isInitialized() && "querying uninitialized conversion");
474 return Kind(ConversionKind);
477 /// \brief Return a ranking of the implicit conversion sequence
478 /// kind, where smaller ranks represent better conversion
481 /// In particular, this routine gives user-defined conversion
482 /// sequences and ambiguous conversion sequences the same rank,
483 /// per C++ [over.best.ics]p10.
484 unsigned getKindRank() const {
486 case StandardConversion:
489 case UserDefinedConversion:
490 case AmbiguousConversion:
493 case EllipsisConversion:
500 llvm_unreachable("Invalid ImplicitConversionSequence::Kind!");
503 bool isBad() const { return getKind() == BadConversion; }
504 bool isStandard() const { return getKind() == StandardConversion; }
505 bool isEllipsis() const { return getKind() == EllipsisConversion; }
506 bool isAmbiguous() const { return getKind() == AmbiguousConversion; }
507 bool isUserDefined() const { return getKind() == UserDefinedConversion; }
508 bool isFailure() const { return isBad() || isAmbiguous(); }
510 /// Determines whether this conversion sequence has been
511 /// initialized. Most operations should never need to query
512 /// uninitialized conversions and should assert as above.
513 bool isInitialized() const { return ConversionKind != Uninitialized; }
515 /// Sets this sequence as a bad conversion for an explicit argument.
516 void setBad(BadConversionSequence::FailureKind Failure,
517 Expr *FromExpr, QualType ToType) {
518 setKind(BadConversion);
519 Bad.init(Failure, FromExpr, ToType);
522 /// Sets this sequence as a bad conversion for an implicit argument.
523 void setBad(BadConversionSequence::FailureKind Failure,
524 QualType FromType, QualType ToType) {
525 setKind(BadConversion);
526 Bad.init(Failure, FromType, ToType);
529 void setStandard() { setKind(StandardConversion); }
530 void setEllipsis() { setKind(EllipsisConversion); }
531 void setUserDefined() { setKind(UserDefinedConversion); }
532 void setAmbiguous() {
533 if (ConversionKind == AmbiguousConversion) return;
534 ConversionKind = AmbiguousConversion;
535 Ambiguous.construct();
538 /// \brief Whether this sequence was created by the rules of
539 /// list-initialization sequences.
540 bool isListInitializationSequence() const {
541 return ListInitializationSequence;
544 void setListInitializationSequence() {
545 ListInitializationSequence = true;
548 /// \brief Whether the target is really a std::initializer_list, and the
549 /// sequence only represents the worst element conversion.
550 bool isStdInitializerListElement() const {
551 return StdInitializerListElement;
554 void setStdInitializerListElement(bool V = true) {
555 StdInitializerListElement = V;
558 // The result of a comparison between implicit conversion
559 // sequences. Use Sema::CompareImplicitConversionSequences to
560 // actually perform the comparison.
563 Indistinguishable = 0,
567 void DiagnoseAmbiguousConversion(Sema &S,
568 SourceLocation CaretLoc,
569 const PartialDiagnostic &PDiag) const;
571 void DebugPrint() const;
574 enum OverloadFailureKind {
575 ovl_fail_too_many_arguments,
576 ovl_fail_too_few_arguments,
577 ovl_fail_bad_conversion,
578 ovl_fail_bad_deduction,
580 /// This conversion candidate was not considered because it
581 /// duplicates the work of a trivial or derived-to-base
583 ovl_fail_trivial_conversion,
585 /// This conversion candidate is not viable because its result
586 /// type is not implicitly convertible to the desired type.
587 ovl_fail_bad_final_conversion,
589 /// This conversion function template specialization candidate is not
590 /// viable because the final conversion was not an exact match.
591 ovl_fail_final_conversion_not_exact,
593 /// (CUDA) This candidate was not viable because the callee
594 /// was not accessible from the caller's target (i.e. host->device,
595 /// global->host, device->host).
599 /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
600 struct OverloadCandidate {
601 /// Function - The actual function that this candidate
602 /// represents. When NULL, this is a built-in candidate
603 /// (C++ [over.oper]) or a surrogate for a conversion to a
604 /// function pointer or reference (C++ [over.call.object]).
605 FunctionDecl *Function;
607 /// FoundDecl - The original declaration that was looked up /
608 /// invented / otherwise found, together with its access.
609 /// Might be a UsingShadowDecl or a FunctionTemplateDecl.
610 DeclAccessPair FoundDecl;
612 // BuiltinTypes - Provides the return and parameter types of a
613 // built-in overload candidate. Only valid when Function is NULL.
616 QualType ParamTypes[3];
619 /// Surrogate - The conversion function for which this candidate
620 /// is a surrogate, but only if IsSurrogate is true.
621 CXXConversionDecl *Surrogate;
623 /// Conversions - The conversion sequences used to convert the
624 /// function arguments to the function parameters, the pointer points to a
625 /// fixed size array with NumConversions elements. The memory is owned by
626 /// the OverloadCandidateSet.
627 ImplicitConversionSequence *Conversions;
629 /// The FixIt hints which can be used to fix the Bad candidate.
630 ConversionFixItGenerator Fix;
632 /// NumConversions - The number of elements in the Conversions array.
633 unsigned NumConversions;
635 /// Viable - True to indicate that this overload candidate is viable.
638 /// IsSurrogate - True to indicate that this candidate is a
639 /// surrogate for a conversion to a function pointer or reference
640 /// (C++ [over.call.object]).
643 /// IgnoreObjectArgument - True to indicate that the first
644 /// argument's conversion, which for this function represents the
645 /// implicit object argument, should be ignored. This will be true
646 /// when the candidate is a static member function (where the
647 /// implicit object argument is just a placeholder) or a
648 /// non-static member function when the call doesn't have an
650 bool IgnoreObjectArgument;
652 /// FailureKind - The reason why this candidate is not viable.
653 /// Actually an OverloadFailureKind.
654 unsigned char FailureKind;
656 /// \brief The number of call arguments that were explicitly provided,
657 /// to be used while performing partial ordering of function templates.
658 unsigned ExplicitCallArguments;
660 /// A structure used to record information about a failed
661 /// template argument deduction.
662 struct DeductionFailureInfo {
663 /// A Sema::TemplateDeductionResult.
666 /// \brief Indicates whether a diagnostic is stored in Diagnostic.
667 unsigned HasDiagnostic : 1;
669 /// \brief Opaque pointer containing additional data about
670 /// this deduction failure.
673 /// \brief A diagnostic indicating why deduction failed.
676 char Diagnostic[sizeof(PartialDiagnosticAt)];
679 /// \brief Retrieve the diagnostic which caused this deduction failure,
681 PartialDiagnosticAt *getSFINAEDiagnostic();
683 /// \brief Retrieve the template parameter this deduction failure
684 /// refers to, if any.
685 TemplateParameter getTemplateParameter();
687 /// \brief Retrieve the template argument list associated with this
688 /// deduction failure, if any.
689 TemplateArgumentList *getTemplateArgumentList();
691 /// \brief Return the first template argument this deduction failure
692 /// refers to, if any.
693 const TemplateArgument *getFirstArg();
695 /// \brief Return the second template argument this deduction failure
696 /// refers to, if any.
697 const TemplateArgument *getSecondArg();
699 /// \brief Return the expression this deduction failure refers to,
703 /// \brief Free any memory associated with this deduction failure.
708 DeductionFailureInfo DeductionFailure;
710 /// FinalConversion - For a conversion function (where Function is
711 /// a CXXConversionDecl), the standard conversion that occurs
712 /// after the call to the overload candidate to convert the result
713 /// of calling the conversion function to the required type.
714 StandardConversionSequence FinalConversion;
717 /// hasAmbiguousConversion - Returns whether this overload
718 /// candidate requires an ambiguous conversion or not.
719 bool hasAmbiguousConversion() const {
720 for (unsigned i = 0, e = NumConversions; i != e; ++i) {
721 if (!Conversions[i].isInitialized()) return false;
722 if (Conversions[i].isAmbiguous()) return true;
727 bool TryToFixBadConversion(unsigned Idx, Sema &S) {
728 bool CanFix = Fix.tryToFixConversion(
729 Conversions[Idx].Bad.FromExpr,
730 Conversions[Idx].Bad.getFromType(),
731 Conversions[Idx].Bad.getToType(), S);
733 // If at least one conversion fails, the candidate cannot be fixed.
741 /// OverloadCandidateSet - A set of overload candidates, used in C++
742 /// overload resolution (C++ 13.3).
743 class OverloadCandidateSet {
744 SmallVector<OverloadCandidate, 16> Candidates;
745 llvm::SmallPtrSet<Decl *, 16> Functions;
747 // Allocator for OverloadCandidate::Conversions. We store the first few
748 // elements inline to avoid allocation for small sets.
749 llvm::BumpPtrAllocator ConversionSequenceAllocator;
753 unsigned NumInlineSequences;
754 char InlineSpace[16 * sizeof(ImplicitConversionSequence)];
756 OverloadCandidateSet(const OverloadCandidateSet &) LLVM_DELETED_FUNCTION;
757 void operator=(const OverloadCandidateSet &) LLVM_DELETED_FUNCTION;
759 void destroyCandidates();
762 OverloadCandidateSet(SourceLocation Loc) : Loc(Loc), NumInlineSequences(0){}
763 ~OverloadCandidateSet() { destroyCandidates(); }
765 SourceLocation getLocation() const { return Loc; }
767 /// \brief Determine when this overload candidate will be new to the
769 bool isNewCandidate(Decl *F) {
770 return Functions.insert(F->getCanonicalDecl());
773 /// \brief Clear out all of the candidates.
776 typedef SmallVector<OverloadCandidate, 16>::iterator iterator;
777 iterator begin() { return Candidates.begin(); }
778 iterator end() { return Candidates.end(); }
780 size_t size() const { return Candidates.size(); }
781 bool empty() const { return Candidates.empty(); }
783 /// \brief Add a new candidate with NumConversions conversion sequence slots
784 /// to the overload set.
785 OverloadCandidate &addCandidate(unsigned NumConversions = 0) {
786 Candidates.push_back(OverloadCandidate());
787 OverloadCandidate &C = Candidates.back();
789 // Assign space from the inline array if there are enough free slots
791 if (NumConversions + NumInlineSequences <= 16) {
792 ImplicitConversionSequence *I =
793 (ImplicitConversionSequence*)InlineSpace;
794 C.Conversions = &I[NumInlineSequences];
795 NumInlineSequences += NumConversions;
797 // Otherwise get memory from the allocator.
798 C.Conversions = ConversionSequenceAllocator
799 .Allocate<ImplicitConversionSequence>(NumConversions);
802 // Construct the new objects.
803 for (unsigned i = 0; i != NumConversions; ++i)
804 new (&C.Conversions[i]) ImplicitConversionSequence();
806 C.NumConversions = NumConversions;
810 /// Find the best viable function on this overload set, if it exists.
811 OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc,
812 OverloadCandidateSet::iterator& Best,
813 bool UserDefinedConversion = false);
815 void NoteCandidates(Sema &S,
816 OverloadCandidateDisplayKind OCD,
817 ArrayRef<Expr *> Args,
819 SourceLocation Loc = SourceLocation());
822 bool isBetterOverloadCandidate(Sema &S,
823 const OverloadCandidate& Cand1,
824 const OverloadCandidate& Cand2,
826 bool UserDefinedConversion = false);
827 } // end namespace clang
829 #endif // LLVM_CLANG_SEMA_OVERLOAD_H