clang  3.9.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_C_Only_Conversion, ///< Conversions allowed in C, but not C++
87  ICK_Num_Conversion_Kinds, ///< The number of conversion kinds
88  };
89 
90  /// ImplicitConversionRank - The rank of an implicit conversion
91  /// kind. The enumerator values match with Table 9 of (C++
92  /// 13.3.3.1.1) and are listed such that better conversion ranks
93  /// have smaller values.
95  ICR_Exact_Match = 0, ///< Exact Match
96  ICR_Promotion, ///< Promotion
97  ICR_Conversion, ///< Conversion
98  ICR_Complex_Real_Conversion, ///< Complex <-> Real conversion
99  ICR_Writeback_Conversion, ///< ObjC ARC writeback conversion
100  ICR_C_Conversion ///< Conversion only allowed in the C standard.
101  /// (e.g. void* to char*)
102  };
103 
105 
106  /// NarrowingKind - The kind of narrowing conversion being performed by a
107  /// standard conversion sequence according to C++11 [dcl.init.list]p7.
109  /// Not a narrowing conversion.
111 
112  /// A narrowing conversion by virtue of the source and destination types.
114 
115  /// A narrowing conversion, because a constant expression got narrowed.
117 
118  /// A narrowing conversion, because a non-constant-expression variable might
119  /// have got narrowed.
121  };
122 
123  /// StandardConversionSequence - represents a standard conversion
124  /// sequence (C++ 13.3.3.1.1). A standard conversion sequence
125  /// contains between zero and three conversions. If a particular
126  /// conversion is not needed, it will be set to the identity conversion
127  /// (ICK_Identity). Note that the three conversions are
128  /// specified as separate members (rather than in an array) so that
129  /// we can keep the size of a standard conversion sequence to a
130  /// single word.
132  public:
133  /// First -- The first conversion can be an lvalue-to-rvalue
134  /// conversion, array-to-pointer conversion, or
135  /// function-to-pointer conversion.
137 
138  /// Second - The second conversion can be an integral promotion,
139  /// floating point promotion, integral conversion, floating point
140  /// conversion, floating-integral conversion, pointer conversion,
141  /// pointer-to-member conversion, or boolean conversion.
143 
144  /// Third - The third conversion can be a qualification conversion.
146 
147  /// \brief Whether this is the deprecated conversion of a
148  /// string literal to a pointer to non-const character data
149  /// (C++ 4.2p2).
151 
152  /// \brief Whether the qualification conversion involves a change in the
153  /// Objective-C lifetime (for automatic reference counting).
155 
156  /// IncompatibleObjC - Whether this is an Objective-C conversion
157  /// that we should warn about (if we actually use it).
158  unsigned IncompatibleObjC : 1;
159 
160  /// ReferenceBinding - True when this is a reference binding
161  /// (C++ [over.ics.ref]).
162  unsigned ReferenceBinding : 1;
163 
164  /// DirectBinding - True when this is a reference binding that is a
165  /// direct binding (C++ [dcl.init.ref]).
166  unsigned DirectBinding : 1;
167 
168  /// \brief Whether this is an lvalue reference binding (otherwise, it's
169  /// an rvalue reference binding).
170  unsigned IsLvalueReference : 1;
171 
172  /// \brief Whether we're binding to a function lvalue.
173  unsigned BindsToFunctionLvalue : 1;
174 
175  /// \brief Whether we're binding to an rvalue.
176  unsigned BindsToRvalue : 1;
177 
178  /// \brief Whether this binds an implicit object argument to a
179  /// non-static member function without a ref-qualifier.
181 
182  /// \brief Whether this binds a reference to an object with a different
183  /// Objective-C lifetime qualifier.
185 
186  /// FromType - The type that this conversion is converting
187  /// from. This is an opaque pointer that can be translated into a
188  /// QualType.
189  void *FromTypePtr;
190 
191  /// ToType - The types that this conversion is converting to in
192  /// each step. This is an opaque pointer that can be translated
193  /// into a QualType.
194  void *ToTypePtrs[3];
195 
196  /// CopyConstructor - The copy constructor that is used to perform
197  /// this conversion, when the conversion is actually just the
198  /// initialization of an object via copy constructor. Such
199  /// conversions are either identity conversions or derived-to-base
200  /// conversions.
203 
205  void setToType(unsigned Idx, QualType T) {
206  assert(Idx < 3 && "To type index is out of range");
207  ToTypePtrs[Idx] = T.getAsOpaquePtr();
208  }
210  ToTypePtrs[0] = T.getAsOpaquePtr();
211  ToTypePtrs[1] = ToTypePtrs[0];
212  ToTypePtrs[2] = ToTypePtrs[0];
213  }
214 
217  }
218  QualType getToType(unsigned Idx) const {
219  assert(Idx < 3 && "To type index is out of range");
221  }
222 
224 
225  bool isIdentityConversion() const {
226  return Second == ICK_Identity && Third == ICK_Identity;
227  }
228 
231  APValue &ConstantValue,
232  QualType &ConstantType) const;
233  bool isPointerConversionToBool() const;
235  void dump() const;
236  };
237 
238  /// UserDefinedConversionSequence - Represents a user-defined
239  /// conversion sequence (C++ 13.3.3.1.2).
241  /// \brief Represents the standard conversion that occurs before
242  /// the actual user-defined conversion.
243  ///
244  /// C++11 13.3.3.1.2p1:
245  /// If the user-defined conversion is specified by a constructor
246  /// (12.3.1), the initial standard conversion sequence converts
247  /// the source type to the type required by the argument of the
248  /// constructor. If the user-defined conversion is specified by
249  /// a conversion function (12.3.2), the initial standard
250  /// conversion sequence converts the source type to the implicit
251  /// object parameter of the conversion function.
253 
254  /// EllipsisConversion - When this is true, it means user-defined
255  /// conversion sequence starts with a ... (ellipsis) conversion, instead of
256  /// a standard conversion. In this case, 'Before' field must be ignored.
257  // FIXME. I much rather put this as the first field. But there seems to be
258  // a gcc code gen. bug which causes a crash in a test. Putting it here seems
259  // to work around the crash.
261 
262  /// HadMultipleCandidates - When this is true, it means that the
263  /// conversion function was resolved from an overloaded set having
264  /// size greater than 1.
266 
267  /// After - Represents the standard conversion that occurs after
268  /// the actual user-defined conversion.
270 
271  /// ConversionFunction - The function that will perform the
272  /// user-defined conversion. Null if the conversion is an
273  /// aggregate initialization from an initializer list.
275 
276  /// \brief The declaration that we found via name lookup, which might be
277  /// the same as \c ConversionFunction or it might be a using declaration
278  /// that refers to \c ConversionFunction.
280 
281  void dump() const;
282  };
283 
284  /// Represents an ambiguous user-defined conversion sequence.
287 
288  void *FromTypePtr;
289  void *ToTypePtr;
290  char Buffer[sizeof(ConversionSet)];
291 
294  }
295  QualType getToType() const {
297  }
300 
302  return *reinterpret_cast<ConversionSet*>(Buffer);
303  }
304 
305  const ConversionSet &conversions() const {
306  return *reinterpret_cast<const ConversionSet*>(Buffer);
307  }
308 
310  conversions().push_back(std::make_pair(Found, D));
311  }
312 
314  iterator begin() { return conversions().begin(); }
315  iterator end() { return conversions().end(); }
316 
317  typedef ConversionSet::const_iterator const_iterator;
318  const_iterator begin() const { return conversions().begin(); }
319  const_iterator end() const { return conversions().end(); }
320 
321  void construct();
322  void destruct();
324  };
325 
326  /// BadConversionSequence - Records information about an invalid
327  /// conversion sequence.
329  enum FailureKind {
335  };
336 
337  // This can be null, e.g. for implicit object arguments.
339 
341 
342  private:
343  // The type we're converting from (an opaque QualType).
344  void *FromTy;
345 
346  // The type we're converting to (an opaque QualType).
347  void *ToTy;
348 
349  public:
350  void init(FailureKind K, Expr *From, QualType To) {
351  init(K, From->getType(), To);
352  FromExpr = From;
353  }
354  void init(FailureKind K, QualType From, QualType To) {
355  Kind = K;
356  FromExpr = nullptr;
357  setFromType(From);
358  setToType(To);
359  }
360 
361  QualType getFromType() const { return QualType::getFromOpaquePtr(FromTy); }
363 
364  void setFromExpr(Expr *E) {
365  FromExpr = E;
366  setFromType(E->getType());
367  }
368  void setFromType(QualType T) { FromTy = T.getAsOpaquePtr(); }
369  void setToType(QualType T) { ToTy = T.getAsOpaquePtr(); }
370  };
371 
372  /// ImplicitConversionSequence - Represents an implicit conversion
373  /// sequence, which may be a standard conversion sequence
374  /// (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2),
375  /// or an ellipsis conversion sequence (C++ 13.3.3.1.3).
377  public:
378  /// Kind - The kind of implicit conversion sequence. BadConversion
379  /// specifies that there is no conversion from the source type to
380  /// the target type. AmbiguousConversion represents the unique
381  /// ambiguous conversion (C++0x [over.best.ics]p10).
382  enum Kind {
388  };
389 
390  private:
391  enum {
392  Uninitialized = BadConversion + 1
393  };
394 
395  /// ConversionKind - The kind of implicit conversion sequence.
396  unsigned ConversionKind : 30;
397 
398  /// \brief Whether the target is really a std::initializer_list, and the
399  /// sequence only represents the worst element conversion.
400  unsigned StdInitializerListElement : 1;
401 
402  void setKind(Kind K) {
403  destruct();
404  ConversionKind = K;
405  }
406 
407  void destruct() {
408  if (ConversionKind == AmbiguousConversion) Ambiguous.destruct();
409  }
410 
411  public:
412  union {
413  /// When ConversionKind == StandardConversion, provides the
414  /// details of the standard conversion sequence.
416 
417  /// When ConversionKind == UserDefinedConversion, provides the
418  /// details of the user-defined conversion sequence.
420 
421  /// When ConversionKind == AmbiguousConversion, provides the
422  /// details of the ambiguous conversion.
424 
425  /// When ConversionKind == BadConversion, provides the details
426  /// of the bad conversion.
428  };
429 
431  : ConversionKind(Uninitialized), StdInitializerListElement(false)
432  {}
434  destruct();
435  }
437  : ConversionKind(Other.ConversionKind),
438  StdInitializerListElement(Other.StdInitializerListElement)
439  {
440  switch (ConversionKind) {
441  case Uninitialized: break;
442  case StandardConversion: Standard = Other.Standard; break;
443  case UserDefinedConversion: UserDefined = Other.UserDefined; break;
444  case AmbiguousConversion: Ambiguous.copyFrom(Other.Ambiguous); break;
445  case EllipsisConversion: break;
446  case BadConversion: Bad = Other.Bad; break;
447  }
448  }
449 
452  destruct();
453  new (this) ImplicitConversionSequence(Other);
454  return *this;
455  }
456 
457  Kind getKind() const {
458  assert(isInitialized() && "querying uninitialized conversion");
459  return Kind(ConversionKind);
460  }
461 
462  /// \brief Return a ranking of the implicit conversion sequence
463  /// kind, where smaller ranks represent better conversion
464  /// sequences.
465  ///
466  /// In particular, this routine gives user-defined conversion
467  /// sequences and ambiguous conversion sequences the same rank,
468  /// per C++ [over.best.ics]p10.
469  unsigned getKindRank() const {
470  switch (getKind()) {
471  case StandardConversion:
472  return 0;
473 
475  case AmbiguousConversion:
476  return 1;
477 
478  case EllipsisConversion:
479  return 2;
480 
481  case BadConversion:
482  return 3;
483  }
484 
485  llvm_unreachable("Invalid ImplicitConversionSequence::Kind!");
486  }
487 
488  bool isBad() const { return getKind() == BadConversion; }
489  bool isStandard() const { return getKind() == StandardConversion; }
490  bool isEllipsis() const { return getKind() == EllipsisConversion; }
491  bool isAmbiguous() const { return getKind() == AmbiguousConversion; }
492  bool isUserDefined() const { return getKind() == UserDefinedConversion; }
493  bool isFailure() const { return isBad() || isAmbiguous(); }
494 
495  /// Determines whether this conversion sequence has been
496  /// initialized. Most operations should never need to query
497  /// uninitialized conversions and should assert as above.
498  bool isInitialized() const { return ConversionKind != Uninitialized; }
499 
500  /// Sets this sequence as a bad conversion for an explicit argument.
502  Expr *FromExpr, QualType ToType) {
503  setKind(BadConversion);
504  Bad.init(Failure, FromExpr, ToType);
505  }
506 
507  /// Sets this sequence as a bad conversion for an implicit argument.
509  QualType FromType, QualType ToType) {
510  setKind(BadConversion);
511  Bad.init(Failure, FromType, ToType);
512  }
513 
514  void setStandard() { setKind(StandardConversion); }
515  void setEllipsis() { setKind(EllipsisConversion); }
517  void setAmbiguous() {
518  if (ConversionKind == AmbiguousConversion) return;
519  ConversionKind = AmbiguousConversion;
521  }
522 
523  /// \brief Whether the target is really a std::initializer_list, and the
524  /// sequence only represents the worst element conversion.
526  return StdInitializerListElement;
527  }
528 
529  void setStdInitializerListElement(bool V = true) {
530  StdInitializerListElement = V;
531  }
532 
533  // The result of a comparison between implicit conversion
534  // sequences. Use Sema::CompareImplicitConversionSequences to
535  // actually perform the comparison.
536  enum CompareKind {
537  Better = -1,
539  Worse = 1
540  };
541 
543  SourceLocation CaretLoc,
544  const PartialDiagnostic &PDiag) const;
545 
546  void dump() const;
547  };
548 
554 
555  /// This conversion candidate was not considered because it
556  /// duplicates the work of a trivial or derived-to-base
557  /// conversion.
559 
560  /// This conversion candidate was not considered because it is
561  /// an illegal instantiation of a constructor temploid: it is
562  /// callable with one argument, we only have one argument, and
563  /// its first parameter type is exactly the type of the class.
564  ///
565  /// Defining such a constructor directly is illegal, and
566  /// template-argument deduction is supposed to ignore such
567  /// instantiations, but we can still get one with the right
568  /// kind of implicit instantiation.
570 
571  /// This conversion candidate is not viable because its result
572  /// type is not implicitly convertible to the desired type.
574 
575  /// This conversion function template specialization candidate is not
576  /// viable because the final conversion was not an exact match.
578 
579  /// (CUDA) This candidate was not viable because the callee
580  /// was not accessible from the caller's target (i.e. host->device,
581  /// global->host, device->host).
583 
584  /// This candidate function was not viable because an enable_if
585  /// attribute disabled it.
587 
588  /// This candidate was not viable because its address could not be taken.
590  };
591 
592  /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
594  /// Function - The actual function that this candidate
595  /// represents. When NULL, this is a built-in candidate
596  /// (C++ [over.oper]) or a surrogate for a conversion to a
597  /// function pointer or reference (C++ [over.call.object]).
599 
600  /// FoundDecl - The original declaration that was looked up /
601  /// invented / otherwise found, together with its access.
602  /// Might be a UsingShadowDecl or a FunctionTemplateDecl.
604 
605  // BuiltinTypes - Provides the return and parameter types of a
606  // built-in overload candidate. Only valid when Function is NULL.
607  struct {
610  } BuiltinTypes;
611 
612  /// Surrogate - The conversion function for which this candidate
613  /// is a surrogate, but only if IsSurrogate is true.
615 
616  /// Conversions - The conversion sequences used to convert the
617  /// function arguments to the function parameters, the pointer points to a
618  /// fixed size array with NumConversions elements. The memory is owned by
619  /// the OverloadCandidateSet.
621 
622  /// The FixIt hints which can be used to fix the Bad candidate.
624 
625  /// NumConversions - The number of elements in the Conversions array.
626  unsigned NumConversions;
627 
628  /// Viable - True to indicate that this overload candidate is viable.
629  bool Viable;
630 
631  /// IsSurrogate - True to indicate that this candidate is a
632  /// surrogate for a conversion to a function pointer or reference
633  /// (C++ [over.call.object]).
635 
636  /// IgnoreObjectArgument - True to indicate that the first
637  /// argument's conversion, which for this function represents the
638  /// implicit object argument, should be ignored. This will be true
639  /// when the candidate is a static member function (where the
640  /// implicit object argument is just a placeholder) or a
641  /// non-static member function when the call doesn't have an
642  /// object argument.
644 
645  /// FailureKind - The reason why this candidate is not viable.
646  /// Actually an OverloadFailureKind.
647  unsigned char FailureKind;
648 
649  /// \brief The number of call arguments that were explicitly provided,
650  /// to be used while performing partial ordering of function templates.
652 
653  union {
655 
656  /// FinalConversion - For a conversion function (where Function is
657  /// a CXXConversionDecl), the standard conversion that occurs
658  /// after the call to the overload candidate to convert the result
659  /// of calling the conversion function to the required type.
661  };
662 
663  /// hasAmbiguousConversion - Returns whether this overload
664  /// candidate requires an ambiguous conversion or not.
665  bool hasAmbiguousConversion() const {
666  for (unsigned i = 0, e = NumConversions; i != e; ++i) {
667  if (!Conversions[i].isInitialized()) return false;
668  if (Conversions[i].isAmbiguous()) return true;
669  }
670  return false;
671  }
672 
673  bool TryToFixBadConversion(unsigned Idx, Sema &S) {
674  bool CanFix = Fix.tryToFixConversion(
675  Conversions[Idx].Bad.FromExpr,
676  Conversions[Idx].Bad.getFromType(),
677  Conversions[Idx].Bad.getToType(), S);
678 
679  // If at least one conversion fails, the candidate cannot be fixed.
680  if (!CanFix)
681  Fix.clear();
682 
683  return CanFix;
684  }
685 
686  unsigned getNumParams() const {
687  if (IsSurrogate) {
688  auto STy = Surrogate->getConversionType();
689  while (STy->isPointerType() || STy->isReferenceType())
690  STy = STy->getPointeeType();
691  return STy->getAs<FunctionProtoType>()->getNumParams();
692  }
693  if (Function)
694  return Function->getNumParams();
695  return ExplicitCallArguments;
696  }
697  };
698 
699  /// OverloadCandidateSet - A set of overload candidates, used in C++
700  /// overload resolution (C++ 13.3).
702  public:
704  /// Normal lookup.
706  /// Lookup for candidates for a call using operator syntax. Candidates
707  /// that have no parameters of class type will be skipped unless there
708  /// is a parameter of (reference to) enum type and the corresponding
709  /// argument is of the same enum type.
711  };
712 
713  private:
715  llvm::SmallPtrSet<Decl *, 16> Functions;
716 
717  // Allocator for OverloadCandidate::Conversions. We store the first few
718  // elements inline to avoid allocation for small sets.
719  llvm::BumpPtrAllocator ConversionSequenceAllocator;
720 
721  SourceLocation Loc;
723 
724  unsigned NumInlineSequences;
725  llvm::AlignedCharArray<llvm::AlignOf<ImplicitConversionSequence>::Alignment,
726  16 * sizeof(ImplicitConversionSequence)> InlineSpace;
727 
728  OverloadCandidateSet(const OverloadCandidateSet &) = delete;
729  void operator=(const OverloadCandidateSet &) = delete;
730 
731  void destroyCandidates();
732 
733  public:
735  : Loc(Loc), Kind(CSK), NumInlineSequences(0) {}
736  ~OverloadCandidateSet() { destroyCandidates(); }
737 
738  SourceLocation getLocation() const { return Loc; }
739  CandidateSetKind getKind() const { return Kind; }
740 
741  /// \brief Determine when this overload candidate will be new to the
742  /// overload set.
743  bool isNewCandidate(Decl *F) {
744  return Functions.insert(F->getCanonicalDecl()).second;
745  }
746 
747  /// \brief Clear out all of the candidates.
748  void clear();
749 
751  iterator begin() { return Candidates.begin(); }
752  iterator end() { return Candidates.end(); }
753 
754  size_t size() const { return Candidates.size(); }
755  bool empty() const { return Candidates.empty(); }
756 
757  /// \brief Add a new candidate with NumConversions conversion sequence slots
758  /// to the overload set.
759  OverloadCandidate &addCandidate(unsigned NumConversions = 0) {
760  Candidates.push_back(OverloadCandidate());
761  OverloadCandidate &C = Candidates.back();
762 
763  // Assign space from the inline array if there are enough free slots
764  // available.
765  if (NumConversions + NumInlineSequences <= 16) {
767  (ImplicitConversionSequence *)InlineSpace.buffer;
768  C.Conversions = &I[NumInlineSequences];
769  NumInlineSequences += NumConversions;
770  } else {
771  // Otherwise get memory from the allocator.
772  C.Conversions = ConversionSequenceAllocator
773  .Allocate<ImplicitConversionSequence>(NumConversions);
774  }
775 
776  // Construct the new objects.
777  for (unsigned i = 0; i != NumConversions; ++i)
779 
780  C.NumConversions = NumConversions;
781  return C;
782  }
783 
784  /// Find the best viable function on this overload set, if it exists.
787  bool UserDefinedConversion = false);
788 
789  void NoteCandidates(Sema &S,
791  ArrayRef<Expr *> Args,
792  StringRef Opc = "",
794  };
795 
796  bool isBetterOverloadCandidate(Sema &S,
797  const OverloadCandidate& Cand1,
798  const OverloadCandidate& Cand2,
799  SourceLocation Loc,
800  bool UserDefinedConversion = false);
801 
806  explicit operator bool() const { return Constructor; }
807  };
808  // FIXME: Add an AddOverloadCandidate / AddTemplateOverloadCandidate overload
809  // that takes one of these.
811  if (isa<UsingDecl>(ND))
812  return ConstructorInfo{};
813 
814  // For constructors, the access check is performed against the underlying
815  // declaration, not the found declaration.
816  auto *D = ND->getUnderlyingDecl();
817  ConstructorInfo Info = {DeclAccessPair::make(ND, D->getAccess()), nullptr,
818  nullptr};
819  Info.ConstructorTmpl = dyn_cast<FunctionTemplateDecl>(D);
820  if (Info.ConstructorTmpl)
821  D = Info.ConstructorTmpl->getTemplatedDecl();
822  Info.Constructor = dyn_cast<CXXConstructorDecl>(D);
823  return Info;
824  }
825 } // end namespace clang
826 
827 #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:651
DeclAccessPair FoundConversionFunction
The declaration that we found via name lookup, which might be the same as ConversionFunction or it mi...
Definition: Overload.h:279
unsigned DeprecatedStringLiteralToCharPtr
Whether this is the deprecated conversion of a string literal to a pointer to non-const character dat...
Definition: Overload.h:150
(CUDA) This candidate was not viable because the callee was not accessible from the caller's target (...
Definition: Overload.h:582
void setFromType(QualType T)
Definition: Overload.h:368
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1561
char Buffer[sizeof(ConversionSet)]
Definition: Overload.h:290
void setStdInitializerListElement(bool V=true)
Definition: Overload.h:529
bool EllipsisConversion
EllipsisConversion - When this is true, it means user-defined conversion sequence starts with a ...
Definition: Overload.h:260
A (possibly-)qualified type.
Definition: Type.h:598
ImplicitConversionKind
ImplicitConversionKind - The kind of implicit conversion used to convert an argument to a parameter's...
Definition: Overload.h:60
void setFromType(QualType T)
Definition: Overload.h:204
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Definition: DeclCXX.h:2501
A structure used to record information about a failed template argument deduction, for diagnosis.
void dump() const
dump - Print this standard conversion sequence to standard error.
Vector conversions.
Definition: Overload.h:79
C Language Family Type Representation.
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
When ConversionKind == UserDefinedConversion, provides the details of the user-defined conversion seq...
Definition: Overload.h:419
ConstructorInfo getConstructorInfo(NamedDecl *ND)
Definition: Overload.h:810
Defines the C++ template declaration subclasses.
Not a narrowing conversion.
Definition: Overload.h:110
ImplicitConversionRank
ImplicitConversionRank - The rank of an implicit conversion kind.
Definition: Overload.h:94
unsigned IncompatibleObjC
IncompatibleObjC - Whether this is an Objective-C conversion that we should warn about (if we actuall...
Definition: Overload.h:158
Ambiguous candidates found.
Definition: Overload.h:43
Conversions between compatible types in C99.
Definition: Overload.h:77
bool IgnoreObjectArgument
IgnoreObjectArgument - True to indicate that the first argument's conversion, which for this function...
Definition: Overload.h:643
ConversionSet::iterator iterator
Definition: Overload.h:313
unsigned DirectBinding
DirectBinding - True when this is a reference binding that is a direct binding (C++ [dcl...
Definition: Overload.h:166
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2187
void * getAsOpaquePtr() const
Definition: Type.h:646
Exact Match.
Definition: Overload.h:95
bool IsSurrogate
IsSurrogate - True to indicate that this candidate is a surrogate for a conversion to a function poin...
Definition: Overload.h:634
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:387
bool HadMultipleCandidates
HadMultipleCandidates - When this is true, it means that the conversion function was resolved from an...
Definition: Overload.h:265
Removal of noreturn from a type (Clang)
Definition: Overload.h:65
Conversion.
Definition: Overload.h:97
void * ToTypePtrs[3]
ToType - The types that this conversion is converting to in each step.
Definition: Overload.h:194
ImplicitConversionSequence(const ImplicitConversionSequence &Other)
Definition: Overload.h:436
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:92
OverloadCandidate & addCandidate(unsigned NumConversions=0)
Add a new candidate with NumConversions conversion sequence slots to the overload set...
Definition: Overload.h:759
ImplicitConversionSequence * Conversions
Conversions - The conversion sequences used to convert the function arguments to the function paramet...
Definition: Overload.h:620
unsigned BindsToFunctionLvalue
Whether we're binding to a function lvalue.
Definition: Overload.h:173
BadConversionSequence Bad
When ConversionKind == BadConversion, provides the details of the bad conversion. ...
Definition: Overload.h:427
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Definition: DeclTemplate.h:899
Identity conversion (no conversion)
Definition: Overload.h:61
Kind
Kind - The kind of implicit conversion sequence.
Definition: Overload.h:382
ConversionSet & conversions()
Definition: Overload.h:301
BadConversionSequence - Records information about an invalid conversion sequence. ...
Definition: Overload.h:328
QualType getToType() const
Definition: Overload.h:362
Floating point conversions (C++ 4.8)
Definition: Overload.h:71
const_iterator end() const
Definition: Overload.h:319
OverloadCandidateDisplayKind
Definition: Overload.h:47
Floating point promotions (C++ 4.6)
Definition: Overload.h:68
ImplicitConversionRank getRank() const
getRank - Retrieve the rank of this standard conversion sequence (C++ 13.3.3.1.1p3).
unsigned BindsToRvalue
Whether we're binding to an rvalue.
Definition: Overload.h:176
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
Succeeded, but refers to a deleted function.
Definition: Overload.h:44
ImplicitConversionSequence & operator=(const ImplicitConversionSequence &Other)
Definition: Overload.h:451
unsigned QualificationIncludesObjCLifetime
Whether the qualification conversion involves a change in the Objective-C lifetime (for automatic ref...
Definition: Overload.h:154
This candidate function was not viable because an enable_if attribute disabled it.
Definition: Overload.h:586
ImplicitConversionKind Second
Second - The second conversion can be an integral promotion, floating point promotion, integral conversion, floating point conversion, floating-integral conversion, pointer conversion, pointer-to-member conversion, or boolean conversion.
Definition: Overload.h:142
A narrowing conversion, because a constant expression got narrowed.
Definition: Overload.h:116
unsigned IsLvalueReference
Whether this is an lvalue reference binding (otherwise, it's an rvalue reference binding).
Definition: Overload.h:170
NarrowingKind
NarrowingKind - The kind of narrowing conversion being performed by a standard conversion sequence ac...
Definition: Overload.h:108
Qualification conversions (C++ 4.4)
Definition: Overload.h:66
NarrowingKind getNarrowingKind(ASTContext &Context, const Expr *Converted, APValue &ConstantValue, QualType &ConstantType) const
Check if this standard conversion sequence represents a narrowing conversion, according to C++11 [dcl...
The number of conversion kinds.
Definition: Overload.h:87
ImplicitConversionKind Third
Third - The third conversion can be a qualification conversion.
Definition: Overload.h:145
detail::InMemoryDirectory::const_iterator I
Complex <-> Real conversion.
Definition: Overload.h:98
bool Viable
Viable - True to indicate that this overload candidate is viable.
Definition: Overload.h:629
Integral promotions (C++ 4.5)
Definition: Overload.h:67
This conversion function template specialization candidate is not viable because the final conversion...
Definition: Overload.h:577
DeclAccessPair FoundDecl
Definition: Overload.h:803
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:263
bool isBetterOverloadCandidate(Sema &S, const OverloadCandidate &Cand1, const OverloadCandidate &Cand2, SourceLocation Loc, bool UserDefinedConversion=false)
isBetterOverloadCandidate - Determines whether the first overload candidate is a better candidate tha...
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3073
Transparent Union Conversions.
Definition: Overload.h:83
ASTContext * Context
This conversion candidate was not considered because it duplicates the work of a trivial or derived-t...
Definition: Overload.h:558
bool isNewCandidate(Decl *F)
Determine when this overload candidate will be new to the overload set.
Definition: Overload.h:743
A narrowing conversion by virtue of the source and destination types.
Definition: Overload.h:113
Promotion.
Definition: Overload.h:96
StandardConversionSequence FinalConversion
FinalConversion - For a conversion function (where Function is a CXXConversionDecl), the standard conversion that occurs after the call to the overload candidate to convert the result of calling the conversion function to the required type.
Definition: Overload.h:660
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:415
ObjC ARC writeback conversion.
Definition: Overload.h:99
bool hasAmbiguousConversion() const
hasAmbiguousConversion - Returns whether this overload candidate requires an ambiguous conversion or ...
Definition: Overload.h:665
friend class ASTContext
Definition: Type.h:4178
void dump() const
dump - Print this user-defined conversion sequence to standard error.
Expr - This represents one expression.
Definition: Expr.h:105
Represents an ambiguous user-defined conversion sequence.
Definition: Overload.h:285
StandardConversionSequence After
After - Represents the standard conversion that occurs after the actual user-defined conversion...
Definition: Overload.h:269
SmallVectorImpl< OverloadCandidate >::iterator iterator
Definition: Overload.h:750
void copyFrom(const AmbiguousConversionSequence &)
#define bool
Definition: stdbool.h:31
CXXConstructorDecl * CopyConstructor
CopyConstructor - The copy constructor that is used to perform this conversion, when the conversion i...
Definition: Overload.h:201
QualType ParamTypes[3]
Definition: Overload.h:609
Overload resolution succeeded.
Definition: Overload.h:41
unsigned ReferenceBinding
ReferenceBinding - True when this is a reference binding (C++ [over.ics.ref]).
Definition: Overload.h:162
QualType getFromType() const
Definition: Overload.h:361
Floating-integral conversions (C++ 4.9)
Definition: Overload.h:73
void init(FailureKind K, Expr *From, QualType To)
Definition: Overload.h:350
This conversion candidate was not considered because it is an illegal instantiation of a constructor ...
Definition: Overload.h:569
bool TryToFixBadConversion(unsigned Idx, Sema &S)
Definition: Overload.h:673
QualType getFromType() const
Definition: Overload.h:215
CXXConversionDecl * Surrogate
Surrogate - The conversion function for which this candidate is a surrogate, but only if IsSurrogate ...
Definition: Overload.h:614
UserDefinedConversionSequence - Represents a user-defined conversion sequence (C++ 13...
Definition: Overload.h:240
This candidate was not viable because its address could not be taken.
Definition: Overload.h:589
void NoteCandidates(Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr * > Args, StringRef Opc="", SourceLocation Loc=SourceLocation())
PrintOverloadCandidates - When overload resolution fails, prints diagnostic messages containing the c...
StandardConversionSequence Standard
When ConversionKind == StandardConversion, provides the details of the standard conversion sequence...
Definition: Overload.h:415
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2461
A narrowing conversion, because a non-constant-expression variable might have got narrowed...
Definition: Overload.h:120
Lvalue-to-rvalue conversion (C++ 4.1)
Definition: Overload.h:62
OverloadFailureKind
Definition: Overload.h:549
unsigned ObjCLifetimeConversionBinding
Whether this binds a reference to an object with a different Objective-C lifetime qualifier...
Definition: Overload.h:184
unsigned NumConversions
NumConversions - The number of elements in the Conversions array.
Definition: Overload.h:626
bool isIdentityConversion() const
Definition: Overload.h:225
CXXConstructorDecl * Constructor
Definition: Overload.h:804
QualType getFromType() const
Definition: Overload.h:292
Integral conversions (C++ 4.7)
Definition: Overload.h:70
Complex promotions (Clang extension)
Definition: Overload.h:69
#define false
Definition: stdbool.h:33
Kind
ImplicitConversionSequence - Represents an implicit conversion sequence, which may be a standard conv...
Definition: Overload.h:376
bool isInitialized() const
Determines whether this conversion sequence has been initialized.
Definition: Overload.h:498
SmallVector< std::pair< NamedDecl *, FunctionDecl * >, 4 > ConversionSet
Definition: Overload.h:286
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
Definition: Overload.h:593
Encodes a location in the source.
unsigned getNumParams() const
getNumParams - Return the number of parameters this function must have based on its FunctionType...
Definition: Decl.cpp:2742
const TemplateArgument * iterator
Definition: Type.h:4233
A vector splat from an arithmetic type.
Definition: Overload.h:80
OverloadingResult
OverloadingResult - Capture the result of performing overload resolution.
Definition: Overload.h:40
Objective-C ARC writeback conversion.
Definition: Overload.h:84
void init(FailureKind K, QualType From, QualType To)
Definition: Overload.h:354
void dump() const
dump - Print this implicit conversion sequence to standard error.
bool isStdInitializerListElement() const
Whether the target is really a std::initializer_list, and the sequence only represents the worst elem...
Definition: Overload.h:525
void setAsIdentityConversion()
StandardConversionSequence - Set the standard conversion sequence to the identity conversion...
Pointer conversions (C++ 4.10)
Definition: Overload.h:74
Lookup for candidates for a call using operator syntax.
Definition: Overload.h:710
CandidateSetKind getKind() const
Definition: Overload.h:739
QualType getToType(unsigned Idx) const
Definition: Overload.h:218
Requests that all candidates be shown.
Definition: Overload.h:50
Derived-to-base (C++ [over.best.ics])
Definition: Overload.h:78
Complex-real conversions (C99 6.3.1.7)
Definition: Overload.h:81
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13...
Definition: Overload.h:701
void setBad(BadConversionSequence::FailureKind Failure, Expr *FromExpr, QualType ToType)
Sets this sequence as a bad conversion for an explicit argument.
Definition: Overload.h:501
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:647
void setFromExpr(Expr *E)
Definition: Overload.h:364
A POD class for pairing a NamedDecl* with an access specifier.
ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind)
GetConversionRank - Retrieve the implicit conversion rank corresponding to the given implicit convers...
QualType getType() const
Definition: Expr.h:126
void DiagnoseAmbiguousConversion(Sema &S, SourceLocation CaretLoc, const PartialDiagnostic &PDiag) const
Diagnoses an ambiguous conversion.
DeclAccessPair FoundCopyConstructor
Definition: Overload.h:202
OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK)
Definition: Overload.h:734
ConversionSet::const_iterator const_iterator
Definition: Overload.h:317
const ConversionSet & conversions() const
Definition: Overload.h:305
Conversions allowed in C, but not C++.
Definition: Overload.h:86
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:252
Requests that only viable candidates be shown.
Definition: Overload.h:53
detail::InMemoryDirectory::const_iterator E
FunctionDecl * Function
Function - The actual function that this candidate represents.
Definition: Overload.h:598
unsigned getNumParams() const
Definition: Overload.h:686
bool isPointerConversionToBool() const
isPointerConversionToBool - Determines whether this conversion is a conversion of a pointer or pointe...
FunctionDecl * ConversionFunction
ConversionFunction - The function that will perform the user-defined conversion.
Definition: Overload.h:274
Conversion only allowed in the C standard.
Definition: Overload.h:100
void setToType(QualType T)
Definition: Overload.h:369
void setAllToTypes(QualType T)
Definition: Overload.h:209
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:5818
unsigned getKindRank() const
Return a ranking of the implicit conversion sequence kind, where smaller ranks represent better conve...
Definition: Overload.h:469
unsigned BindsImplicitObjectArgumentWithoutRefQualifier
Whether this binds an implicit object argument to a non-static member function without a ref-qualifie...
Definition: Overload.h:180
unsigned char FailureKind
FailureKind - The reason why this candidate is not viable.
Definition: Overload.h:647
void setBad(BadConversionSequence::FailureKind Failure, QualType FromType, QualType ToType)
Sets this sequence as a bad conversion for an implicit argument.
Definition: Overload.h:508
DeclAccessPair FoundDecl
FoundDecl - The original declaration that was looked up / invented / otherwise found, together with its access.
Definition: Overload.h:603
Block Pointer conversions.
Definition: Overload.h:82
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Definition: APValue.h:38
ConversionFixItGenerator Fix
The FixIt hints which can be used to fix the Bad candidate.
Definition: Overload.h:623
AmbiguousConversionSequence Ambiguous
When ConversionKind == AmbiguousConversion, provides the details of the ambiguous conversion...
Definition: Overload.h:423
void addConversion(NamedDecl *Found, FunctionDecl *D)
Definition: Overload.h:309
const_iterator begin() const
Definition: Overload.h:318
Function-to-pointer (C++ 4.3)
Definition: Overload.h:64
FunctionTemplateDecl * ConstructorTmpl
Definition: Overload.h:805
void * FromTypePtr
FromType - The type that this conversion is converting from.
Definition: Overload.h:189
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best, bool UserDefinedConversion=false)
Find the best viable function on this overload set, if it exists.
The class facilities generation and storage of conversion FixIts.
Zero constant to event (OpenCL1.2 6.12.10)
Definition: Overload.h:85
void clear()
Clear out all of the candidates.
ImplicitConversionKind First
First – The first conversion can be an lvalue-to-rvalue conversion, array-to-pointer conversion...
Definition: Overload.h:136
struct clang::OverloadCandidate::@202 BuiltinTypes
No viable function found.
Definition: Overload.h:42
DeductionFailureInfo DeductionFailure
Definition: Overload.h:654
size_t size() const
Definition: Overload.h:754
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
Pointer-to-member conversions (C++ 4.11)
Definition: Overload.h:75
void setToType(unsigned Idx, QualType T)
Definition: Overload.h:205
bool isPointerConversionToVoidPointer(ASTContext &Context) const
isPointerConversionToVoidPointer - Determines whether this conversion is a conversion of a pointer to...
This conversion candidate is not viable because its result type is not implicitly convertible to the ...
Definition: Overload.h:573
Declaration of a template function.
Definition: DeclTemplate.h:838
SourceLocation getLocation() const
Definition: Overload.h:738
StandardConversionSequence - represents a standard conversion sequence (C++ 13.3.3.1.1).
Definition: Overload.h:131