clang  3.7.0
Overload.h
Go to the documentation of this file.
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"
26 #include "llvm/ADT/SmallPtrSet.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/Support/AlignOf.h"
29 #include "llvm/Support/Allocator.h"
30 
31 namespace clang {
32  class ASTContext;
33  class CXXConstructorDecl;
34  class CXXConversionDecl;
35  class FunctionDecl;
36  class Sema;
37 
38  /// OverloadingResult - Capture the result of performing overload
39  /// resolution.
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.
45  };
46 
48  /// Requests that all candidates be shown. Viable candidates will
49  /// be printed first.
51 
52  /// Requests that only viable candidates be shown.
54  };
55 
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.
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
87  };
88 
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.
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
99  };
100 
102 
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.
108 
109  /// A narrowing conversion by virtue of the source and destination types.
111 
112  /// A narrowing conversion, because a constant expression got narrowed.
114 
115  /// A narrowing conversion, because a non-constant-expression variable might
116  /// have got narrowed.
118  };
119 
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
127  /// single word.
129  public:
130  /// First -- The first conversion can be an lvalue-to-rvalue
131  /// conversion, array-to-pointer conversion, or
132  /// function-to-pointer conversion.
134 
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.
140 
141  /// Third - The third conversion can be a qualification conversion.
143 
144  /// \brief Whether this is the deprecated conversion of a
145  /// string literal to a pointer to non-const character data
146  /// (C++ 4.2p2).
148 
149  /// \brief Whether the qualification conversion involves a change in the
150  /// Objective-C lifetime (for automatic reference counting).
152 
153  /// IncompatibleObjC - Whether this is an Objective-C conversion
154  /// that we should warn about (if we actually use it).
155  unsigned IncompatibleObjC : 1;
156 
157  /// ReferenceBinding - True when this is a reference binding
158  /// (C++ [over.ics.ref]).
159  unsigned ReferenceBinding : 1;
160 
161  /// DirectBinding - True when this is a reference binding that is a
162  /// direct binding (C++ [dcl.init.ref]).
163  unsigned DirectBinding : 1;
164 
165  /// \brief Whether this is an lvalue reference binding (otherwise, it's
166  /// an rvalue reference binding).
167  unsigned IsLvalueReference : 1;
168 
169  /// \brief Whether we're binding to a function lvalue.
170  unsigned BindsToFunctionLvalue : 1;
171 
172  /// \brief Whether we're binding to an rvalue.
173  unsigned BindsToRvalue : 1;
174 
175  /// \brief Whether this binds an implicit object argument to a
176  /// non-static member function without a ref-qualifier.
178 
179  /// \brief Whether this binds a reference to an object with a different
180  /// Objective-C lifetime qualifier.
182 
183  /// FromType - The type that this conversion is converting
184  /// from. This is an opaque pointer that can be translated into a
185  /// QualType.
186  void *FromTypePtr;
187 
188  /// ToType - The types that this conversion is converting to in
189  /// each step. This is an opaque pointer that can be translated
190  /// into a QualType.
191  void *ToTypePtrs[3];
192 
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
197  /// conversions.
199 
201  void setToType(unsigned Idx, QualType T) {
202  assert(Idx < 3 && "To type index is out of range");
203  ToTypePtrs[Idx] = T.getAsOpaquePtr();
204  }
206  ToTypePtrs[0] = T.getAsOpaquePtr();
207  ToTypePtrs[1] = ToTypePtrs[0];
208  ToTypePtrs[2] = ToTypePtrs[0];
209  }
210 
213  }
214  QualType getToType(unsigned Idx) const {
215  assert(Idx < 3 && "To type index is out of range");
217  }
218 
220 
221  bool isIdentityConversion() const {
222  return Second == ICK_Identity && Third == ICK_Identity;
223  }
224 
227  APValue &ConstantValue,
228  QualType &ConstantType) const;
229  bool isPointerConversionToBool() const;
231  void dump() const;
232  };
233 
234  /// UserDefinedConversionSequence - Represents a user-defined
235  /// conversion sequence (C++ 13.3.3.1.2).
237  /// \brief Represents the standard conversion that occurs before
238  /// the actual user-defined conversion.
239  ///
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.
249 
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.
257 
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.
262 
263  /// After - Represents the standard conversion that occurs after
264  /// the actual user-defined conversion.
266 
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.
271 
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.
276 
277  void dump() const;
278  };
279 
280  /// Represents an ambiguous user-defined conversion sequence.
283 
284  void *FromTypePtr;
285  void *ToTypePtr;
286  char Buffer[sizeof(ConversionSet)];
287 
290  }
291  QualType getToType() const {
293  }
296 
298  return *reinterpret_cast<ConversionSet*>(Buffer);
299  }
300 
301  const ConversionSet &conversions() const {
302  return *reinterpret_cast<const ConversionSet*>(Buffer);
303  }
304 
306  conversions().push_back(D);
307  }
308 
309  typedef ConversionSet::iterator iterator;
310  iterator begin() { return conversions().begin(); }
311  iterator end() { return conversions().end(); }
312 
313  typedef ConversionSet::const_iterator const_iterator;
314  const_iterator begin() const { return conversions().begin(); }
315  const_iterator end() const { return conversions().end(); }
316 
317  void construct();
318  void destruct();
320  };
321 
322  /// BadConversionSequence - Records information about an invalid
323  /// conversion sequence.
325  enum FailureKind {
331  };
332 
333  // This can be null, e.g. for implicit object arguments.
335 
337 
338  private:
339  // The type we're converting from (an opaque QualType).
340  void *FromTy;
341 
342  // The type we're converting to (an opaque QualType).
343  void *ToTy;
344 
345  public:
346  void init(FailureKind K, Expr *From, QualType To) {
347  init(K, From->getType(), To);
348  FromExpr = From;
349  }
350  void init(FailureKind K, QualType From, QualType To) {
351  Kind = K;
352  FromExpr = nullptr;
353  setFromType(From);
354  setToType(To);
355  }
356 
357  QualType getFromType() const { return QualType::getFromOpaquePtr(FromTy); }
359 
360  void setFromExpr(Expr *E) {
361  FromExpr = E;
362  setFromType(E->getType());
363  }
364  void setFromType(QualType T) { FromTy = T.getAsOpaquePtr(); }
365  void setToType(QualType T) { ToTy = T.getAsOpaquePtr(); }
366  };
367 
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).
373  public:
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).
378  enum Kind {
384  };
385 
386  private:
387  enum {
388  Uninitialized = BadConversion + 1
389  };
390 
391  /// ConversionKind - The kind of implicit conversion sequence.
392  unsigned ConversionKind : 30;
393 
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;
397 
398  void setKind(Kind K) {
399  destruct();
400  ConversionKind = K;
401  }
402 
403  void destruct() {
404  if (ConversionKind == AmbiguousConversion) Ambiguous.destruct();
405  }
406 
407  public:
408  union {
409  /// When ConversionKind == StandardConversion, provides the
410  /// details of the standard conversion sequence.
412 
413  /// When ConversionKind == UserDefinedConversion, provides the
414  /// details of the user-defined conversion sequence.
416 
417  /// When ConversionKind == AmbiguousConversion, provides the
418  /// details of the ambiguous conversion.
420 
421  /// When ConversionKind == BadConversion, provides the details
422  /// of the bad conversion.
424  };
425 
427  : ConversionKind(Uninitialized), StdInitializerListElement(false)
428  {}
430  destruct();
431  }
433  : ConversionKind(Other.ConversionKind),
434  StdInitializerListElement(Other.StdInitializerListElement)
435  {
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;
443  }
444  }
445 
448  destruct();
449  new (this) ImplicitConversionSequence(Other);
450  return *this;
451  }
452 
453  Kind getKind() const {
454  assert(isInitialized() && "querying uninitialized conversion");
455  return Kind(ConversionKind);
456  }
457 
458  /// \brief Return a ranking of the implicit conversion sequence
459  /// kind, where smaller ranks represent better conversion
460  /// sequences.
461  ///
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 {
466  switch (getKind()) {
467  case StandardConversion:
468  return 0;
469 
471  case AmbiguousConversion:
472  return 1;
473 
474  case EllipsisConversion:
475  return 2;
476 
477  case BadConversion:
478  return 3;
479  }
480 
481  llvm_unreachable("Invalid ImplicitConversionSequence::Kind!");
482  }
483 
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(); }
490 
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; }
495 
496  /// Sets this sequence as a bad conversion for an explicit argument.
498  Expr *FromExpr, QualType ToType) {
499  setKind(BadConversion);
500  Bad.init(Failure, FromExpr, ToType);
501  }
502 
503  /// Sets this sequence as a bad conversion for an implicit argument.
505  QualType FromType, QualType ToType) {
506  setKind(BadConversion);
507  Bad.init(Failure, FromType, ToType);
508  }
509 
510  void setStandard() { setKind(StandardConversion); }
511  void setEllipsis() { setKind(EllipsisConversion); }
513  void setAmbiguous() {
514  if (ConversionKind == AmbiguousConversion) return;
515  ConversionKind = AmbiguousConversion;
517  }
518 
519  /// \brief Whether the target is really a std::initializer_list, and the
520  /// sequence only represents the worst element conversion.
522  return StdInitializerListElement;
523  }
524 
525  void setStdInitializerListElement(bool V = true) {
526  StdInitializerListElement = V;
527  }
528 
529  // The result of a comparison between implicit conversion
530  // sequences. Use Sema::CompareImplicitConversionSequences to
531  // actually perform the comparison.
532  enum CompareKind {
533  Better = -1,
535  Worse = 1
536  };
537 
539  SourceLocation CaretLoc,
540  const PartialDiagnostic &PDiag) const;
541 
542  void dump() const;
543  };
544 
550 
551  /// This conversion candidate was not considered because it
552  /// duplicates the work of a trivial or derived-to-base
553  /// conversion.
555 
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.
560  ///
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.
566 
567  /// This conversion candidate is not viable because its result
568  /// type is not implicitly convertible to the desired type.
570 
571  /// This conversion function template specialization candidate is not
572  /// viable because the final conversion was not an exact match.
574 
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).
579 
580  /// This candidate function was not viable because an enable_if
581  /// attribute disabled it.
583  };
584 
585  /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
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]).
592 
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.
597 
598  // BuiltinTypes - Provides the return and parameter types of a
599  // built-in overload candidate. Only valid when Function is NULL.
600  struct {
603  } BuiltinTypes;
604 
605  /// Surrogate - The conversion function for which this candidate
606  /// is a surrogate, but only if IsSurrogate is true.
608 
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.
614 
615  /// The FixIt hints which can be used to fix the Bad candidate.
617 
618  /// NumConversions - The number of elements in the Conversions array.
619  unsigned NumConversions;
620 
621  /// Viable - True to indicate that this overload candidate is viable.
622  bool Viable;
623 
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]).
628 
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
635  /// object argument.
637 
638  /// FailureKind - The reason why this candidate is not viable.
639  /// Actually an OverloadFailureKind.
640  unsigned char FailureKind;
641 
642  /// \brief The number of call arguments that were explicitly provided,
643  /// to be used while performing partial ordering of function templates.
645 
646  union {
648 
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.
654  };
655 
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;
662  }
663  return false;
664  }
665 
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);
671 
672  // If at least one conversion fails, the candidate cannot be fixed.
673  if (!CanFix)
674  Fix.clear();
675 
676  return CanFix;
677  }
678 
679  unsigned getNumParams() const {
680  if (IsSurrogate) {
681  auto STy = Surrogate->getConversionType();
682  while (STy->isPointerType() || STy->isReferenceType())
683  STy = STy->getPointeeType();
684  return STy->getAs<FunctionProtoType>()->getNumParams();
685  }
686  if (Function)
687  return Function->getNumParams();
688  return ExplicitCallArguments;
689  }
690  };
691 
692  /// OverloadCandidateSet - A set of overload candidates, used in C++
693  /// overload resolution (C++ 13.3).
695  public:
697  /// Normal lookup.
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.
704  };
705 
706  private:
708  llvm::SmallPtrSet<Decl *, 16> Functions;
709 
710  // Allocator for OverloadCandidate::Conversions. We store the first few
711  // elements inline to avoid allocation for small sets.
712  llvm::BumpPtrAllocator ConversionSequenceAllocator;
713 
714  SourceLocation Loc;
716 
717  unsigned NumInlineSequences;
718  llvm::AlignedCharArray<llvm::AlignOf<ImplicitConversionSequence>::Alignment,
719  16 * sizeof(ImplicitConversionSequence)> InlineSpace;
720 
721  OverloadCandidateSet(const OverloadCandidateSet &) = delete;
722  void operator=(const OverloadCandidateSet &) = delete;
723 
724  void destroyCandidates();
725 
726  public:
728  : Loc(Loc), Kind(CSK), NumInlineSequences(0) {}
729  ~OverloadCandidateSet() { destroyCandidates(); }
730 
731  SourceLocation getLocation() const { return Loc; }
732  CandidateSetKind getKind() const { return Kind; }
733 
734  /// \brief Determine when this overload candidate will be new to the
735  /// overload set.
736  bool isNewCandidate(Decl *F) {
737  return Functions.insert(F->getCanonicalDecl()).second;
738  }
739 
740  /// \brief Clear out all of the candidates.
741  void clear();
742 
744  iterator begin() { return Candidates.begin(); }
745  iterator end() { return Candidates.end(); }
746 
747  size_t size() const { return Candidates.size(); }
748  bool empty() const { return Candidates.empty(); }
749 
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();
755 
756  // Assign space from the inline array if there are enough free slots
757  // available.
758  if (NumConversions + NumInlineSequences <= 16) {
760  (ImplicitConversionSequence *)InlineSpace.buffer;
761  C.Conversions = &I[NumInlineSequences];
762  NumInlineSequences += NumConversions;
763  } else {
764  // Otherwise get memory from the allocator.
765  C.Conversions = ConversionSequenceAllocator
766  .Allocate<ImplicitConversionSequence>(NumConversions);
767  }
768 
769  // Construct the new objects.
770  for (unsigned i = 0; i != NumConversions; ++i)
772 
773  C.NumConversions = NumConversions;
774  return C;
775  }
776 
777  /// Find the best viable function on this overload set, if it exists.
780  bool UserDefinedConversion = false);
781 
782  void NoteCandidates(Sema &S,
784  ArrayRef<Expr *> Args,
785  StringRef Opc = "",
787  };
788 
789  bool isBetterOverloadCandidate(Sema &S,
790  const OverloadCandidate& Cand1,
791  const OverloadCandidate& Cand2,
792  SourceLocation Loc,
793  bool UserDefinedConversion = false);
794 } // end namespace clang
795 
796 #endif // LLVM_CLANG_SEMA_OVERLOAD_H
unsigned ExplicitCallArguments
The number of call arguments that were explicitly provided, to be used while performing partial order...
Definition: Overload.h:644
DeclAccessPair FoundConversionFunction
The declaration that we found via name lookup, which might be the same as ConversionFunction or it mi...
Definition: Overload.h:275
unsigned DeprecatedStringLiteralToCharPtr
Whether this is the deprecated conversion of a string literal to a pointer to non-const character dat...
Definition: Overload.h:147
void setFromType(QualType T)
Definition: Overload.h:364
char Buffer[sizeof(ConversionSet)]
Definition: Overload.h:286
void setStdInitializerListElement(bool V=true)
Definition: Overload.h:525
ImplicitConversionKind
Definition: Overload.h:60
void setFromType(QualType T)
Definition: Overload.h:200
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Definition: DeclCXX.h:2445
Vector conversions.
Definition: Overload.h:79
bool tryToFixConversion(const Expr *FromExpr, const QualType FromQTy, const QualType ToQTy, Sema &S)
If possible, generates and stores a fix for the given conversion.
Complex conversions (C99 6.3.1.6)
Definition: Overload.h:72
UserDefinedConversionSequence UserDefined
Definition: Overload.h:415
Defines the C++ template declaration subclasses.
Not a narrowing conversion.
Definition: Overload.h:107
ImplicitConversionRank
Definition: Overload.h:93
Ambiguous candidates found.
Definition: Overload.h:43
Conversions between compatible types in C99.
Definition: Overload.h:77
ConversionSet::iterator iterator
Definition: Overload.h:309
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2147
void * getAsOpaquePtr() const
Definition: Type.h:614
Exact Match.
Definition: Overload.h:94
SmallVector< FunctionDecl *, 4 > ConversionSet
Definition: Overload.h:282
Removal of noreturn from a type (Clang)
Definition: Overload.h:65
Conversion.
Definition: Overload.h:96
ImplicitConversionSequence(const ImplicitConversionSequence &Other)
Definition: Overload.h:432
Boolean conversions (C++ 4.12)
Definition: Overload.h:76
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:89
OverloadCandidate & addCandidate(unsigned NumConversions=0)
Add a new candidate with NumConversions conversion sequence slots to the overload set...
Definition: Overload.h:752
ImplicitConversionSequence * Conversions
Definition: Overload.h:613
unsigned BindsToFunctionLvalue
Whether we're binding to a function lvalue.
Definition: Overload.h:170
BadConversionSequence Bad
Definition: Overload.h:423
Identity conversion (no conversion)
Definition: Overload.h:61
ConversionSet & conversions()
Definition: Overload.h:297
QualType getToType() const
Definition: Overload.h:358
Floating point conversions (C++ 4.8)
Definition: Overload.h:71
const_iterator end() const
Definition: Overload.h:315
OverloadCandidateDisplayKind
Definition: Overload.h:47
Floating point promotions (C++ 4.6)
Definition: Overload.h:68
ImplicitConversionRank getRank() const
unsigned BindsToRvalue
Whether we're binding to an rvalue.
Definition: Overload.h:173
Succeeded, but refers to a deleted function.
Definition: Overload.h:44
ImplicitConversionSequence & operator=(const ImplicitConversionSequence &Other)
Definition: Overload.h:447
unsigned QualificationIncludesObjCLifetime
Whether the qualification conversion involves a change in the Objective-C lifetime (for automatic ref...
Definition: Overload.h:151
ImplicitConversionKind Second
Definition: Overload.h:139
A narrowing conversion, because a constant expression got narrowed.
Definition: Overload.h:113
unsigned IsLvalueReference
Whether this is an lvalue reference binding (otherwise, it's an rvalue reference binding).
Definition: Overload.h:167
NarrowingKind
Definition: Overload.h:105
Qualification conversions (C++ 4.4)
Definition: Overload.h:66
NarrowingKind getNarrowingKind(ASTContext &Context, const Expr *Converted, APValue &ConstantValue, QualType &ConstantType) const
The number of conversion kinds.
Definition: Overload.h:86
ImplicitConversionKind Third
Third - The third conversion can be a qualification conversion.
Definition: Overload.h:142
Complex <-> Real conversion.
Definition: Overload.h:97
bool Viable
Viable - True to indicate that this overload candidate is viable.
Definition: Overload.h:622
Integral promotions (C++ 4.5)
Definition: Overload.h:67
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:733
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:258
bool isBetterOverloadCandidate(Sema &S, const OverloadCandidate &Cand1, const OverloadCandidate &Cand2, SourceLocation Loc, bool UserDefinedConversion=false)
Transparent Union Conversions.
Definition: Overload.h:83
ASTContext * Context
bool isNewCandidate(Decl *F)
Determine when this overload candidate will be new to the overload set.
Definition: Overload.h:736
A narrowing conversion by virtue of the source and destination types.
Definition: Overload.h:110
Promotion.
Definition: Overload.h:95
StandardConversionSequence FinalConversion
Definition: Overload.h:653
QualType getPointeeType() const
Definition: Type.cpp:414
ObjC ARC writeback conversion.
Definition: Overload.h:98
bool hasAmbiguousConversion() const
Definition: Overload.h:658
Represents an ambiguous user-defined conversion sequence.
Definition: Overload.h:281
StandardConversionSequence After
Definition: Overload.h:265
SmallVectorImpl< OverloadCandidate >::iterator iterator
Definition: Overload.h:743
void copyFrom(const AmbiguousConversionSequence &)
CXXConstructorDecl * CopyConstructor
Definition: Overload.h:198
QualType ParamTypes[3]
Definition: Overload.h:602
void addConversion(FunctionDecl *D)
Definition: Overload.h:305
Overload resolution succeeded.
Definition: Overload.h:41
QualType getFromType() const
Definition: Overload.h:357
Floating-integral conversions (C++ 4.9)
Definition: Overload.h:73
void init(FailureKind K, Expr *From, QualType To)
Definition: Overload.h:346
bool TryToFixBadConversion(unsigned Idx, Sema &S)
Definition: Overload.h:666
QualType getFromType() const
Definition: Overload.h:211
CXXConversionDecl * Surrogate
Definition: Overload.h:607
void NoteCandidates(Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr * > Args, StringRef Opc="", SourceLocation Loc=SourceLocation())
StandardConversionSequence Standard
Definition: Overload.h:411
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2405
Lvalue-to-rvalue conversion (C++ 4.1)
Definition: Overload.h:62
OverloadFailureKind
Definition: Overload.h:545
unsigned ObjCLifetimeConversionBinding
Whether this binds a reference to an object with a different Objective-C lifetime qualifier...
Definition: Overload.h:181
unsigned NumConversions
NumConversions - The number of elements in the Conversions array.
Definition: Overload.h:619
bool isIdentityConversion() const
Definition: Overload.h:221
QualType getFromType() const
Definition: Overload.h:288
Integral conversions (C++ 4.7)
Definition: Overload.h:70
Complex promotions (Clang extension)
Definition: Overload.h:69
#define false
Definition: stdbool.h:33
Kind
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
Definition: Overload.h:586
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
unsigned getNumParams() const
Definition: Decl.cpp:2651
A vector splat from an arithmetic type.
Definition: Overload.h:80
OverloadingResult
Definition: Overload.h:40
Objective-C ARC writeback conversion.
Definition: Overload.h:84
void init(FailureKind K, QualType From, QualType To)
Definition: Overload.h:350
bool isStdInitializerListElement() const
Whether the target is really a std::initializer_list, and the sequence only represents the worst elem...
Definition: Overload.h:521
Pointer conversions (C++ 4.10)
Definition: Overload.h:74
CandidateSetKind getKind() const
Definition: Overload.h:732
QualType getToType(unsigned Idx) const
Definition: Overload.h:214
Derived-to-base (C++ [over.best.ics])
Definition: Overload.h:78
Complex-real conversions (C99 6.3.1.7)
Definition: Overload.h:81
void setBad(BadConversionSequence::FailureKind Failure, Expr *FromExpr, QualType ToType)
Sets this sequence as a bad conversion for an explicit argument.
Definition: Overload.h:497
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:615
void setFromExpr(Expr *E)
Definition: Overload.h:360
ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind)
QualType getType() const
Definition: Expr.h:125
void DiagnoseAmbiguousConversion(Sema &S, SourceLocation CaretLoc, const PartialDiagnostic &PDiag) const
OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK)
Definition: Overload.h:727
ConversionSet::const_iterator const_iterator
Definition: Overload.h:313
const ConversionSet & conversions() const
Definition: Overload.h:301
Array-to-pointer conversion (C++ 4.2)
Definition: Overload.h:63
StandardConversionSequence Before
Represents the standard conversion that occurs before the actual user-defined conversion.
Definition: Overload.h:248
Requests that only viable candidates be shown.
Definition: Overload.h:53
FunctionDecl * Function
Definition: Overload.h:591
unsigned getNumParams() const
Definition: Overload.h:679
void setToType(QualType T)
Definition: Overload.h:365
void setAllToTypes(QualType T)
Definition: Overload.h:205
const T * getAs() const
Definition: Type.h:5555
unsigned getKindRank() const
Return a ranking of the implicit conversion sequence kind, where smaller ranks represent better conve...
Definition: Overload.h:465
unsigned BindsImplicitObjectArgumentWithoutRefQualifier
Whether this binds an implicit object argument to a non-static member function without a ref-qualifie...
Definition: Overload.h:177
unsigned char FailureKind
Definition: Overload.h:640
void setBad(BadConversionSequence::FailureKind Failure, QualType FromType, QualType ToType)
Sets this sequence as a bad conversion for an implicit argument.
Definition: Overload.h:504
DeclAccessPair FoundDecl
Definition: Overload.h:596
Block Pointer conversions.
Definition: Overload.h:82
ConversionFixItGenerator Fix
The FixIt hints which can be used to fix the Bad candidate.
Definition: Overload.h:616
AmbiguousConversionSequence Ambiguous
Definition: Overload.h:419
const_iterator begin() const
Definition: Overload.h:314
Function-to-pointer (C++ 4.3)
Definition: Overload.h:64
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best, bool UserDefinedConversion=false)
Find the best viable function on this overload set, if it exists.
Zero constant to event (OpenCL1.2 6.12.10)
Definition: Overload.h:85
void clear()
Clear out all of the candidates.
ImplicitConversionKind First
Definition: Overload.h:133
struct clang::OverloadCandidate::@202 BuiltinTypes
No viable function found.
Definition: Overload.h:42
DeductionFailureInfo DeductionFailure
Definition: Overload.h:647
size_t size() const
Definition: Overload.h:747
Pointer-to-member conversions (C++ 4.11)
Definition: Overload.h:75
void setToType(unsigned Idx, QualType T)
Definition: Overload.h:201
bool isPointerConversionToVoidPointer(ASTContext &Context) const
SourceLocation getLocation() const
Definition: Overload.h:731