clang  20.0.0git
Overload.h
Go to the documentation of this file.
1 //===- Overload.h - C++ Overloading -----------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the data structures and types used in C++
10 // overload resolution.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_SEMA_OVERLOAD_H
15 #define LLVM_CLANG_SEMA_OVERLOAD_H
16 
17 #include "clang/AST/Decl.h"
19 #include "clang/AST/DeclBase.h"
20 #include "clang/AST/DeclCXX.h"
21 #include "clang/AST/DeclTemplate.h"
22 #include "clang/AST/Expr.h"
23 #include "clang/AST/Type.h"
24 #include "clang/Basic/LLVM.h"
28 #include "llvm/ADT/ArrayRef.h"
29 #include "llvm/ADT/STLExtras.h"
30 #include "llvm/ADT/SmallPtrSet.h"
31 #include "llvm/ADT/SmallVector.h"
32 #include "llvm/ADT/StringRef.h"
33 #include "llvm/Support/AlignOf.h"
34 #include "llvm/Support/Allocator.h"
35 #include "llvm/Support/Casting.h"
36 #include "llvm/Support/ErrorHandling.h"
37 #include <cassert>
38 #include <cstddef>
39 #include <cstdint>
40 #include <utility>
41 
42 namespace clang {
43 
44 class APValue;
45 class ASTContext;
46 class Sema;
47 
48  /// OverloadingResult - Capture the result of performing overload
49  /// resolution.
51  /// Overload resolution succeeded.
53 
54  /// No viable function found.
56 
57  /// Ambiguous candidates found.
59 
60  /// Succeeded, but refers to a deleted function.
62  };
63 
65  /// Requests that all candidates be shown. Viable candidates will
66  /// be printed first.
68 
69  /// Requests that only viable candidates be shown.
71 
72  /// Requests that only tied-for-best candidates be shown.
74  };
75 
76  /// The parameter ordering that will be used for the candidate. This is
77  /// used to represent C++20 binary operator rewrites that reverse the order
78  /// of the arguments. If the parameter ordering is Reversed, the Args list is
79  /// reversed (but obviously the ParamDecls for the function are not).
80  ///
81  /// After forming an OverloadCandidate with reversed parameters, the list
82  /// of conversions will (as always) be indexed by argument, so will be
83  /// in reverse parameter order.
85 
86  /// The kinds of rewrite we perform on overload candidates. Note that the
87  /// values here are chosen to serve as both bitflags and as a rank (lower
88  /// values are preferred by overload resolution).
89  enum OverloadCandidateRewriteKind : unsigned {
90  /// Candidate is not a rewritten candidate.
91  CRK_None = 0x0,
92 
93  /// Candidate is a rewritten candidate with a different operator name.
95 
96  /// Candidate is a rewritten candidate with a reversed order of parameters.
97  CRK_Reversed = 0x2,
98  };
99 
100  /// ImplicitConversionKind - The kind of implicit conversion used to
101  /// convert an argument to a parameter's type. The enumerator values
102  /// match with the table titled 'Conversions' in [over.ics.scs] and are listed
103  /// such that better conversion kinds have smaller values.
105  /// Identity conversion (no conversion)
107 
108  /// Lvalue-to-rvalue conversion (C++ [conv.lval])
110 
111  /// Array-to-pointer conversion (C++ [conv.array])
113 
114  /// Function-to-pointer (C++ [conv.array])
116 
117  /// Function pointer conversion (C++17 [conv.fctptr])
119 
120  /// Qualification conversions (C++ [conv.qual])
122 
123  /// Integral promotions (C++ [conv.prom])
125 
126  /// Floating point promotions (C++ [conv.fpprom])
128 
129  /// Complex promotions (Clang extension)
131 
132  /// Integral conversions (C++ [conv.integral])
134 
135  /// Floating point conversions (C++ [conv.double]
137 
138  /// Complex conversions (C99 6.3.1.6)
140 
141  /// Floating-integral conversions (C++ [conv.fpint])
143 
144  /// Pointer conversions (C++ [conv.ptr])
146 
147  /// Pointer-to-member conversions (C++ [conv.mem])
149 
150  /// Boolean conversions (C++ [conv.bool])
152 
153  /// Conversions between compatible types in C99
155 
156  /// Derived-to-base (C++ [over.best.ics])
158 
159  /// Vector conversions
161 
162  /// Arm SVE Vector conversions
164 
165  /// RISC-V RVV Vector conversions
167 
168  /// A vector splat from an arithmetic type
170 
171  /// Complex-real conversions (C99 6.3.1.7)
173 
174  /// Block Pointer conversions
176 
177  /// Transparent Union Conversions
179 
180  /// Objective-C ARC writeback conversion
182 
183  /// Zero constant to event (OpenCL1.2 6.12.10)
185 
186  /// Zero constant to queue
188 
189  /// Conversions allowed in C, but not C++
191 
192  /// C-only conversion between pointers with incompatible types
194 
195  /// Fixed point type conversions according to N1169.
197 
198  /// HLSL vector truncation.
200 
201  /// HLSL non-decaying array rvalue cast.
203 
204  // HLSL vector splat from scalar or boolean type.
206 
207  /// The number of conversion kinds
209  };
210 
211  /// ImplicitConversionRank - The rank of an implicit conversion
212  /// kind. The enumerator values match with Table 9 of (C++
213  /// 13.3.3.1.1) and are listed such that better conversion ranks
214  /// have smaller values.
216  /// Exact Match
218 
219  /// HLSL Scalar Widening
221 
222  /// Promotion
224 
225  /// HLSL Scalar Widening with promotion
227 
228  /// HLSL Matching Dimension Reduction
230 
231  /// Conversion
233 
234  /// OpenCL Scalar Widening
236 
237  /// HLSL Scalar Widening with conversion
239 
240  /// Complex <-> Real conversion
242 
243  /// ObjC ARC writeback conversion
245 
246  /// Conversion only allowed in the C standard (e.g. void* to char*).
248 
249  /// Conversion not allowed by the C standard, but that we accept as an
250  /// extension anyway.
252 
253  /// HLSL Dimension reduction with promotion
255 
256  /// HLSL Dimension reduction with conversion
258  };
259 
261 
264  ImplicitConversionKind Dimension);
265 
266  /// NarrowingKind - The kind of narrowing conversion being performed by a
267  /// standard conversion sequence according to C++11 [dcl.init.list]p7.
269  /// Not a narrowing conversion.
271 
272  /// A narrowing conversion by virtue of the source and destination types.
274 
275  /// A narrowing conversion, because a constant expression got narrowed.
277 
278  /// A narrowing conversion, because a non-constant-expression variable might
279  /// have got narrowed.
281 
282  /// Cannot tell whether this is a narrowing conversion because the
283  /// expression is value-dependent.
285  };
286 
287  /// StandardConversionSequence - represents a standard conversion
288  /// sequence (C++ 13.3.3.1.1). A standard conversion sequence
289  /// contains between zero and three conversions. If a particular
290  /// conversion is not needed, it will be set to the identity conversion
291  /// (ICK_Identity).
293  public:
294  /// First -- The first conversion can be an lvalue-to-rvalue
295  /// conversion, array-to-pointer conversion, or
296  /// function-to-pointer conversion.
298 
299  /// Second - The second conversion can be an integral promotion,
300  /// floating point promotion, integral conversion, floating point
301  /// conversion, floating-integral conversion, pointer conversion,
302  /// pointer-to-member conversion, or boolean conversion.
304 
305  /// Dimension - Between the second and third conversion a vector or matrix
306  /// dimension conversion may occur. If this is not ICK_Identity this
307  /// conversion truncates the vector or matrix, or extends a scalar.
309 
310  /// Third - The third conversion can be a qualification conversion
311  /// or a function conversion.
313 
314  /// Whether this is the deprecated conversion of a
315  /// string literal to a pointer to non-const character data
316  /// (C++ 4.2p2).
317  LLVM_PREFERRED_TYPE(bool)
319 
320  /// Whether the qualification conversion involves a change in the
321  /// Objective-C lifetime (for automatic reference counting).
322  LLVM_PREFERRED_TYPE(bool)
324 
325  /// IncompatibleObjC - Whether this is an Objective-C conversion
326  /// that we should warn about (if we actually use it).
327  LLVM_PREFERRED_TYPE(bool)
328  unsigned IncompatibleObjC : 1;
329 
330  /// ReferenceBinding - True when this is a reference binding
331  /// (C++ [over.ics.ref]).
332  LLVM_PREFERRED_TYPE(bool)
333  unsigned ReferenceBinding : 1;
334 
335  /// DirectBinding - True when this is a reference binding that is a
336  /// direct binding (C++ [dcl.init.ref]).
337  LLVM_PREFERRED_TYPE(bool)
338  unsigned DirectBinding : 1;
339 
340  /// Whether this is an lvalue reference binding (otherwise, it's
341  /// an rvalue reference binding).
342  LLVM_PREFERRED_TYPE(bool)
343  unsigned IsLvalueReference : 1;
344 
345  /// Whether we're binding to a function lvalue.
346  LLVM_PREFERRED_TYPE(bool)
347  unsigned BindsToFunctionLvalue : 1;
348 
349  /// Whether we're binding to an rvalue.
350  LLVM_PREFERRED_TYPE(bool)
351  unsigned BindsToRvalue : 1;
352 
353  /// Whether this binds an implicit object argument to a
354  /// non-static member function without a ref-qualifier.
355  LLVM_PREFERRED_TYPE(bool)
357 
358  /// Whether this binds a reference to an object with a different
359  /// Objective-C lifetime qualifier.
360  LLVM_PREFERRED_TYPE(bool)
362 
363  /// FromType - The type that this conversion is converting
364  /// from. This is an opaque pointer that can be translated into a
365  /// QualType.
366  void *FromTypePtr;
367 
368  /// ToType - The types that this conversion is converting to in
369  /// each step. This is an opaque pointer that can be translated
370  /// into a QualType.
371  void *ToTypePtrs[3];
372 
373  /// CopyConstructor - The copy constructor that is used to perform
374  /// this conversion, when the conversion is actually just the
375  /// initialization of an object via copy constructor. Such
376  /// conversions are either identity conversions or derived-to-base
377  /// conversions.
380 
381  void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
382 
383  void setToType(unsigned Idx, QualType T) {
384  assert(Idx < 3 && "To type index is out of range");
385  ToTypePtrs[Idx] = T.getAsOpaquePtr();
386  }
387 
389  ToTypePtrs[0] = T.getAsOpaquePtr();
390  ToTypePtrs[1] = ToTypePtrs[0];
391  ToTypePtrs[2] = ToTypePtrs[0];
392  }
393 
396  }
397 
398  QualType getToType(unsigned Idx) const {
399  assert(Idx < 3 && "To type index is out of range");
401  }
402 
404 
405  bool isIdentityConversion() const {
406  return Second == ICK_Identity && Dimension == ICK_Identity &&
407  Third == ICK_Identity;
408  }
409 
412  getNarrowingKind(ASTContext &Context, const Expr *Converted,
413  APValue &ConstantValue, QualType &ConstantType,
414  bool IgnoreFloatToIntegralConversion = false) const;
415  bool isPointerConversionToBool() const;
416  bool isPointerConversionToVoidPointer(ASTContext& Context) const;
417  void dump() const;
418  };
419 
420  /// UserDefinedConversionSequence - Represents a user-defined
421  /// conversion sequence (C++ 13.3.3.1.2).
423  /// Represents the standard conversion that occurs before
424  /// the actual user-defined conversion.
425  ///
426  /// C++11 13.3.3.1.2p1:
427  /// If the user-defined conversion is specified by a constructor
428  /// (12.3.1), the initial standard conversion sequence converts
429  /// the source type to the type required by the argument of the
430  /// constructor. If the user-defined conversion is specified by
431  /// a conversion function (12.3.2), the initial standard
432  /// conversion sequence converts the source type to the implicit
433  /// object parameter of the conversion function.
435 
436  /// EllipsisConversion - When this is true, it means user-defined
437  /// conversion sequence starts with a ... (ellipsis) conversion, instead of
438  /// a standard conversion. In this case, 'Before' field must be ignored.
439  // FIXME. I much rather put this as the first field. But there seems to be
440  // a gcc code gen. bug which causes a crash in a test. Putting it here seems
441  // to work around the crash.
443 
444  /// HadMultipleCandidates - When this is true, it means that the
445  /// conversion function was resolved from an overloaded set having
446  /// size greater than 1.
448 
449  /// After - Represents the standard conversion that occurs after
450  /// the actual user-defined conversion.
452 
453  /// ConversionFunction - The function that will perform the
454  /// user-defined conversion. Null if the conversion is an
455  /// aggregate initialization from an initializer list.
457 
458  /// The declaration that we found via name lookup, which might be
459  /// the same as \c ConversionFunction or it might be a using declaration
460  /// that refers to \c ConversionFunction.
462 
463  void dump() const;
464  };
465 
466  /// Represents an ambiguous user-defined conversion sequence.
470 
471  void *FromTypePtr;
472  void *ToTypePtr;
473  char Buffer[sizeof(ConversionSet)];
474 
477  }
478 
479  QualType getToType() const {
481  }
482 
483  void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
484  void setToType(QualType T) { ToTypePtr = T.getAsOpaquePtr(); }
485 
487  return *reinterpret_cast<ConversionSet*>(Buffer);
488  }
489 
490  const ConversionSet &conversions() const {
491  return *reinterpret_cast<const ConversionSet*>(Buffer);
492  }
493 
495  conversions().push_back(std::make_pair(Found, D));
496  }
497 
498  using iterator = ConversionSet::iterator;
499 
500  iterator begin() { return conversions().begin(); }
501  iterator end() { return conversions().end(); }
502 
503  using const_iterator = ConversionSet::const_iterator;
504 
505  const_iterator begin() const { return conversions().begin(); }
506  const_iterator end() const { return conversions().end(); }
507 
508  void construct();
509  void destruct();
511  };
512 
513  /// BadConversionSequence - Records information about an invalid
514  /// conversion sequence.
516  enum FailureKind {
524  };
525 
526  // This can be null, e.g. for implicit object arguments.
528 
530 
531  private:
532  // The type we're converting from (an opaque QualType).
533  void *FromTy;
534 
535  // The type we're converting to (an opaque QualType).
536  void *ToTy;
537 
538  public:
539  void init(FailureKind K, Expr *From, QualType To) {
540  init(K, From->getType(), To);
541  FromExpr = From;
542  }
543 
544  void init(FailureKind K, QualType From, QualType To) {
545  Kind = K;
546  FromExpr = nullptr;
547  setFromType(From);
548  setToType(To);
549  }
550 
551  QualType getFromType() const { return QualType::getFromOpaquePtr(FromTy); }
553 
554  void setFromExpr(Expr *E) {
555  FromExpr = E;
556  setFromType(E->getType());
557  }
558 
559  void setFromType(QualType T) { FromTy = T.getAsOpaquePtr(); }
560  void setToType(QualType T) { ToTy = T.getAsOpaquePtr(); }
561  };
562 
563  /// ImplicitConversionSequence - Represents an implicit conversion
564  /// sequence, which may be a standard conversion sequence
565  /// (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2),
566  /// or an ellipsis conversion sequence (C++ 13.3.3.1.3).
568  public:
569  /// Kind - The kind of implicit conversion sequence. BadConversion
570  /// specifies that there is no conversion from the source type to
571  /// the target type. AmbiguousConversion represents the unique
572  /// ambiguous conversion (C++0x [over.best.ics]p10).
573  /// StaticObjectArgumentConversion represents the conversion rules for
574  /// the synthesized first argument of calls to static member functions
575  /// ([over.best.ics.general]p8).
576  enum Kind {
583  };
584 
585  private:
586  enum {
587  Uninitialized = BadConversion + 1
588  };
589 
590  /// ConversionKind - The kind of implicit conversion sequence.
591  LLVM_PREFERRED_TYPE(Kind)
592  unsigned ConversionKind : 31;
593 
594  // Whether the initializer list was of an incomplete array.
595  LLVM_PREFERRED_TYPE(bool)
596  unsigned InitializerListOfIncompleteArray : 1;
597 
598  /// When initializing an array or std::initializer_list from an
599  /// initializer-list, this is the array or std::initializer_list type being
600  /// initialized. The remainder of the conversion sequence, including ToType,
601  /// describe the worst conversion of an initializer to an element of the
602  /// array or std::initializer_list. (Note, 'worst' is not well defined.)
603  QualType InitializerListContainerType;
604 
605  void setKind(Kind K) {
606  destruct();
607  ConversionKind = K;
608  }
609 
610  void destruct() {
611  if (ConversionKind == AmbiguousConversion) Ambiguous.destruct();
612  }
613 
614  public:
615  union {
616  /// When ConversionKind == StandardConversion, provides the
617  /// details of the standard conversion sequence.
619 
620  /// When ConversionKind == UserDefinedConversion, provides the
621  /// details of the user-defined conversion sequence.
623 
624  /// When ConversionKind == AmbiguousConversion, provides the
625  /// details of the ambiguous conversion.
627 
628  /// When ConversionKind == BadConversion, provides the details
629  /// of the bad conversion.
631  };
632 
634  : ConversionKind(Uninitialized),
635  InitializerListOfIncompleteArray(false) {
637  }
638 
640  : ConversionKind(Other.ConversionKind),
641  InitializerListOfIncompleteArray(
642  Other.InitializerListOfIncompleteArray),
643  InitializerListContainerType(Other.InitializerListContainerType) {
644  switch (ConversionKind) {
645  case Uninitialized: break;
646  case StandardConversion: Standard = Other.Standard; break;
648  break;
649  case UserDefinedConversion: UserDefined = Other.UserDefined; break;
650  case AmbiguousConversion: Ambiguous.copyFrom(Other.Ambiguous); break;
651  case EllipsisConversion: break;
652  case BadConversion: Bad = Other.Bad; break;
653  }
654  }
655 
658  destruct();
659  new (this) ImplicitConversionSequence(Other);
660  return *this;
661  }
662 
664  destruct();
665  }
666 
667  Kind getKind() const {
668  assert(isInitialized() && "querying uninitialized conversion");
669  return Kind(ConversionKind);
670  }
671 
672  /// Return a ranking of the implicit conversion sequence
673  /// kind, where smaller ranks represent better conversion
674  /// sequences.
675  ///
676  /// In particular, this routine gives user-defined conversion
677  /// sequences and ambiguous conversion sequences the same rank,
678  /// per C++ [over.best.ics]p10.
679  unsigned getKindRank() const {
680  switch (getKind()) {
681  case StandardConversion:
683  return 0;
684 
686  case AmbiguousConversion:
687  return 1;
688 
689  case EllipsisConversion:
690  return 2;
691 
692  case BadConversion:
693  return 3;
694  }
695 
696  llvm_unreachable("Invalid ImplicitConversionSequence::Kind!");
697  }
698 
699  bool isBad() const { return getKind() == BadConversion; }
700  bool isStandard() const { return getKind() == StandardConversion; }
701  bool isStaticObjectArgument() const {
703  }
704  bool isEllipsis() const { return getKind() == EllipsisConversion; }
705  bool isAmbiguous() const { return getKind() == AmbiguousConversion; }
706  bool isUserDefined() const { return getKind() == UserDefinedConversion; }
707  bool isFailure() const { return isBad() || isAmbiguous(); }
708 
709  /// Determines whether this conversion sequence has been
710  /// initialized. Most operations should never need to query
711  /// uninitialized conversions and should assert as above.
712  bool isInitialized() const { return ConversionKind != Uninitialized; }
713 
714  /// Sets this sequence as a bad conversion for an explicit argument.
716  Expr *FromExpr, QualType ToType) {
717  setKind(BadConversion);
718  Bad.init(Failure, FromExpr, ToType);
719  }
720 
721  /// Sets this sequence as a bad conversion for an implicit argument.
723  QualType FromType, QualType ToType) {
724  setKind(BadConversion);
725  Bad.init(Failure, FromType, ToType);
726  }
727 
728  void setStandard() { setKind(StandardConversion); }
730  void setEllipsis() { setKind(EllipsisConversion); }
732 
733  void setAmbiguous() {
734  if (ConversionKind == AmbiguousConversion) return;
735  ConversionKind = AmbiguousConversion;
737  }
738 
740  setStandard();
744  }
745 
746  // True iff this is a conversion sequence from an initializer list to an
747  // array or std::initializer.
749  return !InitializerListContainerType.isNull();
750  }
752  InitializerListContainerType = T;
753  InitializerListOfIncompleteArray = IA;
754  }
756  return InitializerListOfIncompleteArray;
757  }
760  "not initializer list container");
761  return InitializerListContainerType;
762  }
763 
764  /// Form an "implicit" conversion sequence from nullptr_t to bool, for a
765  /// direct-initialization of a bool object from nullptr_t.
767  QualType DestType,
768  bool NeedLValToRVal) {
770  ICS.setStandard();
772  ICS.Standard.setFromType(SourceType);
773  if (NeedLValToRVal)
775  ICS.Standard.setToType(0, SourceType);
777  ICS.Standard.setToType(1, DestType);
778  ICS.Standard.setToType(2, DestType);
779  return ICS;
780  }
781 
782  // The result of a comparison between implicit conversion
783  // sequences. Use Sema::CompareImplicitConversionSequences to
784  // actually perform the comparison.
785  enum CompareKind {
786  Better = -1,
788  Worse = 1
789  };
790 
792  SourceLocation CaretLoc,
793  const PartialDiagnostic &PDiag) const;
794 
795  void dump() const;
796  };
797 
803 
804  /// This conversion candidate was not considered because it
805  /// duplicates the work of a trivial or derived-to-base
806  /// conversion.
808 
809  /// This conversion candidate was not considered because it is
810  /// an illegal instantiation of a constructor temploid: it is
811  /// callable with one argument, we only have one argument, and
812  /// its first parameter type is exactly the type of the class.
813  ///
814  /// Defining such a constructor directly is illegal, and
815  /// template-argument deduction is supposed to ignore such
816  /// instantiations, but we can still get one with the right
817  /// kind of implicit instantiation.
819 
820  /// This conversion candidate is not viable because its result
821  /// type is not implicitly convertible to the desired type.
823 
824  /// This conversion function template specialization candidate is not
825  /// viable because the final conversion was not an exact match.
827 
828  /// (CUDA) This candidate was not viable because the callee
829  /// was not accessible from the caller's target (i.e. host->device,
830  /// global->host, device->host).
832 
833  /// This candidate function was not viable because an enable_if
834  /// attribute disabled it.
836 
837  /// This candidate constructor or conversion function is explicit but
838  /// the context doesn't permit explicit functions.
840 
841  /// This candidate was not viable because its address could not be taken.
843 
844  /// This inherited constructor is not viable because it would slice the
845  /// argument.
847 
848  /// This candidate was not viable because it is a non-default multiversioned
849  /// function.
851 
852  /// This constructor/conversion candidate fail due to an address space
853  /// mismatch between the object being constructed and the overload
854  /// candidate.
856 
857  /// This candidate was not viable because its associated constraints were
858  /// not satisfied.
860 
861  /// This candidate was not viable because it has internal linkage and is
862  /// from a different module unit than the use.
864  };
865 
866  /// A list of implicit conversion sequences for the arguments of an
867  /// OverloadCandidate.
870 
871  /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
873  /// Function - The actual function that this candidate
874  /// represents. When NULL, this is a built-in candidate
875  /// (C++ [over.oper]) or a surrogate for a conversion to a
876  /// function pointer or reference (C++ [over.call.object]).
878 
879  /// FoundDecl - The original declaration that was looked up /
880  /// invented / otherwise found, together with its access.
881  /// Might be a UsingShadowDecl or a FunctionTemplateDecl.
883 
884  /// BuiltinParamTypes - Provides the parameter types of a built-in overload
885  /// candidate. Only valid when Function is NULL.
887 
888  /// Surrogate - The conversion function for which this candidate
889  /// is a surrogate, but only if IsSurrogate is true.
891 
892  /// The conversion sequences used to convert the function arguments
893  /// to the function parameters. Note that these are indexed by argument,
894  /// so may not match the parameter order of Function.
896 
897  /// The FixIt hints which can be used to fix the Bad candidate.
899 
900  /// Viable - True to indicate that this overload candidate is viable.
901  bool Viable : 1;
902 
903  /// Whether this candidate is the best viable function, or tied for being
904  /// the best viable function.
905  ///
906  /// For an ambiguous overload resolution, indicates whether this candidate
907  /// was part of the ambiguity kernel: the minimal non-empty set of viable
908  /// candidates such that all elements of the ambiguity kernel are better
909  /// than all viable candidates not in the ambiguity kernel.
910  bool Best : 1;
911 
912  /// IsSurrogate - True to indicate that this candidate is a
913  /// surrogate for a conversion to a function pointer or reference
914  /// (C++ [over.call.object]).
915  bool IsSurrogate : 1;
916 
917  /// IgnoreObjectArgument - True to indicate that the first
918  /// argument's conversion, which for this function represents the
919  /// implicit object argument, should be ignored. This will be true
920  /// when the candidate is a static member function (where the
921  /// implicit object argument is just a placeholder) or a
922  /// non-static member function when the call doesn't have an
923  /// object argument.
925 
927 
928  /// True if the candidate was found using ADL.
930 
931  /// Whether this is a rewritten candidate, and if so, of what kind?
932  LLVM_PREFERRED_TYPE(OverloadCandidateRewriteKind)
934 
935  /// FailureKind - The reason why this candidate is not viable.
936  /// Actually an OverloadFailureKind.
937  unsigned char FailureKind;
938 
939  /// The number of call arguments that were explicitly provided,
940  /// to be used while performing partial ordering of function templates.
942 
943  union {
945 
946  /// FinalConversion - For a conversion function (where Function is
947  /// a CXXConversionDecl), the standard conversion that occurs
948  /// after the call to the overload candidate to convert the result
949  /// of calling the conversion function to the required type.
951  };
952 
953  /// Get RewriteKind value in OverloadCandidateRewriteKind type (This
954  /// function is to workaround the spurious GCC bitfield enum warning)
956  return static_cast<OverloadCandidateRewriteKind>(RewriteKind);
957  }
958 
959  bool isReversed() const { return getRewriteKind() & CRK_Reversed; }
960 
961  /// hasAmbiguousConversion - Returns whether this overload
962  /// candidate requires an ambiguous conversion or not.
963  bool hasAmbiguousConversion() const {
964  for (auto &C : Conversions) {
965  if (!C.isInitialized()) return false;
966  if (C.isAmbiguous()) return true;
967  }
968  return false;
969  }
970 
971  bool TryToFixBadConversion(unsigned Idx, Sema &S) {
972  bool CanFix = Fix.tryToFixConversion(
973  Conversions[Idx].Bad.FromExpr,
974  Conversions[Idx].Bad.getFromType(),
975  Conversions[Idx].Bad.getToType(), S);
976 
977  // If at least one conversion fails, the candidate cannot be fixed.
978  if (!CanFix)
979  Fix.clear();
980 
981  return CanFix;
982  }
983 
984  unsigned getNumParams() const {
985  if (IsSurrogate) {
987  while (STy->isPointerOrReferenceType())
988  STy = STy->getPointeeType();
989  return STy->castAs<FunctionProtoType>()->getNumParams();
990  }
991  if (Function)
992  return Function->getNumParams();
993  return ExplicitCallArguments;
994  }
995 
997 
998  private:
999  friend class OverloadCandidateSet;
1003  RewriteKind(CRK_None) {}
1004  };
1005 
1006  /// OverloadCandidateSet - A set of overload candidates, used in C++
1007  /// overload resolution (C++ 13.3).
1009  public:
1011  /// Normal lookup.
1013 
1014  /// C++ [over.match.oper]:
1015  /// Lookup of operator function candidates in a call using operator
1016  /// syntax. Candidates that have no parameters of class type will be
1017  /// skipped unless there is a parameter of (reference to) enum type and
1018  /// the corresponding argument is of the same enum type.
1020 
1021  /// C++ [over.match.copy]:
1022  /// Copy-initialization of an object of class type by user-defined
1023  /// conversion.
1025 
1026  /// C++ [over.match.ctor], [over.match.list]
1027  /// Initialization of an object of class type by constructor,
1028  /// using either a parenthesized or braced list of arguments.
1030 
1031  /// C++ [over.match.call.general]
1032  /// Resolve a call through the address of an overload set.
1034  };
1035 
1036  /// Information about operator rewrites to consider when adding operator
1037  /// functions to a candidate set.
1042  bool AllowRewritten)
1043  : OriginalOperator(Op), OpLoc(OpLoc),
1044  AllowRewrittenCandidates(AllowRewritten) {}
1045 
1046  /// The original operator as written in the source.
1048  /// The source location of the operator.
1050  /// Whether we should include rewritten candidates in the overload set.
1052 
1053  /// Would use of this function result in a rewrite using a different
1054  /// operator?
1056  return OriginalOperator &&
1058  }
1059 
1061  if (!OriginalOperator)
1062  return true;
1063 
1064  // For an overloaded operator, we can have candidates with a different
1065  // name in our unqualified lookup set. Make sure we only consider the
1066  // ones we're supposed to.
1069  return OO && (OO == OriginalOperator ||
1072  }
1073 
1074  /// Determine the kind of rewrite that should be performed for this
1075  /// candidate.
1079  if (isRewrittenOperator(FD))
1083  return CRK;
1084  }
1085  /// Determines whether this operator could be implemented by a function
1086  /// with reversed parameter order.
1087  bool isReversible() {
1091  }
1092 
1093  /// Determine whether reversing parameter order is allowed for operator
1094  /// Op.
1096 
1097  /// Determine whether we should add a rewritten candidate for \p FD with
1098  /// reversed parameter order.
1099  /// \param OriginalArgs are the original non reversed arguments.
1100  bool shouldAddReversed(Sema &S, ArrayRef<Expr *> OriginalArgs,
1101  FunctionDecl *FD);
1102  };
1103 
1104  private:
1107 
1108  // Allocator for ConversionSequenceLists. We store the first few of these
1109  // inline to avoid allocation for small sets.
1110  llvm::BumpPtrAllocator SlabAllocator;
1111 
1112  SourceLocation Loc;
1113  CandidateSetKind Kind;
1114  OperatorRewriteInfo RewriteInfo;
1115 
1116  constexpr static unsigned NumInlineBytes =
1117  24 * sizeof(ImplicitConversionSequence);
1118  unsigned NumInlineBytesUsed = 0;
1119  alignas(void *) char InlineSpace[NumInlineBytes];
1120 
1121  // Address space of the object being constructed.
1122  LangAS DestAS = LangAS::Default;
1123 
1124  /// If we have space, allocates from inline storage. Otherwise, allocates
1125  /// from the slab allocator.
1126  /// FIXME: It would probably be nice to have a SmallBumpPtrAllocator
1127  /// instead.
1128  /// FIXME: Now that this only allocates ImplicitConversionSequences, do we
1129  /// want to un-generalize this?
1130  template <typename T>
1131  T *slabAllocate(unsigned N) {
1132  // It's simpler if this doesn't need to consider alignment.
1133  static_assert(alignof(T) == alignof(void *),
1134  "Only works for pointer-aligned types.");
1135  static_assert(std::is_trivial<T>::value ||
1136  std::is_same<ImplicitConversionSequence, T>::value,
1137  "Add destruction logic to OverloadCandidateSet::clear().");
1138 
1139  unsigned NBytes = sizeof(T) * N;
1140  if (NBytes > NumInlineBytes - NumInlineBytesUsed)
1141  return SlabAllocator.Allocate<T>(N);
1142  char *FreeSpaceStart = InlineSpace + NumInlineBytesUsed;
1143  assert(uintptr_t(FreeSpaceStart) % alignof(void *) == 0 &&
1144  "Misaligned storage!");
1145 
1146  NumInlineBytesUsed += NBytes;
1147  return reinterpret_cast<T *>(FreeSpaceStart);
1148  }
1149 
1150  void destroyCandidates();
1151 
1152  public:
1154  OperatorRewriteInfo RewriteInfo = {})
1155  : Loc(Loc), Kind(CSK), RewriteInfo(RewriteInfo) {}
1158  ~OverloadCandidateSet() { destroyCandidates(); }
1159 
1160  SourceLocation getLocation() const { return Loc; }
1161  CandidateSetKind getKind() const { return Kind; }
1162  OperatorRewriteInfo getRewriteInfo() const { return RewriteInfo; }
1163 
1164  /// Whether diagnostics should be deferred.
1165  bool shouldDeferDiags(Sema &S, ArrayRef<Expr *> Args, SourceLocation OpLoc);
1166 
1167  /// Determine when this overload candidate will be new to the
1168  /// overload set.
1171  uintptr_t Key = reinterpret_cast<uintptr_t>(F->getCanonicalDecl());
1172  Key |= static_cast<uintptr_t>(PO);
1173  return Functions.insert(Key).second;
1174  }
1175 
1176  /// Exclude a function from being considered by overload resolution.
1177  void exclude(Decl *F) {
1180  }
1181 
1182  /// Clear out all of the candidates.
1183  void clear(CandidateSetKind CSK);
1184 
1186 
1187  iterator begin() { return Candidates.begin(); }
1188  iterator end() { return Candidates.end(); }
1189 
1190  size_t size() const { return Candidates.size(); }
1191  bool empty() const { return Candidates.empty(); }
1192 
1193  /// Allocate storage for conversion sequences for NumConversions
1194  /// conversions.
1196  allocateConversionSequences(unsigned NumConversions) {
1197  ImplicitConversionSequence *Conversions =
1198  slabAllocate<ImplicitConversionSequence>(NumConversions);
1199 
1200  // Construct the new objects.
1201  for (unsigned I = 0; I != NumConversions; ++I)
1202  new (&Conversions[I]) ImplicitConversionSequence();
1203 
1204  return ConversionSequenceList(Conversions, NumConversions);
1205  }
1206 
1207  /// Add a new candidate with NumConversions conversion sequence slots
1208  /// to the overload set.
1210  addCandidate(unsigned NumConversions = 0,
1211  ConversionSequenceList Conversions = std::nullopt) {
1212  assert((Conversions.empty() || Conversions.size() == NumConversions) &&
1213  "preallocated conversion sequence has wrong length");
1214 
1215  Candidates.push_back(OverloadCandidate());
1216  OverloadCandidate &C = Candidates.back();
1217  C.Conversions = Conversions.empty()
1218  ? allocateConversionSequences(NumConversions)
1219  : Conversions;
1220  return C;
1221  }
1222 
1223  /// Find the best viable function on this overload set, if it exists.
1226 
1229  SourceLocation OpLoc = SourceLocation(),
1230  llvm::function_ref<bool(OverloadCandidate &)> Filter =
1231  [](OverloadCandidate &) { return true; });
1232 
1233  void NoteCandidates(
1235  ArrayRef<Expr *> Args, StringRef Opc = "",
1236  SourceLocation Loc = SourceLocation(),
1237  llvm::function_ref<bool(OverloadCandidate &)> Filter =
1238  [](OverloadCandidate &) { return true; });
1239 
1240  void NoteCandidates(Sema &S, ArrayRef<Expr *> Args,
1241  ArrayRef<OverloadCandidate *> Cands,
1242  StringRef Opc = "",
1243  SourceLocation OpLoc = SourceLocation());
1244 
1245  LangAS getDestAS() { return DestAS; }
1246 
1247  void setDestAS(LangAS AS) {
1248  assert((Kind == CSK_InitByConstructor ||
1250  "can't set the destination address space when not constructing an "
1251  "object");
1252  DestAS = AS;
1253  }
1254 
1255  };
1256 
1257  bool isBetterOverloadCandidate(Sema &S,
1258  const OverloadCandidate &Cand1,
1259  const OverloadCandidate &Cand2,
1260  SourceLocation Loc,
1262 
1267 
1268  explicit operator bool() const { return Constructor; }
1269  };
1270 
1271  // FIXME: Add an AddOverloadCandidate / AddTemplateOverloadCandidate overload
1272  // that takes one of these.
1274  if (isa<UsingDecl>(ND))
1275  return ConstructorInfo{};
1276 
1277  // For constructors, the access check is performed against the underlying
1278  // declaration, not the found declaration.
1279  auto *D = ND->getUnderlyingDecl();
1280  ConstructorInfo Info = {DeclAccessPair::make(ND, D->getAccess()), nullptr,
1281  nullptr};
1282  Info.ConstructorTmpl = dyn_cast<FunctionTemplateDecl>(D);
1283  if (Info.ConstructorTmpl)
1285  Info.Constructor = dyn_cast<CXXConstructorDecl>(D);
1286  return Info;
1287  }
1288 
1289  // Returns false if signature help is relevant despite number of arguments
1290  // exceeding parameters. Specifically, it returns false when
1291  // PartialOverloading is true and one of the following:
1292  // * Function is variadic
1293  // * Function is template variadic
1294  // * Function is an instantiation of template variadic function
1295  // The last case may seem strange. The idea is that if we added one more
1296  // argument, we'd end up with a function similar to Function. Since, in the
1297  // context of signature help and/or code completion, we do not know what the
1298  // type of the next argument (that the user is typing) will be, this is as
1299  // good candidate as we can get, despite the fact that it takes one less
1300  // parameter.
1301  bool shouldEnforceArgLimit(bool PartialOverloading, FunctionDecl *Function);
1302 
1303 } // namespace clang
1304 
1305 #endif // LLVM_CLANG_SEMA_OVERLOAD_H
const Decl * D
enum clang::sema::@1659::IndirectLocalPathEntry::EntryKind Kind
Expr * E
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
SourceLocation Loc
Definition: SemaObjC.cpp:759
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2539
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2866
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Definition: DeclCXX.h:2906
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2882
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:968
AccessSpecifier getAccess() const
Definition: DeclBase.h:514
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
This represents one expression.
Definition: Expr.h:110
QualType getType() const
Definition: Expr.h:142
Represents a function declaration or definition.
Definition: Decl.h:1933
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3682
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5012
Declaration of a template function.
Definition: DeclTemplate.h:957
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
ImplicitConversionSequence - Represents an implicit conversion sequence, which may be a standard conv...
Definition: Overload.h:567
void dump() const
dump - Print this implicit conversion sequence to standard error.
Kind
Kind - The kind of implicit conversion sequence.
Definition: Overload.h:576
StandardConversionSequence Standard
When ConversionKind == StandardConversion, provides the details of the standard conversion sequence.
Definition: Overload.h:618
void setBad(BadConversionSequence::FailureKind Failure, Expr *FromExpr, QualType ToType)
Sets this sequence as a bad conversion for an explicit argument.
Definition: Overload.h:715
UserDefinedConversionSequence UserDefined
When ConversionKind == UserDefinedConversion, provides the details of the user-defined conversion seq...
Definition: Overload.h:622
ImplicitConversionSequence(const ImplicitConversionSequence &Other)
Definition: Overload.h:639
bool isInitialized() const
Determines whether this conversion sequence has been initialized.
Definition: Overload.h:712
static ImplicitConversionSequence getNullptrToBool(QualType SourceType, QualType DestType, bool NeedLValToRVal)
Form an "implicit" conversion sequence from nullptr_t to bool, for a direct-initialization of a bool ...
Definition: Overload.h:766
AmbiguousConversionSequence Ambiguous
When ConversionKind == AmbiguousConversion, provides the details of the ambiguous conversion.
Definition: Overload.h:626
void setInitializerListContainerType(QualType T, bool IA)
Definition: Overload.h:751
bool hasInitializerListContainerType() const
Definition: Overload.h:748
unsigned getKindRank() const
Return a ranking of the implicit conversion sequence kind, where smaller ranks represent better conve...
Definition: Overload.h:679
bool isInitializerListOfIncompleteArray() const
Definition: Overload.h:755
BadConversionSequence Bad
When ConversionKind == BadConversion, provides the details of the bad conversion.
Definition: Overload.h:630
QualType getInitializerListContainerType() const
Definition: Overload.h:758
void setAsIdentityConversion(QualType T)
Definition: Overload.h:739
void DiagnoseAmbiguousConversion(Sema &S, SourceLocation CaretLoc, const PartialDiagnostic &PDiag) const
Diagnoses an ambiguous conversion.
void setBad(BadConversionSequence::FailureKind Failure, QualType FromType, QualType ToType)
Sets this sequence as a bad conversion for an implicit argument.
Definition: Overload.h:722
ImplicitConversionSequence & operator=(const ImplicitConversionSequence &Other)
Definition: Overload.h:657
This represents a decl that may have a name.
Definition: Decl.h:249
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:315
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:463
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
Definition: Overload.h:1008
void clear(CandidateSetKind CSK)
Clear out all of the candidates.
OverloadCandidateSet & operator=(const OverloadCandidateSet &)=delete
bool isNewCandidate(Decl *F, OverloadCandidateParamOrder PO=OverloadCandidateParamOrder::Normal)
Determine when this overload candidate will be new to the overload set.
Definition: Overload.h:1169
void setDestAS(LangAS AS)
Definition: Overload.h:1247
ConversionSequenceList allocateConversionSequences(unsigned NumConversions)
Allocate storage for conversion sequences for NumConversions conversions.
Definition: Overload.h:1196
OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK, OperatorRewriteInfo RewriteInfo={})
Definition: Overload.h:1153
OperatorRewriteInfo getRewriteInfo() const
Definition: Overload.h:1162
@ CSK_AddressOfOverloadSet
C++ [over.match.call.general] Resolve a call through the address of an overload set.
Definition: Overload.h:1033
@ CSK_InitByConstructor
C++ [over.match.ctor], [over.match.list] Initialization of an object of class type by constructor,...
Definition: Overload.h:1029
@ CSK_InitByUserDefinedConversion
C++ [over.match.copy]: Copy-initialization of an object of class type by user-defined conversion.
Definition: Overload.h:1024
@ CSK_Normal
Normal lookup.
Definition: Overload.h:1012
@ CSK_Operator
C++ [over.match.oper]: Lookup of operator function candidates in a call using operator syntax.
Definition: Overload.h:1019
SmallVectorImpl< OverloadCandidate >::iterator iterator
Definition: Overload.h:1185
void NoteCandidates(PartialDiagnosticAt PA, Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr * > Args, StringRef Opc="", SourceLocation Loc=SourceLocation(), llvm::function_ref< bool(OverloadCandidate &)> Filter=[](OverloadCandidate &) { return true;})
When overload resolution fails, prints diagnostic messages containing the candidates in the candidate...
OverloadCandidateSet(const OverloadCandidateSet &)=delete
bool shouldDeferDiags(Sema &S, ArrayRef< Expr * > Args, SourceLocation OpLoc)
Whether diagnostics should be deferred.
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best)
Find the best viable function on this overload set, if it exists.
void exclude(Decl *F)
Exclude a function from being considered by overload resolution.
Definition: Overload.h:1177
SourceLocation getLocation() const
Definition: Overload.h:1160
OverloadCandidate & addCandidate(unsigned NumConversions=0, ConversionSequenceList Conversions=std::nullopt)
Add a new candidate with NumConversions conversion sequence slots to the overload set.
Definition: Overload.h:1210
CandidateSetKind getKind() const
Definition: Overload.h:1161
SmallVector< OverloadCandidate *, 32 > CompleteCandidates(Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr * > Args, SourceLocation OpLoc=SourceLocation(), llvm::function_ref< bool(OverloadCandidate &)> Filter=[](OverloadCandidate &) { return true;})
A (possibly-)qualified type.
Definition: Type.h:941
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:990
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:493
Encodes a location in the source.
StandardConversionSequence - represents a standard conversion sequence (C++ 13.3.3....
Definition: Overload.h:292
void dump() const
dump - Print this standard conversion sequence to standard error.
void setFromType(QualType T)
Definition: Overload.h:381
DeclAccessPair FoundCopyConstructor
Definition: Overload.h:379
void * FromTypePtr
FromType - The type that this conversion is converting from.
Definition: Overload.h:366
unsigned BindsToRvalue
Whether we're binding to an rvalue.
Definition: Overload.h:351
ImplicitConversionKind Second
Second - The second conversion can be an integral promotion, floating point promotion,...
Definition: Overload.h:303
QualType getFromType() const
Definition: Overload.h:394
ImplicitConversionKind First
First – The first conversion can be an lvalue-to-rvalue conversion, array-to-pointer conversion,...
Definition: Overload.h:297
unsigned BindsImplicitObjectArgumentWithoutRefQualifier
Whether this binds an implicit object argument to a non-static member function without a ref-qualifie...
Definition: Overload.h:356
unsigned ReferenceBinding
ReferenceBinding - True when this is a reference binding (C++ [over.ics.ref]).
Definition: Overload.h:333
void setAsIdentityConversion()
StandardConversionSequence - Set the standard conversion sequence to the identity conversion.
unsigned DeprecatedStringLiteralToCharPtr
Whether this is the deprecated conversion of a string literal to a pointer to non-const character dat...
Definition: Overload.h:318
CXXConstructorDecl * CopyConstructor
CopyConstructor - The copy constructor that is used to perform this conversion, when the conversion i...
Definition: Overload.h:378
unsigned IncompatibleObjC
IncompatibleObjC - Whether this is an Objective-C conversion that we should warn about (if we actuall...
Definition: Overload.h:328
unsigned ObjCLifetimeConversionBinding
Whether this binds a reference to an object with a different Objective-C lifetime qualifier.
Definition: Overload.h:361
ImplicitConversionKind Third
Third - The third conversion can be a qualification conversion or a function conversion.
Definition: Overload.h:312
unsigned QualificationIncludesObjCLifetime
Whether the qualification conversion involves a change in the Objective-C lifetime (for automatic ref...
Definition: Overload.h:323
void setToType(unsigned Idx, QualType T)
Definition: Overload.h:383
bool isPointerConversionToBool() const
isPointerConversionToBool - Determines whether this conversion is a conversion of a pointer or pointe...
void * ToTypePtrs[3]
ToType - The types that this conversion is converting to in each step.
Definition: Overload.h:371
NarrowingKind getNarrowingKind(ASTContext &Context, const Expr *Converted, APValue &ConstantValue, QualType &ConstantType, bool IgnoreFloatToIntegralConversion=false) const
Check if this standard conversion sequence represents a narrowing conversion, according to C++11 [dcl...
unsigned IsLvalueReference
Whether this is an lvalue reference binding (otherwise, it's an rvalue reference binding).
Definition: Overload.h:343
ImplicitConversionKind Dimension
Dimension - Between the second and third conversion a vector or matrix dimension conversion may occur...
Definition: Overload.h:308
unsigned BindsToFunctionLvalue
Whether we're binding to a function lvalue.
Definition: Overload.h:347
unsigned DirectBinding
DirectBinding - True when this is a reference binding that is a direct binding (C++ [dcl....
Definition: Overload.h:338
ImplicitConversionRank getRank() const
getRank - Retrieve the rank of this standard conversion sequence (C++ 13.3.3.1.1p3).
bool isPointerConversionToVoidPointer(ASTContext &Context) const
isPointerConversionToVoidPointer - Determines whether this conversion is a conversion of a pointer to...
void setAllToTypes(QualType T)
Definition: Overload.h:388
QualType getToType(unsigned Idx) const
Definition: Overload.h:398
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8635
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:705
bool isPointerOrReferenceType() const
Definition: Type.h:8017
llvm::cl::opt< std::string > Filter
The JSON file list parser is used to communicate input to InstallAPI.
ImplicitConversionRank GetDimensionConversionRank(ImplicitConversionRank Base, ImplicitConversionKind Dimension)
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
@ OO_None
Not an overloaded operator.
Definition: OperatorKinds.h:22
llvm::MutableArrayRef< ImplicitConversionSequence > ConversionSequenceList
A list of implicit conversion sequences for the arguments of an OverloadCandidate.
Definition: Overload.h:869
OverloadingResult
OverloadingResult - Capture the result of performing overload resolution.
Definition: Overload.h:50
@ OR_Deleted
Succeeded, but refers to a deleted function.
Definition: Overload.h:61
@ OR_Success
Overload resolution succeeded.
Definition: Overload.h:52
@ OR_Ambiguous
Ambiguous candidates found.
Definition: Overload.h:58
@ OR_No_Viable_Function
No viable function found.
Definition: Overload.h:55
OverloadFailureKind
Definition: Overload.h:798
@ ovl_fail_final_conversion_not_exact
This conversion function template specialization candidate is not viable because the final conversion...
Definition: Overload.h:826
@ ovl_fail_enable_if
This candidate function was not viable because an enable_if attribute disabled it.
Definition: Overload.h:835
@ ovl_fail_illegal_constructor
This conversion candidate was not considered because it is an illegal instantiation of a constructor ...
Definition: Overload.h:818
@ ovl_fail_bad_final_conversion
This conversion candidate is not viable because its result type is not implicitly convertible to the ...
Definition: Overload.h:822
@ ovl_fail_module_mismatched
This candidate was not viable because it has internal linkage and is from a different module unit tha...
Definition: Overload.h:863
@ ovl_fail_too_few_arguments
Definition: Overload.h:800
@ ovl_fail_addr_not_available
This candidate was not viable because its address could not be taken.
Definition: Overload.h:842
@ ovl_fail_too_many_arguments
Definition: Overload.h:799
@ ovl_non_default_multiversion_function
This candidate was not viable because it is a non-default multiversioned function.
Definition: Overload.h:850
@ ovl_fail_constraints_not_satisfied
This candidate was not viable because its associated constraints were not satisfied.
Definition: Overload.h:859
@ ovl_fail_bad_conversion
Definition: Overload.h:801
@ ovl_fail_bad_target
(CUDA) This candidate was not viable because the callee was not accessible from the caller's target (...
Definition: Overload.h:831
@ ovl_fail_bad_deduction
Definition: Overload.h:802
@ ovl_fail_inhctor_slice
This inherited constructor is not viable because it would slice the argument.
Definition: Overload.h:846
@ ovl_fail_object_addrspace_mismatch
This constructor/conversion candidate fail due to an address space mismatch between the object being ...
Definition: Overload.h:855
@ ovl_fail_explicit
This candidate constructor or conversion function is explicit but the context doesn't permit explicit...
Definition: Overload.h:839
@ ovl_fail_trivial_conversion
This conversion candidate was not considered because it duplicates the work of a trivial or derived-t...
Definition: Overload.h:807
ImplicitConversionRank
ImplicitConversionRank - The rank of an implicit conversion kind.
Definition: Overload.h:215
@ ICR_Conversion
Conversion.
Definition: Overload.h:232
@ ICR_Writeback_Conversion
ObjC ARC writeback conversion.
Definition: Overload.h:244
@ ICR_HLSL_Dimension_Reduction
HLSL Matching Dimension Reduction.
Definition: Overload.h:229
@ ICR_HLSL_Dimension_Reduction_Conversion
HLSL Dimension reduction with conversion.
Definition: Overload.h:257
@ ICR_HLSL_Scalar_Widening
HLSL Scalar Widening.
Definition: Overload.h:220
@ ICR_C_Conversion
Conversion only allowed in the C standard (e.g. void* to char*).
Definition: Overload.h:247
@ ICR_OCL_Scalar_Widening
OpenCL Scalar Widening.
Definition: Overload.h:235
@ ICR_Complex_Real_Conversion
Complex <-> Real conversion.
Definition: Overload.h:241
@ ICR_HLSL_Scalar_Widening_Conversion
HLSL Scalar Widening with conversion.
Definition: Overload.h:238
@ ICR_HLSL_Dimension_Reduction_Promotion
HLSL Dimension reduction with promotion.
Definition: Overload.h:254
@ ICR_Promotion
Promotion.
Definition: Overload.h:223
@ ICR_Exact_Match
Exact Match.
Definition: Overload.h:217
@ ICR_C_Conversion_Extension
Conversion not allowed by the C standard, but that we accept as an extension anyway.
Definition: Overload.h:251
@ ICR_HLSL_Scalar_Widening_Promotion
HLSL Scalar Widening with promotion.
Definition: Overload.h:226
OverloadCandidateDisplayKind
Definition: Overload.h:64
@ OCD_AmbiguousCandidates
Requests that only tied-for-best candidates be shown.
Definition: Overload.h:73
@ OCD_ViableCandidates
Requests that only viable candidates be shown.
Definition: Overload.h:70
@ OCD_AllCandidates
Requests that all candidates be shown.
Definition: Overload.h:67
OverloadCandidateParamOrder
The parameter ordering that will be used for the candidate.
Definition: Overload.h:84
OverloadCandidateRewriteKind
The kinds of rewrite we perform on overload candidates.
Definition: Overload.h:89
@ CRK_Reversed
Candidate is a rewritten candidate with a reversed order of parameters.
Definition: Overload.h:97
@ CRK_None
Candidate is not a rewritten candidate.
Definition: Overload.h:91
@ CRK_DifferentOperator
Candidate is a rewritten candidate with a different operator name.
Definition: Overload.h:94
ImplicitConversionKind
ImplicitConversionKind - The kind of implicit conversion used to convert an argument to a parameter's...
Definition: Overload.h:104
@ ICK_Complex_Conversion
Complex conversions (C99 6.3.1.6)
Definition: Overload.h:139
@ ICK_Floating_Promotion
Floating point promotions (C++ [conv.fpprom])
Definition: Overload.h:127
@ ICK_Boolean_Conversion
Boolean conversions (C++ [conv.bool])
Definition: Overload.h:151
@ ICK_Integral_Conversion
Integral conversions (C++ [conv.integral])
Definition: Overload.h:133
@ ICK_HLSL_Vector_Splat
Definition: Overload.h:205
@ ICK_Fixed_Point_Conversion
Fixed point type conversions according to N1169.
Definition: Overload.h:196
@ ICK_Vector_Conversion
Vector conversions.
Definition: Overload.h:160
@ ICK_Block_Pointer_Conversion
Block Pointer conversions.
Definition: Overload.h:175
@ ICK_Pointer_Member
Pointer-to-member conversions (C++ [conv.mem])
Definition: Overload.h:148
@ ICK_Floating_Integral
Floating-integral conversions (C++ [conv.fpint])
Definition: Overload.h:142
@ ICK_HLSL_Array_RValue
HLSL non-decaying array rvalue cast.
Definition: Overload.h:202
@ ICK_SVE_Vector_Conversion
Arm SVE Vector conversions.
Definition: Overload.h:163
@ ICK_HLSL_Vector_Truncation
HLSL vector truncation.
Definition: Overload.h:199
@ ICK_Incompatible_Pointer_Conversion
C-only conversion between pointers with incompatible types.
Definition: Overload.h:193
@ ICK_Array_To_Pointer
Array-to-pointer conversion (C++ [conv.array])
Definition: Overload.h:112
@ ICK_RVV_Vector_Conversion
RISC-V RVV Vector conversions.
Definition: Overload.h:166
@ ICK_Complex_Promotion
Complex promotions (Clang extension)
Definition: Overload.h:130
@ ICK_Num_Conversion_Kinds
The number of conversion kinds.
Definition: Overload.h:208
@ ICK_Function_Conversion
Function pointer conversion (C++17 [conv.fctptr])
Definition: Overload.h:118
@ ICK_Vector_Splat
A vector splat from an arithmetic type.
Definition: Overload.h:169
@ ICK_Zero_Queue_Conversion
Zero constant to queue.
Definition: Overload.h:187
@ ICK_Identity
Identity conversion (no conversion)
Definition: Overload.h:106
@ ICK_Derived_To_Base
Derived-to-base (C++ [over.best.ics])
Definition: Overload.h:157
@ ICK_Lvalue_To_Rvalue
Lvalue-to-rvalue conversion (C++ [conv.lval])
Definition: Overload.h:109
@ ICK_Qualification
Qualification conversions (C++ [conv.qual])
Definition: Overload.h:121
@ ICK_Pointer_Conversion
Pointer conversions (C++ [conv.ptr])
Definition: Overload.h:145
@ ICK_TransparentUnionConversion
Transparent Union Conversions.
Definition: Overload.h:178
@ ICK_Integral_Promotion
Integral promotions (C++ [conv.prom])
Definition: Overload.h:124
@ ICK_Floating_Conversion
Floating point conversions (C++ [conv.double].
Definition: Overload.h:136
@ ICK_Compatible_Conversion
Conversions between compatible types in C99.
Definition: Overload.h:154
@ ICK_C_Only_Conversion
Conversions allowed in C, but not C++.
Definition: Overload.h:190
@ ICK_Writeback_Conversion
Objective-C ARC writeback conversion.
Definition: Overload.h:181
@ ICK_Zero_Event_Conversion
Zero constant to event (OpenCL1.2 6.12.10)
Definition: Overload.h:184
@ ICK_Complex_Real
Complex-real conversions (C99 6.3.1.7)
Definition: Overload.h:172
@ ICK_Function_To_Pointer
Function-to-pointer (C++ [conv.array])
Definition: Overload.h:115
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
OverloadedOperatorKind getRewrittenOverloadedOperator(OverloadedOperatorKind Kind)
Get the other overloaded operator that the given operator can be rewritten into, if any such operator...
Definition: OperatorKinds.h:36
bool isBetterOverloadCandidate(Sema &S, const OverloadCandidate &Cand1, const OverloadCandidate &Cand2, SourceLocation Loc, OverloadCandidateSet::CandidateSetKind Kind)
isBetterOverloadCandidate - Determines whether the first overload candidate is a better candidate tha...
const FunctionProtoType * T
bool shouldEnforceArgLimit(bool PartialOverloading, FunctionDecl *Function)
NarrowingKind
NarrowingKind - The kind of narrowing conversion being performed by a standard conversion sequence ac...
Definition: Overload.h:268
@ NK_Not_Narrowing
Not a narrowing conversion.
Definition: Overload.h:270
@ NK_Constant_Narrowing
A narrowing conversion, because a constant expression got narrowed.
Definition: Overload.h:276
@ NK_Dependent_Narrowing
Cannot tell whether this is a narrowing conversion because the expression is value-dependent.
Definition: Overload.h:284
@ NK_Type_Narrowing
A narrowing conversion by virtue of the source and destination types.
Definition: Overload.h:273
@ NK_Variable_Narrowing
A narrowing conversion, because a non-constant-expression variable might have got narrowed.
Definition: Overload.h:280
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
ConstructorInfo getConstructorInfo(NamedDecl *ND)
Definition: Overload.h:1273
ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind)
GetConversionRank - Retrieve the implicit conversion rank corresponding to the given implicit convers...
@ Other
Other implicit parameter.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
#define false
Definition: stdbool.h:26
#define bool
Definition: stdbool.h:24
Represents an ambiguous user-defined conversion sequence.
Definition: Overload.h:467
ConversionSet::const_iterator const_iterator
Definition: Overload.h:503
ConversionSet & conversions()
Definition: Overload.h:486
const_iterator end() const
Definition: Overload.h:506
void addConversion(NamedDecl *Found, FunctionDecl *D)
Definition: Overload.h:494
SmallVector< std::pair< NamedDecl *, FunctionDecl * >, 4 > ConversionSet
Definition: Overload.h:469
char Buffer[sizeof(ConversionSet)]
Definition: Overload.h:473
void copyFrom(const AmbiguousConversionSequence &)
const ConversionSet & conversions() const
Definition: Overload.h:490
ConversionSet::iterator iterator
Definition: Overload.h:498
const_iterator begin() const
Definition: Overload.h:505
BadConversionSequence - Records information about an invalid conversion sequence.
Definition: Overload.h:515
void setToType(QualType T)
Definition: Overload.h:560
void setFromType(QualType T)
Definition: Overload.h:559
void init(FailureKind K, Expr *From, QualType To)
Definition: Overload.h:539
void init(FailureKind K, QualType From, QualType To)
Definition: Overload.h:544
QualType getToType() const
Definition: Overload.h:552
void setFromExpr(Expr *E)
Definition: Overload.h:554
QualType getFromType() const
Definition: Overload.h:551
FunctionTemplateDecl * ConstructorTmpl
Definition: Overload.h:1266
CXXConstructorDecl * Constructor
Definition: Overload.h:1265
DeclAccessPair FoundDecl
Definition: Overload.h:1264
The class facilities generation and storage of conversion FixIts.
bool tryToFixConversion(const Expr *FromExpr, const QualType FromQTy, const QualType ToQTy, Sema &S)
If possible, generates and stores a fix for the given conversion.
A structure used to record information about a failed template argument deduction,...
Information about operator rewrites to consider when adding operator functions to a candidate set.
Definition: Overload.h:1038
bool shouldAddReversed(Sema &S, ArrayRef< Expr * > OriginalArgs, FunctionDecl *FD)
Determine whether we should add a rewritten candidate for FD with reversed parameter order.
bool allowsReversed(OverloadedOperatorKind Op)
Determine whether reversing parameter order is allowed for operator Op.
OperatorRewriteInfo(OverloadedOperatorKind Op, SourceLocation OpLoc, bool AllowRewritten)
Definition: Overload.h:1041
bool isRewrittenOperator(const FunctionDecl *FD)
Would use of this function result in a rewrite using a different operator?
Definition: Overload.h:1055
SourceLocation OpLoc
The source location of the operator.
Definition: Overload.h:1049
bool AllowRewrittenCandidates
Whether we should include rewritten candidates in the overload set.
Definition: Overload.h:1051
bool isReversible()
Determines whether this operator could be implemented by a function with reversed parameter order.
Definition: Overload.h:1087
OverloadedOperatorKind OriginalOperator
The original operator as written in the source.
Definition: Overload.h:1047
bool isAcceptableCandidate(const FunctionDecl *FD)
Definition: Overload.h:1060
OverloadCandidateRewriteKind getRewriteKind(const FunctionDecl *FD, OverloadCandidateParamOrder PO)
Determine the kind of rewrite that should be performed for this candidate.
Definition: Overload.h:1077
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
Definition: Overload.h:872
CallExpr::ADLCallKind IsADLCandidate
True if the candidate was found using ADL.
Definition: Overload.h:929
bool TryToFixBadConversion(unsigned Idx, Sema &S)
Definition: Overload.h:971
bool NotValidBecauseConstraintExprHasError() const
bool isReversed() const
Definition: Overload.h:959
bool IsSurrogate
IsSurrogate - True to indicate that this candidate is a surrogate for a conversion to a function poin...
Definition: Overload.h:915
QualType BuiltinParamTypes[3]
BuiltinParamTypes - Provides the parameter types of a built-in overload candidate.
Definition: Overload.h:886
bool hasAmbiguousConversion() const
hasAmbiguousConversion - Returns whether this overload candidate requires an ambiguous conversion or ...
Definition: Overload.h:963
bool IgnoreObjectArgument
IgnoreObjectArgument - True to indicate that the first argument's conversion, which for this function...
Definition: Overload.h:924
DeclAccessPair FoundDecl
FoundDecl - The original declaration that was looked up / invented / otherwise found,...
Definition: Overload.h:882
FunctionDecl * Function
Function - The actual function that this candidate represents.
Definition: Overload.h:877
bool Viable
Viable - True to indicate that this overload candidate is viable.
Definition: Overload.h:901
unsigned RewriteKind
Whether this is a rewritten candidate, and if so, of what kind?
Definition: Overload.h:933
ConversionFixItGenerator Fix
The FixIt hints which can be used to fix the Bad candidate.
Definition: Overload.h:898
StandardConversionSequence FinalConversion
FinalConversion - For a conversion function (where Function is a CXXConversionDecl),...
Definition: Overload.h:950
unsigned getNumParams() const
Definition: Overload.h:984
unsigned ExplicitCallArguments
The number of call arguments that were explicitly provided, to be used while performing partial order...
Definition: Overload.h:941
unsigned char FailureKind
FailureKind - The reason why this candidate is not viable.
Definition: Overload.h:937
ConversionSequenceList Conversions
The conversion sequences used to convert the function arguments to the function parameters.
Definition: Overload.h:895
DeductionFailureInfo DeductionFailure
Definition: Overload.h:944
bool Best
Whether this candidate is the best viable function, or tied for being the best viable function.
Definition: Overload.h:910
CXXConversionDecl * Surrogate
Surrogate - The conversion function for which this candidate is a surrogate, but only if IsSurrogate ...
Definition: Overload.h:890
OverloadCandidateRewriteKind getRewriteKind() const
Get RewriteKind value in OverloadCandidateRewriteKind type (This function is to workaround the spurio...
Definition: Overload.h:955
UserDefinedConversionSequence - Represents a user-defined conversion sequence (C++ 13....
Definition: Overload.h:422
StandardConversionSequence Before
Represents the standard conversion that occurs before the actual user-defined conversion.
Definition: Overload.h:434
FunctionDecl * ConversionFunction
ConversionFunction - The function that will perform the user-defined conversion.
Definition: Overload.h:456
bool HadMultipleCandidates
HadMultipleCandidates - When this is true, it means that the conversion function was resolved from an...
Definition: Overload.h:447
StandardConversionSequence After
After - Represents the standard conversion that occurs after the actual user-defined conversion.
Definition: Overload.h:451
bool EllipsisConversion
EllipsisConversion - When this is true, it means user-defined conversion sequence starts with a ....
Definition: Overload.h:442
DeclAccessPair FoundConversionFunction
The declaration that we found via name lookup, which might be the same as ConversionFunction or it mi...
Definition: Overload.h:461
void dump() const
dump - Print this user-defined conversion sequence to standard error.