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