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/Allocator.h"
32 class CXXConstructorDecl;
33 class CXXConversionDecl;
37 /// OverloadingResult - Capture the result of performing overload
39 enum OverloadingResult {
40 OR_Success, ///< Overload resolution succeeded.
41 OR_No_Viable_Function, ///< No viable function found.
42 OR_Ambiguous, ///< Ambiguous candidates found.
43 OR_Deleted ///< Succeeded, but refers to a deleted function.
46 enum OverloadCandidateDisplayKind {
47 /// Requests that all candidates be shown. Viable candidates will
51 /// Requests that only viable candidates be shown.
55 /// ImplicitConversionKind - The kind of implicit conversion used to
56 /// convert an argument to a parameter's type. The enumerator values
57 /// match with Table 9 of (C++ 13.3.3.1.1) and are listed such that
58 /// better conversion kinds have smaller values.
59 enum ImplicitConversionKind {
60 ICK_Identity = 0, ///< Identity conversion (no conversion)
61 ICK_Lvalue_To_Rvalue, ///< Lvalue-to-rvalue conversion (C++ 4.1)
62 ICK_Array_To_Pointer, ///< Array-to-pointer conversion (C++ 4.2)
63 ICK_Function_To_Pointer, ///< Function-to-pointer (C++ 4.3)
64 ICK_NoReturn_Adjustment, ///< Removal of noreturn from a type (Clang)
65 ICK_Qualification, ///< Qualification conversions (C++ 4.4)
66 ICK_Integral_Promotion, ///< Integral promotions (C++ 4.5)
67 ICK_Floating_Promotion, ///< Floating point promotions (C++ 4.6)
68 ICK_Complex_Promotion, ///< Complex promotions (Clang extension)
69 ICK_Integral_Conversion, ///< Integral conversions (C++ 4.7)
70 ICK_Floating_Conversion, ///< Floating point conversions (C++ 4.8)
71 ICK_Complex_Conversion, ///< Complex conversions (C99 6.3.1.6)
72 ICK_Floating_Integral, ///< Floating-integral conversions (C++ 4.9)
73 ICK_Pointer_Conversion, ///< Pointer conversions (C++ 4.10)
74 ICK_Pointer_Member, ///< Pointer-to-member conversions (C++ 4.11)
75 ICK_Boolean_Conversion, ///< Boolean conversions (C++ 4.12)
76 ICK_Compatible_Conversion, ///< Conversions between compatible types in C99
77 ICK_Derived_To_Base, ///< Derived-to-base (C++ [over.best.ics])
78 ICK_Vector_Conversion, ///< Vector conversions
79 ICK_Vector_Splat, ///< A vector splat from an arithmetic type
80 ICK_Complex_Real, ///< Complex-real conversions (C99 6.3.1.7)
81 ICK_Block_Pointer_Conversion, ///< Block Pointer conversions
82 ICK_TransparentUnionConversion, ///< Transparent Union Conversions
83 ICK_Writeback_Conversion, ///< Objective-C ARC writeback conversion
84 ICK_Zero_Event_Conversion, ///< Zero constant to event (OpenCL1.2 6.12.10)
85 ICK_Num_Conversion_Kinds ///< The number of conversion kinds
88 /// ImplicitConversionCategory - The category of an implicit
89 /// conversion kind. The enumerator values match with Table 9 of
90 /// (C++ 13.3.3.1.1) and are listed such that better conversion
91 /// categories have smaller values.
92 enum ImplicitConversionCategory {
93 ICC_Identity = 0, ///< Identity
94 ICC_Lvalue_Transformation, ///< Lvalue transformation
95 ICC_Qualification_Adjustment, ///< Qualification adjustment
96 ICC_Promotion, ///< Promotion
97 ICC_Conversion ///< Conversion
100 ImplicitConversionCategory
101 GetConversionCategory(ImplicitConversionKind Kind);
103 /// ImplicitConversionRank - The rank of an implicit conversion
104 /// kind. The enumerator values match with Table 9 of (C++
105 /// 13.3.3.1.1) and are listed such that better conversion ranks
106 /// have smaller values.
107 enum ImplicitConversionRank {
108 ICR_Exact_Match = 0, ///< Exact Match
109 ICR_Promotion, ///< Promotion
110 ICR_Conversion, ///< Conversion
111 ICR_Complex_Real_Conversion, ///< Complex <-> Real conversion
112 ICR_Writeback_Conversion ///< ObjC ARC writeback conversion
115 ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind);
117 /// NarrowingKind - The kind of narrowing conversion being performed by a
118 /// standard conversion sequence according to C++11 [dcl.init.list]p7.
120 /// Not a narrowing conversion.
123 /// A narrowing conversion by virtue of the source and destination types.
126 /// A narrowing conversion, because a constant expression got narrowed.
127 NK_Constant_Narrowing,
129 /// A narrowing conversion, because a non-constant-expression variable might
130 /// have got narrowed.
131 NK_Variable_Narrowing
134 /// StandardConversionSequence - represents a standard conversion
135 /// sequence (C++ 13.3.3.1.1). A standard conversion sequence
136 /// contains between zero and three conversions. If a particular
137 /// conversion is not needed, it will be set to the identity conversion
138 /// (ICK_Identity). Note that the three conversions are
139 /// specified as separate members (rather than in an array) so that
140 /// we can keep the size of a standard conversion sequence to a
142 class StandardConversionSequence {
144 /// First -- The first conversion can be an lvalue-to-rvalue
145 /// conversion, array-to-pointer conversion, or
146 /// function-to-pointer conversion.
147 ImplicitConversionKind First : 8;
149 /// Second - The second conversion can be an integral promotion,
150 /// floating point promotion, integral conversion, floating point
151 /// conversion, floating-integral conversion, pointer conversion,
152 /// pointer-to-member conversion, or boolean conversion.
153 ImplicitConversionKind Second : 8;
155 /// Third - The third conversion can be a qualification conversion.
156 ImplicitConversionKind Third : 8;
158 /// \brief Whether this is the deprecated conversion of a
159 /// string literal to a pointer to non-const character data
161 unsigned DeprecatedStringLiteralToCharPtr : 1;
163 /// \brief Whether the qualification conversion involves a change in the
164 /// Objective-C lifetime (for automatic reference counting).
165 unsigned QualificationIncludesObjCLifetime : 1;
167 /// IncompatibleObjC - Whether this is an Objective-C conversion
168 /// that we should warn about (if we actually use it).
169 unsigned IncompatibleObjC : 1;
171 /// ReferenceBinding - True when this is a reference binding
172 /// (C++ [over.ics.ref]).
173 unsigned ReferenceBinding : 1;
175 /// DirectBinding - True when this is a reference binding that is a
176 /// direct binding (C++ [dcl.init.ref]).
177 unsigned DirectBinding : 1;
179 /// \brief Whether this is an lvalue reference binding (otherwise, it's
180 /// an rvalue reference binding).
181 unsigned IsLvalueReference : 1;
183 /// \brief Whether we're binding to a function lvalue.
184 unsigned BindsToFunctionLvalue : 1;
186 /// \brief Whether we're binding to an rvalue.
187 unsigned BindsToRvalue : 1;
189 /// \brief Whether this binds an implicit object argument to a
190 /// non-static member function without a ref-qualifier.
191 unsigned BindsImplicitObjectArgumentWithoutRefQualifier : 1;
193 /// \brief Whether this binds a reference to an object with a different
194 /// Objective-C lifetime qualifier.
195 unsigned ObjCLifetimeConversionBinding : 1;
197 /// FromType - The type that this conversion is converting
198 /// from. This is an opaque pointer that can be translated into a
202 /// ToType - The types that this conversion is converting to in
203 /// each step. This is an opaque pointer that can be translated
207 /// CopyConstructor - The copy constructor that is used to perform
208 /// this conversion, when the conversion is actually just the
209 /// initialization of an object via copy constructor. Such
210 /// conversions are either identity conversions or derived-to-base
212 CXXConstructorDecl *CopyConstructor;
214 void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
215 void setToType(unsigned Idx, QualType T) {
216 assert(Idx < 3 && "To type index is out of range");
217 ToTypePtrs[Idx] = T.getAsOpaquePtr();
219 void setAllToTypes(QualType T) {
220 ToTypePtrs[0] = T.getAsOpaquePtr();
221 ToTypePtrs[1] = ToTypePtrs[0];
222 ToTypePtrs[2] = ToTypePtrs[0];
225 QualType getFromType() const {
226 return QualType::getFromOpaquePtr(FromTypePtr);
228 QualType getToType(unsigned Idx) const {
229 assert(Idx < 3 && "To type index is out of range");
230 return QualType::getFromOpaquePtr(ToTypePtrs[Idx]);
233 void setAsIdentityConversion();
235 bool isIdentityConversion() const {
236 return Second == ICK_Identity && Third == ICK_Identity;
239 ImplicitConversionRank getRank() const;
240 NarrowingKind getNarrowingKind(ASTContext &Context, const Expr *Converted,
241 APValue &ConstantValue,
242 QualType &ConstantType) const;
243 bool isPointerConversionToBool() const;
244 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
248 /// UserDefinedConversionSequence - Represents a user-defined
249 /// conversion sequence (C++ 13.3.3.1.2).
250 struct UserDefinedConversionSequence {
251 /// \brief Represents the standard conversion that occurs before
252 /// the actual user-defined conversion.
254 /// C++11 13.3.3.1.2p1:
255 /// If the user-defined conversion is specified by a constructor
256 /// (12.3.1), the initial standard conversion sequence converts
257 /// the source type to the type required by the argument of the
258 /// constructor. If the user-defined conversion is specified by
259 /// a conversion function (12.3.2), the initial standard
260 /// conversion sequence converts the source type to the implicit
261 /// object parameter of the conversion function.
262 StandardConversionSequence Before;
264 /// EllipsisConversion - When this is true, it means user-defined
265 /// conversion sequence starts with a ... (ellipsis) conversion, instead of
266 /// a standard conversion. In this case, 'Before' field must be ignored.
267 // FIXME. I much rather put this as the first field. But there seems to be
268 // a gcc code gen. bug which causes a crash in a test. Putting it here seems
269 // to work around the crash.
270 bool EllipsisConversion : 1;
272 /// HadMultipleCandidates - When this is true, it means that the
273 /// conversion function was resolved from an overloaded set having
274 /// size greater than 1.
275 bool HadMultipleCandidates : 1;
277 /// After - Represents the standard conversion that occurs after
278 /// the actual user-defined conversion.
279 StandardConversionSequence After;
281 /// ConversionFunction - The function that will perform the
282 /// user-defined conversion. Null if the conversion is an
283 /// aggregate initialization from an initializer list.
284 FunctionDecl* ConversionFunction;
286 /// \brief The declaration that we found via name lookup, which might be
287 /// the same as \c ConversionFunction or it might be a using declaration
288 /// that refers to \c ConversionFunction.
289 DeclAccessPair FoundConversionFunction;
294 /// Represents an ambiguous user-defined conversion sequence.
295 struct AmbiguousConversionSequence {
296 typedef SmallVector<FunctionDecl*, 4> ConversionSet;
300 char Buffer[sizeof(ConversionSet)];
302 QualType getFromType() const {
303 return QualType::getFromOpaquePtr(FromTypePtr);
305 QualType getToType() const {
306 return QualType::getFromOpaquePtr(ToTypePtr);
308 void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
309 void setToType(QualType T) { ToTypePtr = T.getAsOpaquePtr(); }
311 ConversionSet &conversions() {
312 return *reinterpret_cast<ConversionSet*>(Buffer);
315 const ConversionSet &conversions() const {
316 return *reinterpret_cast<const ConversionSet*>(Buffer);
319 void addConversion(FunctionDecl *D) {
320 conversions().push_back(D);
323 typedef ConversionSet::iterator iterator;
324 iterator begin() { return conversions().begin(); }
325 iterator end() { return conversions().end(); }
327 typedef ConversionSet::const_iterator const_iterator;
328 const_iterator begin() const { return conversions().begin(); }
329 const_iterator end() const { return conversions().end(); }
333 void copyFrom(const AmbiguousConversionSequence &);
336 /// BadConversionSequence - Records information about an invalid
337 /// conversion sequence.
338 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 target is really a std::initializer_list, and the
409 /// sequence only represents the worst element conversion.
410 bool StdInitializerListElement : 1;
412 void setKind(Kind K) {
418 if (ConversionKind == AmbiguousConversion) Ambiguous.destruct();
423 /// When ConversionKind == StandardConversion, provides the
424 /// details of the standard conversion sequence.
425 StandardConversionSequence Standard;
427 /// When ConversionKind == UserDefinedConversion, provides the
428 /// details of the user-defined conversion sequence.
429 UserDefinedConversionSequence UserDefined;
431 /// When ConversionKind == AmbiguousConversion, provides the
432 /// details of the ambiguous conversion.
433 AmbiguousConversionSequence Ambiguous;
435 /// When ConversionKind == BadConversion, provides the details
436 /// of the bad conversion.
437 BadConversionSequence Bad;
440 ImplicitConversionSequence()
441 : ConversionKind(Uninitialized), StdInitializerListElement(false)
443 ~ImplicitConversionSequence() {
446 ImplicitConversionSequence(const ImplicitConversionSequence &Other)
447 : ConversionKind(Other.ConversionKind),
448 StdInitializerListElement(Other.StdInitializerListElement)
450 switch (ConversionKind) {
451 case Uninitialized: break;
452 case StandardConversion: Standard = Other.Standard; break;
453 case UserDefinedConversion: UserDefined = Other.UserDefined; break;
454 case AmbiguousConversion: Ambiguous.copyFrom(Other.Ambiguous); break;
455 case EllipsisConversion: break;
456 case BadConversion: Bad = Other.Bad; break;
460 ImplicitConversionSequence &
461 operator=(const ImplicitConversionSequence &Other) {
463 new (this) ImplicitConversionSequence(Other);
467 Kind getKind() const {
468 assert(isInitialized() && "querying uninitialized conversion");
469 return Kind(ConversionKind);
472 /// \brief Return a ranking of the implicit conversion sequence
473 /// kind, where smaller ranks represent better conversion
476 /// In particular, this routine gives user-defined conversion
477 /// sequences and ambiguous conversion sequences the same rank,
478 /// per C++ [over.best.ics]p10.
479 unsigned getKindRank() const {
481 case StandardConversion:
484 case UserDefinedConversion:
485 case AmbiguousConversion:
488 case EllipsisConversion:
495 llvm_unreachable("Invalid ImplicitConversionSequence::Kind!");
498 bool isBad() const { return getKind() == BadConversion; }
499 bool isStandard() const { return getKind() == StandardConversion; }
500 bool isEllipsis() const { return getKind() == EllipsisConversion; }
501 bool isAmbiguous() const { return getKind() == AmbiguousConversion; }
502 bool isUserDefined() const { return getKind() == UserDefinedConversion; }
503 bool isFailure() const { return isBad() || isAmbiguous(); }
505 /// Determines whether this conversion sequence has been
506 /// initialized. Most operations should never need to query
507 /// uninitialized conversions and should assert as above.
508 bool isInitialized() const { return ConversionKind != Uninitialized; }
510 /// Sets this sequence as a bad conversion for an explicit argument.
511 void setBad(BadConversionSequence::FailureKind Failure,
512 Expr *FromExpr, QualType ToType) {
513 setKind(BadConversion);
514 Bad.init(Failure, FromExpr, ToType);
517 /// Sets this sequence as a bad conversion for an implicit argument.
518 void setBad(BadConversionSequence::FailureKind Failure,
519 QualType FromType, QualType ToType) {
520 setKind(BadConversion);
521 Bad.init(Failure, FromType, ToType);
524 void setStandard() { setKind(StandardConversion); }
525 void setEllipsis() { setKind(EllipsisConversion); }
526 void setUserDefined() { setKind(UserDefinedConversion); }
527 void setAmbiguous() {
528 if (ConversionKind == AmbiguousConversion) return;
529 ConversionKind = AmbiguousConversion;
530 Ambiguous.construct();
533 /// \brief Whether the target is really a std::initializer_list, and the
534 /// sequence only represents the worst element conversion.
535 bool isStdInitializerListElement() const {
536 return StdInitializerListElement;
539 void setStdInitializerListElement(bool V = true) {
540 StdInitializerListElement = V;
543 // The result of a comparison between implicit conversion
544 // sequences. Use Sema::CompareImplicitConversionSequences to
545 // actually perform the comparison.
548 Indistinguishable = 0,
552 void DiagnoseAmbiguousConversion(Sema &S,
553 SourceLocation CaretLoc,
554 const PartialDiagnostic &PDiag) const;
559 enum OverloadFailureKind {
560 ovl_fail_too_many_arguments,
561 ovl_fail_too_few_arguments,
562 ovl_fail_bad_conversion,
563 ovl_fail_bad_deduction,
565 /// This conversion candidate was not considered because it
566 /// duplicates the work of a trivial or derived-to-base
568 ovl_fail_trivial_conversion,
570 /// This conversion candidate is not viable because its result
571 /// type is not implicitly convertible to the desired type.
572 ovl_fail_bad_final_conversion,
574 /// This conversion function template specialization candidate is not
575 /// viable because the final conversion was not an exact match.
576 ovl_fail_final_conversion_not_exact,
578 /// (CUDA) This candidate was not viable because the callee
579 /// was not accessible from the caller's target (i.e. host->device,
580 /// global->host, device->host).
583 /// This candidate function was not viable because an enable_if
584 /// attribute disabled it.
588 /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
589 struct OverloadCandidate {
590 /// Function - The actual function that this candidate
591 /// represents. When NULL, this is a built-in candidate
592 /// (C++ [over.oper]) or a surrogate for a conversion to a
593 /// function pointer or reference (C++ [over.call.object]).
594 FunctionDecl *Function;
596 /// FoundDecl - The original declaration that was looked up /
597 /// invented / otherwise found, together with its access.
598 /// Might be a UsingShadowDecl or a FunctionTemplateDecl.
599 DeclAccessPair FoundDecl;
601 // BuiltinTypes - Provides the return and parameter types of a
602 // built-in overload candidate. Only valid when Function is NULL.
605 QualType ParamTypes[3];
608 /// Surrogate - The conversion function for which this candidate
609 /// is a surrogate, but only if IsSurrogate is true.
610 CXXConversionDecl *Surrogate;
612 /// Conversions - The conversion sequences used to convert the
613 /// function arguments to the function parameters, the pointer points to a
614 /// fixed size array with NumConversions elements. The memory is owned by
615 /// the OverloadCandidateSet.
616 ImplicitConversionSequence *Conversions;
618 /// The FixIt hints which can be used to fix the Bad candidate.
619 ConversionFixItGenerator Fix;
621 /// NumConversions - The number of elements in the Conversions array.
622 unsigned NumConversions;
624 /// Viable - True to indicate that this overload candidate is viable.
627 /// IsSurrogate - True to indicate that this candidate is a
628 /// surrogate for a conversion to a function pointer or reference
629 /// (C++ [over.call.object]).
632 /// IgnoreObjectArgument - True to indicate that the first
633 /// argument's conversion, which for this function represents the
634 /// implicit object argument, should be ignored. This will be true
635 /// when the candidate is a static member function (where the
636 /// implicit object argument is just a placeholder) or a
637 /// non-static member function when the call doesn't have an
639 bool IgnoreObjectArgument;
641 /// FailureKind - The reason why this candidate is not viable.
642 /// Actually an OverloadFailureKind.
643 unsigned char FailureKind;
645 /// \brief The number of call arguments that were explicitly provided,
646 /// to be used while performing partial ordering of function templates.
647 unsigned ExplicitCallArguments;
650 DeductionFailureInfo DeductionFailure;
652 /// FinalConversion - For a conversion function (where Function is
653 /// a CXXConversionDecl), the standard conversion that occurs
654 /// after the call to the overload candidate to convert the result
655 /// of calling the conversion function to the required type.
656 StandardConversionSequence FinalConversion;
659 /// hasAmbiguousConversion - Returns whether this overload
660 /// candidate requires an ambiguous conversion or not.
661 bool hasAmbiguousConversion() const {
662 for (unsigned i = 0, e = NumConversions; i != e; ++i) {
663 if (!Conversions[i].isInitialized()) return false;
664 if (Conversions[i].isAmbiguous()) return true;
669 bool TryToFixBadConversion(unsigned Idx, Sema &S) {
670 bool CanFix = Fix.tryToFixConversion(
671 Conversions[Idx].Bad.FromExpr,
672 Conversions[Idx].Bad.getFromType(),
673 Conversions[Idx].Bad.getToType(), S);
675 // If at least one conversion fails, the candidate cannot be fixed.
682 unsigned getNumParams() const {
684 auto STy = Surrogate->getConversionType();
685 while (STy->isPointerType() || STy->isReferenceType())
686 STy = STy->getPointeeType();
687 return STy->getAs<FunctionProtoType>()->getNumParams();
690 return Function->getNumParams();
691 return ExplicitCallArguments;
695 /// OverloadCandidateSet - A set of overload candidates, used in C++
696 /// overload resolution (C++ 13.3).
697 class OverloadCandidateSet {
699 enum CandidateSetKind {
702 /// Lookup for candidates for a call using operator syntax. Candidates
703 /// that have no parameters of class type will be skipped unless there
704 /// is a parameter of (reference to) enum type and the corresponding
705 /// argument is of the same enum type.
710 SmallVector<OverloadCandidate, 16> Candidates;
711 llvm::SmallPtrSet<Decl *, 16> Functions;
713 // Allocator for OverloadCandidate::Conversions. We store the first few
714 // elements inline to avoid allocation for small sets.
715 llvm::BumpPtrAllocator ConversionSequenceAllocator;
718 CandidateSetKind Kind;
720 unsigned NumInlineSequences;
721 char InlineSpace[16 * sizeof(ImplicitConversionSequence)];
723 OverloadCandidateSet(const OverloadCandidateSet &) LLVM_DELETED_FUNCTION;
724 void operator=(const OverloadCandidateSet &) LLVM_DELETED_FUNCTION;
726 void destroyCandidates();
729 OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK)
730 : Loc(Loc), Kind(CSK), NumInlineSequences(0) {}
731 ~OverloadCandidateSet() { destroyCandidates(); }
733 SourceLocation getLocation() const { return Loc; }
734 CandidateSetKind getKind() const { return Kind; }
736 /// \brief Determine when this overload candidate will be new to the
738 bool isNewCandidate(Decl *F) {
739 return Functions.insert(F->getCanonicalDecl());
742 /// \brief Clear out all of the candidates.
745 typedef SmallVectorImpl<OverloadCandidate>::iterator iterator;
746 iterator begin() { return Candidates.begin(); }
747 iterator end() { return Candidates.end(); }
749 size_t size() const { return Candidates.size(); }
750 bool empty() const { return Candidates.empty(); }
752 /// \brief Add a new candidate with NumConversions conversion sequence slots
753 /// to the overload set.
754 OverloadCandidate &addCandidate(unsigned NumConversions = 0) {
755 Candidates.push_back(OverloadCandidate());
756 OverloadCandidate &C = Candidates.back();
758 // Assign space from the inline array if there are enough free slots
760 if (NumConversions + NumInlineSequences <= 16) {
761 ImplicitConversionSequence *I =
762 (ImplicitConversionSequence*)InlineSpace;
763 C.Conversions = &I[NumInlineSequences];
764 NumInlineSequences += NumConversions;
766 // Otherwise get memory from the allocator.
767 C.Conversions = ConversionSequenceAllocator
768 .Allocate<ImplicitConversionSequence>(NumConversions);
771 // Construct the new objects.
772 for (unsigned i = 0; i != NumConversions; ++i)
773 new (&C.Conversions[i]) ImplicitConversionSequence();
775 C.NumConversions = NumConversions;
779 /// Find the best viable function on this overload set, if it exists.
780 OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc,
781 OverloadCandidateSet::iterator& Best,
782 bool UserDefinedConversion = false);
784 void NoteCandidates(Sema &S,
785 OverloadCandidateDisplayKind OCD,
786 ArrayRef<Expr *> Args,
788 SourceLocation Loc = SourceLocation());
791 bool isBetterOverloadCandidate(Sema &S,
792 const OverloadCandidate& Cand1,
793 const OverloadCandidate& Cand2,
795 bool UserDefinedConversion = false);
796 } // end namespace clang
798 #endif // LLVM_CLANG_SEMA_OVERLOAD_H