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 "clang/Sema/TemplateDeduction.h"
26 #include "llvm/ADT/SmallPtrSet.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/Support/AlignOf.h"
29 #include "llvm/Support/Allocator.h"
33 class CXXConstructorDecl;
34 class CXXConversionDecl;
38 /// OverloadingResult - Capture the result of performing overload
40 enum OverloadingResult {
41 OR_Success, ///< Overload resolution succeeded.
42 OR_No_Viable_Function, ///< No viable function found.
43 OR_Ambiguous, ///< Ambiguous candidates found.
44 OR_Deleted ///< Succeeded, but refers to a deleted function.
47 enum OverloadCandidateDisplayKind {
48 /// Requests that all candidates be shown. Viable candidates will
52 /// Requests that only viable candidates be shown.
56 /// ImplicitConversionKind - The kind of implicit conversion used to
57 /// convert an argument to a parameter's type. The enumerator values
58 /// match with Table 9 of (C++ 13.3.3.1.1) and are listed such that
59 /// better conversion kinds have smaller values.
60 enum ImplicitConversionKind {
61 ICK_Identity = 0, ///< Identity conversion (no conversion)
62 ICK_Lvalue_To_Rvalue, ///< Lvalue-to-rvalue conversion (C++ 4.1)
63 ICK_Array_To_Pointer, ///< Array-to-pointer conversion (C++ 4.2)
64 ICK_Function_To_Pointer, ///< Function-to-pointer (C++ 4.3)
65 ICK_NoReturn_Adjustment, ///< Removal of noreturn from a type (Clang)
66 ICK_Qualification, ///< Qualification conversions (C++ 4.4)
67 ICK_Integral_Promotion, ///< Integral promotions (C++ 4.5)
68 ICK_Floating_Promotion, ///< Floating point promotions (C++ 4.6)
69 ICK_Complex_Promotion, ///< Complex promotions (Clang extension)
70 ICK_Integral_Conversion, ///< Integral conversions (C++ 4.7)
71 ICK_Floating_Conversion, ///< Floating point conversions (C++ 4.8)
72 ICK_Complex_Conversion, ///< Complex conversions (C99 6.3.1.6)
73 ICK_Floating_Integral, ///< Floating-integral conversions (C++ 4.9)
74 ICK_Pointer_Conversion, ///< Pointer conversions (C++ 4.10)
75 ICK_Pointer_Member, ///< Pointer-to-member conversions (C++ 4.11)
76 ICK_Boolean_Conversion, ///< Boolean conversions (C++ 4.12)
77 ICK_Compatible_Conversion, ///< Conversions between compatible types in C99
78 ICK_Derived_To_Base, ///< Derived-to-base (C++ [over.best.ics])
79 ICK_Vector_Conversion, ///< Vector conversions
80 ICK_Vector_Splat, ///< A vector splat from an arithmetic type
81 ICK_Complex_Real, ///< Complex-real conversions (C99 6.3.1.7)
82 ICK_Block_Pointer_Conversion, ///< Block Pointer conversions
83 ICK_TransparentUnionConversion, ///< Transparent Union Conversions
84 ICK_Writeback_Conversion, ///< Objective-C ARC writeback conversion
85 ICK_Zero_Event_Conversion, ///< Zero constant to event (OpenCL1.2 6.12.10)
86 ICK_Num_Conversion_Kinds ///< The number of conversion kinds
89 /// ImplicitConversionRank - The rank of an implicit conversion
90 /// kind. The enumerator values match with Table 9 of (C++
91 /// 13.3.3.1.1) and are listed such that better conversion ranks
92 /// have smaller values.
93 enum ImplicitConversionRank {
94 ICR_Exact_Match = 0, ///< Exact Match
95 ICR_Promotion, ///< Promotion
96 ICR_Conversion, ///< Conversion
97 ICR_Complex_Real_Conversion, ///< Complex <-> Real conversion
98 ICR_Writeback_Conversion ///< ObjC ARC writeback conversion
101 ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind);
103 /// NarrowingKind - The kind of narrowing conversion being performed by a
104 /// standard conversion sequence according to C++11 [dcl.init.list]p7.
106 /// Not a narrowing conversion.
109 /// A narrowing conversion by virtue of the source and destination types.
112 /// A narrowing conversion, because a constant expression got narrowed.
113 NK_Constant_Narrowing,
115 /// A narrowing conversion, because a non-constant-expression variable might
116 /// have got narrowed.
117 NK_Variable_Narrowing
120 /// StandardConversionSequence - represents a standard conversion
121 /// sequence (C++ 13.3.3.1.1). A standard conversion sequence
122 /// contains between zero and three conversions. If a particular
123 /// conversion is not needed, it will be set to the identity conversion
124 /// (ICK_Identity). Note that the three conversions are
125 /// specified as separate members (rather than in an array) so that
126 /// we can keep the size of a standard conversion sequence to a
128 class StandardConversionSequence {
130 /// First -- The first conversion can be an lvalue-to-rvalue
131 /// conversion, array-to-pointer conversion, or
132 /// function-to-pointer conversion.
133 ImplicitConversionKind First : 8;
135 /// Second - The second conversion can be an integral promotion,
136 /// floating point promotion, integral conversion, floating point
137 /// conversion, floating-integral conversion, pointer conversion,
138 /// pointer-to-member conversion, or boolean conversion.
139 ImplicitConversionKind Second : 8;
141 /// Third - The third conversion can be a qualification conversion.
142 ImplicitConversionKind Third : 8;
144 /// \brief Whether this is the deprecated conversion of a
145 /// string literal to a pointer to non-const character data
147 unsigned DeprecatedStringLiteralToCharPtr : 1;
149 /// \brief Whether the qualification conversion involves a change in the
150 /// Objective-C lifetime (for automatic reference counting).
151 unsigned QualificationIncludesObjCLifetime : 1;
153 /// IncompatibleObjC - Whether this is an Objective-C conversion
154 /// that we should warn about (if we actually use it).
155 unsigned IncompatibleObjC : 1;
157 /// ReferenceBinding - True when this is a reference binding
158 /// (C++ [over.ics.ref]).
159 unsigned ReferenceBinding : 1;
161 /// DirectBinding - True when this is a reference binding that is a
162 /// direct binding (C++ [dcl.init.ref]).
163 unsigned DirectBinding : 1;
165 /// \brief Whether this is an lvalue reference binding (otherwise, it's
166 /// an rvalue reference binding).
167 unsigned IsLvalueReference : 1;
169 /// \brief Whether we're binding to a function lvalue.
170 unsigned BindsToFunctionLvalue : 1;
172 /// \brief Whether we're binding to an rvalue.
173 unsigned BindsToRvalue : 1;
175 /// \brief Whether this binds an implicit object argument to a
176 /// non-static member function without a ref-qualifier.
177 unsigned BindsImplicitObjectArgumentWithoutRefQualifier : 1;
179 /// \brief Whether this binds a reference to an object with a different
180 /// Objective-C lifetime qualifier.
181 unsigned ObjCLifetimeConversionBinding : 1;
183 /// FromType - The type that this conversion is converting
184 /// from. This is an opaque pointer that can be translated into a
188 /// ToType - The types that this conversion is converting to in
189 /// each step. This is an opaque pointer that can be translated
193 /// CopyConstructor - The copy constructor that is used to perform
194 /// this conversion, when the conversion is actually just the
195 /// initialization of an object via copy constructor. Such
196 /// conversions are either identity conversions or derived-to-base
198 CXXConstructorDecl *CopyConstructor;
200 void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
201 void setToType(unsigned Idx, QualType T) {
202 assert(Idx < 3 && "To type index is out of range");
203 ToTypePtrs[Idx] = T.getAsOpaquePtr();
205 void setAllToTypes(QualType T) {
206 ToTypePtrs[0] = T.getAsOpaquePtr();
207 ToTypePtrs[1] = ToTypePtrs[0];
208 ToTypePtrs[2] = ToTypePtrs[0];
211 QualType getFromType() const {
212 return QualType::getFromOpaquePtr(FromTypePtr);
214 QualType getToType(unsigned Idx) const {
215 assert(Idx < 3 && "To type index is out of range");
216 return QualType::getFromOpaquePtr(ToTypePtrs[Idx]);
219 void setAsIdentityConversion();
221 bool isIdentityConversion() const {
222 return Second == ICK_Identity && Third == ICK_Identity;
225 ImplicitConversionRank getRank() const;
226 NarrowingKind getNarrowingKind(ASTContext &Context, const Expr *Converted,
227 APValue &ConstantValue,
228 QualType &ConstantType) const;
229 bool isPointerConversionToBool() const;
230 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
234 /// UserDefinedConversionSequence - Represents a user-defined
235 /// conversion sequence (C++ 13.3.3.1.2).
236 struct UserDefinedConversionSequence {
237 /// \brief Represents the standard conversion that occurs before
238 /// the actual user-defined conversion.
240 /// C++11 13.3.3.1.2p1:
241 /// If the user-defined conversion is specified by a constructor
242 /// (12.3.1), the initial standard conversion sequence converts
243 /// the source type to the type required by the argument of the
244 /// constructor. If the user-defined conversion is specified by
245 /// a conversion function (12.3.2), the initial standard
246 /// conversion sequence converts the source type to the implicit
247 /// object parameter of the conversion function.
248 StandardConversionSequence Before;
250 /// EllipsisConversion - When this is true, it means user-defined
251 /// conversion sequence starts with a ... (ellipsis) conversion, instead of
252 /// a standard conversion. In this case, 'Before' field must be ignored.
253 // FIXME. I much rather put this as the first field. But there seems to be
254 // a gcc code gen. bug which causes a crash in a test. Putting it here seems
255 // to work around the crash.
256 bool EllipsisConversion : 1;
258 /// HadMultipleCandidates - When this is true, it means that the
259 /// conversion function was resolved from an overloaded set having
260 /// size greater than 1.
261 bool HadMultipleCandidates : 1;
263 /// After - Represents the standard conversion that occurs after
264 /// the actual user-defined conversion.
265 StandardConversionSequence After;
267 /// ConversionFunction - The function that will perform the
268 /// user-defined conversion. Null if the conversion is an
269 /// aggregate initialization from an initializer list.
270 FunctionDecl* ConversionFunction;
272 /// \brief The declaration that we found via name lookup, which might be
273 /// the same as \c ConversionFunction or it might be a using declaration
274 /// that refers to \c ConversionFunction.
275 DeclAccessPair FoundConversionFunction;
280 /// Represents an ambiguous user-defined conversion sequence.
281 struct AmbiguousConversionSequence {
282 typedef SmallVector<FunctionDecl*, 4> ConversionSet;
286 char Buffer[sizeof(ConversionSet)];
288 QualType getFromType() const {
289 return QualType::getFromOpaquePtr(FromTypePtr);
291 QualType getToType() const {
292 return QualType::getFromOpaquePtr(ToTypePtr);
294 void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
295 void setToType(QualType T) { ToTypePtr = T.getAsOpaquePtr(); }
297 ConversionSet &conversions() {
298 return *reinterpret_cast<ConversionSet*>(Buffer);
301 const ConversionSet &conversions() const {
302 return *reinterpret_cast<const ConversionSet*>(Buffer);
305 void addConversion(FunctionDecl *D) {
306 conversions().push_back(D);
309 typedef ConversionSet::iterator iterator;
310 iterator begin() { return conversions().begin(); }
311 iterator end() { return conversions().end(); }
313 typedef ConversionSet::const_iterator const_iterator;
314 const_iterator begin() const { return conversions().begin(); }
315 const_iterator end() const { return conversions().end(); }
319 void copyFrom(const AmbiguousConversionSequence &);
322 /// BadConversionSequence - Records information about an invalid
323 /// conversion sequence.
324 struct BadConversionSequence {
329 lvalue_ref_to_rvalue,
333 // This can be null, e.g. for implicit object arguments.
339 // The type we're converting from (an opaque QualType).
342 // The type we're converting to (an opaque QualType).
346 void init(FailureKind K, Expr *From, QualType To) {
347 init(K, From->getType(), To);
350 void init(FailureKind K, QualType From, QualType To) {
357 QualType getFromType() const { return QualType::getFromOpaquePtr(FromTy); }
358 QualType getToType() const { return QualType::getFromOpaquePtr(ToTy); }
360 void setFromExpr(Expr *E) {
362 setFromType(E->getType());
364 void setFromType(QualType T) { FromTy = T.getAsOpaquePtr(); }
365 void setToType(QualType T) { ToTy = T.getAsOpaquePtr(); }
368 /// ImplicitConversionSequence - Represents an implicit conversion
369 /// sequence, which may be a standard conversion sequence
370 /// (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2),
371 /// or an ellipsis conversion sequence (C++ 13.3.3.1.3).
372 class ImplicitConversionSequence {
374 /// Kind - The kind of implicit conversion sequence. BadConversion
375 /// specifies that there is no conversion from the source type to
376 /// the target type. AmbiguousConversion represents the unique
377 /// ambiguous conversion (C++0x [over.best.ics]p10).
379 StandardConversion = 0,
380 UserDefinedConversion,
388 Uninitialized = BadConversion + 1
391 /// ConversionKind - The kind of implicit conversion sequence.
392 unsigned ConversionKind : 30;
394 /// \brief Whether the target is really a std::initializer_list, and the
395 /// sequence only represents the worst element conversion.
396 bool StdInitializerListElement : 1;
398 void setKind(Kind K) {
404 if (ConversionKind == AmbiguousConversion) Ambiguous.destruct();
409 /// When ConversionKind == StandardConversion, provides the
410 /// details of the standard conversion sequence.
411 StandardConversionSequence Standard;
413 /// When ConversionKind == UserDefinedConversion, provides the
414 /// details of the user-defined conversion sequence.
415 UserDefinedConversionSequence UserDefined;
417 /// When ConversionKind == AmbiguousConversion, provides the
418 /// details of the ambiguous conversion.
419 AmbiguousConversionSequence Ambiguous;
421 /// When ConversionKind == BadConversion, provides the details
422 /// of the bad conversion.
423 BadConversionSequence Bad;
426 ImplicitConversionSequence()
427 : ConversionKind(Uninitialized), StdInitializerListElement(false)
429 ~ImplicitConversionSequence() {
432 ImplicitConversionSequence(const ImplicitConversionSequence &Other)
433 : ConversionKind(Other.ConversionKind),
434 StdInitializerListElement(Other.StdInitializerListElement)
436 switch (ConversionKind) {
437 case Uninitialized: break;
438 case StandardConversion: Standard = Other.Standard; break;
439 case UserDefinedConversion: UserDefined = Other.UserDefined; break;
440 case AmbiguousConversion: Ambiguous.copyFrom(Other.Ambiguous); break;
441 case EllipsisConversion: break;
442 case BadConversion: Bad = Other.Bad; break;
446 ImplicitConversionSequence &
447 operator=(const ImplicitConversionSequence &Other) {
449 new (this) ImplicitConversionSequence(Other);
453 Kind getKind() const {
454 assert(isInitialized() && "querying uninitialized conversion");
455 return Kind(ConversionKind);
458 /// \brief Return a ranking of the implicit conversion sequence
459 /// kind, where smaller ranks represent better conversion
462 /// In particular, this routine gives user-defined conversion
463 /// sequences and ambiguous conversion sequences the same rank,
464 /// per C++ [over.best.ics]p10.
465 unsigned getKindRank() const {
467 case StandardConversion:
470 case UserDefinedConversion:
471 case AmbiguousConversion:
474 case EllipsisConversion:
481 llvm_unreachable("Invalid ImplicitConversionSequence::Kind!");
484 bool isBad() const { return getKind() == BadConversion; }
485 bool isStandard() const { return getKind() == StandardConversion; }
486 bool isEllipsis() const { return getKind() == EllipsisConversion; }
487 bool isAmbiguous() const { return getKind() == AmbiguousConversion; }
488 bool isUserDefined() const { return getKind() == UserDefinedConversion; }
489 bool isFailure() const { return isBad() || isAmbiguous(); }
491 /// Determines whether this conversion sequence has been
492 /// initialized. Most operations should never need to query
493 /// uninitialized conversions and should assert as above.
494 bool isInitialized() const { return ConversionKind != Uninitialized; }
496 /// Sets this sequence as a bad conversion for an explicit argument.
497 void setBad(BadConversionSequence::FailureKind Failure,
498 Expr *FromExpr, QualType ToType) {
499 setKind(BadConversion);
500 Bad.init(Failure, FromExpr, ToType);
503 /// Sets this sequence as a bad conversion for an implicit argument.
504 void setBad(BadConversionSequence::FailureKind Failure,
505 QualType FromType, QualType ToType) {
506 setKind(BadConversion);
507 Bad.init(Failure, FromType, ToType);
510 void setStandard() { setKind(StandardConversion); }
511 void setEllipsis() { setKind(EllipsisConversion); }
512 void setUserDefined() { setKind(UserDefinedConversion); }
513 void setAmbiguous() {
514 if (ConversionKind == AmbiguousConversion) return;
515 ConversionKind = AmbiguousConversion;
516 Ambiguous.construct();
519 /// \brief Whether the target is really a std::initializer_list, and the
520 /// sequence only represents the worst element conversion.
521 bool isStdInitializerListElement() const {
522 return StdInitializerListElement;
525 void setStdInitializerListElement(bool V = true) {
526 StdInitializerListElement = V;
529 // The result of a comparison between implicit conversion
530 // sequences. Use Sema::CompareImplicitConversionSequences to
531 // actually perform the comparison.
534 Indistinguishable = 0,
538 void DiagnoseAmbiguousConversion(Sema &S,
539 SourceLocation CaretLoc,
540 const PartialDiagnostic &PDiag) const;
545 enum OverloadFailureKind {
546 ovl_fail_too_many_arguments,
547 ovl_fail_too_few_arguments,
548 ovl_fail_bad_conversion,
549 ovl_fail_bad_deduction,
551 /// This conversion candidate was not considered because it
552 /// duplicates the work of a trivial or derived-to-base
554 ovl_fail_trivial_conversion,
556 /// This conversion candidate was not considered because it is
557 /// an illegal instantiation of a constructor temploid: it is
558 /// callable with one argument, we only have one argument, and
559 /// its first parameter type is exactly the type of the class.
561 /// Defining such a constructor directly is illegal, and
562 /// template-argument deduction is supposed to ignore such
563 /// instantiations, but we can still get one with the right
564 /// kind of implicit instantiation.
565 ovl_fail_illegal_constructor,
567 /// This conversion candidate is not viable because its result
568 /// type is not implicitly convertible to the desired type.
569 ovl_fail_bad_final_conversion,
571 /// This conversion function template specialization candidate is not
572 /// viable because the final conversion was not an exact match.
573 ovl_fail_final_conversion_not_exact,
575 /// (CUDA) This candidate was not viable because the callee
576 /// was not accessible from the caller's target (i.e. host->device,
577 /// global->host, device->host).
580 /// This candidate function was not viable because an enable_if
581 /// attribute disabled it.
585 /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
586 struct OverloadCandidate {
587 /// Function - The actual function that this candidate
588 /// represents. When NULL, this is a built-in candidate
589 /// (C++ [over.oper]) or a surrogate for a conversion to a
590 /// function pointer or reference (C++ [over.call.object]).
591 FunctionDecl *Function;
593 /// FoundDecl - The original declaration that was looked up /
594 /// invented / otherwise found, together with its access.
595 /// Might be a UsingShadowDecl or a FunctionTemplateDecl.
596 DeclAccessPair FoundDecl;
598 // BuiltinTypes - Provides the return and parameter types of a
599 // built-in overload candidate. Only valid when Function is NULL.
602 QualType ParamTypes[3];
605 /// Surrogate - The conversion function for which this candidate
606 /// is a surrogate, but only if IsSurrogate is true.
607 CXXConversionDecl *Surrogate;
609 /// Conversions - The conversion sequences used to convert the
610 /// function arguments to the function parameters, the pointer points to a
611 /// fixed size array with NumConversions elements. The memory is owned by
612 /// the OverloadCandidateSet.
613 ImplicitConversionSequence *Conversions;
615 /// The FixIt hints which can be used to fix the Bad candidate.
616 ConversionFixItGenerator Fix;
618 /// NumConversions - The number of elements in the Conversions array.
619 unsigned NumConversions;
621 /// Viable - True to indicate that this overload candidate is viable.
624 /// IsSurrogate - True to indicate that this candidate is a
625 /// surrogate for a conversion to a function pointer or reference
626 /// (C++ [over.call.object]).
629 /// IgnoreObjectArgument - True to indicate that the first
630 /// argument's conversion, which for this function represents the
631 /// implicit object argument, should be ignored. This will be true
632 /// when the candidate is a static member function (where the
633 /// implicit object argument is just a placeholder) or a
634 /// non-static member function when the call doesn't have an
636 bool IgnoreObjectArgument;
638 /// FailureKind - The reason why this candidate is not viable.
639 /// Actually an OverloadFailureKind.
640 unsigned char FailureKind;
642 /// \brief The number of call arguments that were explicitly provided,
643 /// to be used while performing partial ordering of function templates.
644 unsigned ExplicitCallArguments;
647 DeductionFailureInfo DeductionFailure;
649 /// FinalConversion - For a conversion function (where Function is
650 /// a CXXConversionDecl), the standard conversion that occurs
651 /// after the call to the overload candidate to convert the result
652 /// of calling the conversion function to the required type.
653 StandardConversionSequence FinalConversion;
656 /// hasAmbiguousConversion - Returns whether this overload
657 /// candidate requires an ambiguous conversion or not.
658 bool hasAmbiguousConversion() const {
659 for (unsigned i = 0, e = NumConversions; i != e; ++i) {
660 if (!Conversions[i].isInitialized()) return false;
661 if (Conversions[i].isAmbiguous()) return true;
666 bool TryToFixBadConversion(unsigned Idx, Sema &S) {
667 bool CanFix = Fix.tryToFixConversion(
668 Conversions[Idx].Bad.FromExpr,
669 Conversions[Idx].Bad.getFromType(),
670 Conversions[Idx].Bad.getToType(), S);
672 // If at least one conversion fails, the candidate cannot be fixed.
679 unsigned getNumParams() const {
681 auto STy = Surrogate->getConversionType();
682 while (STy->isPointerType() || STy->isReferenceType())
683 STy = STy->getPointeeType();
684 return STy->getAs<FunctionProtoType>()->getNumParams();
687 return Function->getNumParams();
688 return ExplicitCallArguments;
692 /// OverloadCandidateSet - A set of overload candidates, used in C++
693 /// overload resolution (C++ 13.3).
694 class OverloadCandidateSet {
696 enum CandidateSetKind {
699 /// Lookup for candidates for a call using operator syntax. Candidates
700 /// that have no parameters of class type will be skipped unless there
701 /// is a parameter of (reference to) enum type and the corresponding
702 /// argument is of the same enum type.
707 SmallVector<OverloadCandidate, 16> Candidates;
708 llvm::SmallPtrSet<Decl *, 16> Functions;
710 // Allocator for OverloadCandidate::Conversions. We store the first few
711 // elements inline to avoid allocation for small sets.
712 llvm::BumpPtrAllocator ConversionSequenceAllocator;
715 CandidateSetKind Kind;
717 unsigned NumInlineSequences;
718 llvm::AlignedCharArray<llvm::AlignOf<ImplicitConversionSequence>::Alignment,
719 16 * sizeof(ImplicitConversionSequence)> InlineSpace;
721 OverloadCandidateSet(const OverloadCandidateSet &) = delete;
722 void operator=(const OverloadCandidateSet &) = delete;
724 void destroyCandidates();
727 OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK)
728 : Loc(Loc), Kind(CSK), NumInlineSequences(0) {}
729 ~OverloadCandidateSet() { destroyCandidates(); }
731 SourceLocation getLocation() const { return Loc; }
732 CandidateSetKind getKind() const { return Kind; }
734 /// \brief Determine when this overload candidate will be new to the
736 bool isNewCandidate(Decl *F) {
737 return Functions.insert(F->getCanonicalDecl()).second;
740 /// \brief Clear out all of the candidates.
743 typedef SmallVectorImpl<OverloadCandidate>::iterator iterator;
744 iterator begin() { return Candidates.begin(); }
745 iterator end() { return Candidates.end(); }
747 size_t size() const { return Candidates.size(); }
748 bool empty() const { return Candidates.empty(); }
750 /// \brief Add a new candidate with NumConversions conversion sequence slots
751 /// to the overload set.
752 OverloadCandidate &addCandidate(unsigned NumConversions = 0) {
753 Candidates.push_back(OverloadCandidate());
754 OverloadCandidate &C = Candidates.back();
756 // Assign space from the inline array if there are enough free slots
758 if (NumConversions + NumInlineSequences <= 16) {
759 ImplicitConversionSequence *I =
760 (ImplicitConversionSequence *)InlineSpace.buffer;
761 C.Conversions = &I[NumInlineSequences];
762 NumInlineSequences += NumConversions;
764 // Otherwise get memory from the allocator.
765 C.Conversions = ConversionSequenceAllocator
766 .Allocate<ImplicitConversionSequence>(NumConversions);
769 // Construct the new objects.
770 for (unsigned i = 0; i != NumConversions; ++i)
771 new (&C.Conversions[i]) ImplicitConversionSequence();
773 C.NumConversions = NumConversions;
777 /// Find the best viable function on this overload set, if it exists.
778 OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc,
779 OverloadCandidateSet::iterator& Best,
780 bool UserDefinedConversion = false);
782 void NoteCandidates(Sema &S,
783 OverloadCandidateDisplayKind OCD,
784 ArrayRef<Expr *> Args,
786 SourceLocation Loc = SourceLocation());
789 bool isBetterOverloadCandidate(Sema &S,
790 const OverloadCandidate& Cand1,
791 const OverloadCandidate& Cand2,
793 bool UserDefinedConversion = false);
794 } // end namespace clang
796 #endif // LLVM_CLANG_SEMA_OVERLOAD_H