clang 17.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"
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
42namespace clang {
43
44class APValue;
45class ASTContext;
46class 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).
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.
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 /// A vector splat from an arithmetic type
167
168 /// Complex-real conversions (C99 6.3.1.7)
170
171 /// Block Pointer conversions
173
174 /// Transparent Union Conversions
176
177 /// Objective-C ARC writeback conversion
179
180 /// Zero constant to event (OpenCL1.2 6.12.10)
182
183 /// Zero constant to queue
185
186 /// Conversions allowed in C, but not C++
188
189 /// C-only conversion between pointers with incompatible types
191
192 /// The number of conversion kinds
194 };
195
196 /// ImplicitConversionRank - The rank of an implicit conversion
197 /// kind. The enumerator values match with Table 9 of (C++
198 /// 13.3.3.1.1) and are listed such that better conversion ranks
199 /// have smaller values.
201 /// Exact Match
203
204 /// Promotion
206
207 /// Conversion
209
210 /// OpenCL Scalar Widening
212
213 /// Complex <-> Real conversion
215
216 /// ObjC ARC writeback conversion
218
219 /// Conversion only allowed in the C standard (e.g. void* to char*).
221
222 /// Conversion not allowed by the C standard, but that we accept as an
223 /// extension anyway.
225 };
226
228
229 /// NarrowingKind - The kind of narrowing conversion being performed by a
230 /// standard conversion sequence according to C++11 [dcl.init.list]p7.
232 /// Not a narrowing conversion.
234
235 /// A narrowing conversion by virtue of the source and destination types.
237
238 /// A narrowing conversion, because a constant expression got narrowed.
240
241 /// A narrowing conversion, because a non-constant-expression variable might
242 /// have got narrowed.
244
245 /// Cannot tell whether this is a narrowing conversion because the
246 /// expression is value-dependent.
248 };
249
250 /// StandardConversionSequence - represents a standard conversion
251 /// sequence (C++ 13.3.3.1.1). A standard conversion sequence
252 /// contains between zero and three conversions. If a particular
253 /// conversion is not needed, it will be set to the identity conversion
254 /// (ICK_Identity). Note that the three conversions are
255 /// specified as separate members (rather than in an array) so that
256 /// we can keep the size of a standard conversion sequence to a
257 /// single word.
259 public:
260 /// First -- The first conversion can be an lvalue-to-rvalue
261 /// conversion, array-to-pointer conversion, or
262 /// function-to-pointer conversion.
264
265 /// Second - The second conversion can be an integral promotion,
266 /// floating point promotion, integral conversion, floating point
267 /// conversion, floating-integral conversion, pointer conversion,
268 /// pointer-to-member conversion, or boolean conversion.
270
271 /// Third - The third conversion can be a qualification conversion
272 /// or a function conversion.
274
275 /// Whether this is the deprecated conversion of a
276 /// string literal to a pointer to non-const character data
277 /// (C++ 4.2p2).
279
280 /// Whether the qualification conversion involves a change in the
281 /// Objective-C lifetime (for automatic reference counting).
283
284 /// IncompatibleObjC - Whether this is an Objective-C conversion
285 /// that we should warn about (if we actually use it).
286 unsigned IncompatibleObjC : 1;
287
288 /// ReferenceBinding - True when this is a reference binding
289 /// (C++ [over.ics.ref]).
290 unsigned ReferenceBinding : 1;
291
292 /// DirectBinding - True when this is a reference binding that is a
293 /// direct binding (C++ [dcl.init.ref]).
294 unsigned DirectBinding : 1;
295
296 /// Whether this is an lvalue reference binding (otherwise, it's
297 /// an rvalue reference binding).
298 unsigned IsLvalueReference : 1;
299
300 /// Whether we're binding to a function lvalue.
302
303 /// Whether we're binding to an rvalue.
304 unsigned BindsToRvalue : 1;
305
306 /// Whether this binds an implicit object argument to a
307 /// non-static member function without a ref-qualifier.
309
310 /// Whether this binds a reference to an object with a different
311 /// Objective-C lifetime qualifier.
313
314 /// FromType - The type that this conversion is converting
315 /// from. This is an opaque pointer that can be translated into a
316 /// QualType.
318
319 /// ToType - The types that this conversion is converting to in
320 /// each step. This is an opaque pointer that can be translated
321 /// into a QualType.
322 void *ToTypePtrs[3];
323
324 /// CopyConstructor - The copy constructor that is used to perform
325 /// this conversion, when the conversion is actually just the
326 /// initialization of an object via copy constructor. Such
327 /// conversions are either identity conversions or derived-to-base
328 /// conversions.
331
333
334 void setToType(unsigned Idx, QualType T) {
335 assert(Idx < 3 && "To type index is out of range");
336 ToTypePtrs[Idx] = T.getAsOpaquePtr();
337 }
338
340 ToTypePtrs[0] = T.getAsOpaquePtr();
341 ToTypePtrs[1] = ToTypePtrs[0];
342 ToTypePtrs[2] = ToTypePtrs[0];
343 }
344
347 }
348
349 QualType getToType(unsigned Idx) const {
350 assert(Idx < 3 && "To type index is out of range");
352 }
353
355
356 bool isIdentityConversion() const {
357 return Second == ICK_Identity && Third == ICK_Identity;
358 }
359
362 getNarrowingKind(ASTContext &Context, const Expr *Converted,
363 APValue &ConstantValue, QualType &ConstantType,
364 bool IgnoreFloatToIntegralConversion = false) const;
365 bool isPointerConversionToBool() const;
366 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
367 void dump() const;
368 };
369
370 /// UserDefinedConversionSequence - Represents a user-defined
371 /// conversion sequence (C++ 13.3.3.1.2).
373 /// Represents the standard conversion that occurs before
374 /// the actual user-defined conversion.
375 ///
376 /// C++11 13.3.3.1.2p1:
377 /// If the user-defined conversion is specified by a constructor
378 /// (12.3.1), the initial standard conversion sequence converts
379 /// the source type to the type required by the argument of the
380 /// constructor. If the user-defined conversion is specified by
381 /// a conversion function (12.3.2), the initial standard
382 /// conversion sequence converts the source type to the implicit
383 /// object parameter of the conversion function.
385
386 /// EllipsisConversion - When this is true, it means user-defined
387 /// conversion sequence starts with a ... (ellipsis) conversion, instead of
388 /// a standard conversion. In this case, 'Before' field must be ignored.
389 // FIXME. I much rather put this as the first field. But there seems to be
390 // a gcc code gen. bug which causes a crash in a test. Putting it here seems
391 // to work around the crash.
393
394 /// HadMultipleCandidates - When this is true, it means that the
395 /// conversion function was resolved from an overloaded set having
396 /// size greater than 1.
398
399 /// After - Represents the standard conversion that occurs after
400 /// the actual user-defined conversion.
402
403 /// ConversionFunction - The function that will perform the
404 /// user-defined conversion. Null if the conversion is an
405 /// aggregate initialization from an initializer list.
407
408 /// The declaration that we found via name lookup, which might be
409 /// the same as \c ConversionFunction or it might be a using declaration
410 /// that refers to \c ConversionFunction.
412
413 void dump() const;
414 };
415
416 /// Represents an ambiguous user-defined conversion sequence.
420
423 char Buffer[sizeof(ConversionSet)];
424
427 }
428
431 }
432
435
437 return *reinterpret_cast<ConversionSet*>(Buffer);
438 }
439
440 const ConversionSet &conversions() const {
441 return *reinterpret_cast<const ConversionSet*>(Buffer);
442 }
443
445 conversions().push_back(std::make_pair(Found, D));
446 }
447
448 using iterator = ConversionSet::iterator;
449
450 iterator begin() { return conversions().begin(); }
451 iterator end() { return conversions().end(); }
452
453 using const_iterator = ConversionSet::const_iterator;
454
455 const_iterator begin() const { return conversions().begin(); }
456 const_iterator end() const { return conversions().end(); }
457
458 void construct();
459 void destruct();
461 };
462
463 /// BadConversionSequence - Records information about an invalid
464 /// conversion sequence.
474 };
475
476 // This can be null, e.g. for implicit object arguments.
478
480
481 private:
482 // The type we're converting from (an opaque QualType).
483 void *FromTy;
484
485 // The type we're converting to (an opaque QualType).
486 void *ToTy;
487
488 public:
489 void init(FailureKind K, Expr *From, QualType To) {
490 init(K, From->getType(), To);
491 FromExpr = From;
492 }
493
494 void init(FailureKind K, QualType From, QualType To) {
495 Kind = K;
496 FromExpr = nullptr;
497 setFromType(From);
498 setToType(To);
499 }
500
503
504 void setFromExpr(Expr *E) {
505 FromExpr = E;
506 setFromType(E->getType());
507 }
508
509 void setFromType(QualType T) { FromTy = T.getAsOpaquePtr(); }
510 void setToType(QualType T) { ToTy = T.getAsOpaquePtr(); }
511 };
512
513 /// ImplicitConversionSequence - Represents an implicit conversion
514 /// sequence, which may be a standard conversion sequence
515 /// (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2),
516 /// or an ellipsis conversion sequence (C++ 13.3.3.1.3).
518 public:
519 /// Kind - The kind of implicit conversion sequence. BadConversion
520 /// specifies that there is no conversion from the source type to
521 /// the target type. AmbiguousConversion represents the unique
522 /// ambiguous conversion (C++0x [over.best.ics]p10).
523 /// StaticObjectArgumentConversion represents the conversion rules for
524 /// the synthesized first argument of calls to static member functions
525 /// ([over.best.ics.general]p8).
526 enum Kind {
533 };
534
535 private:
536 enum {
537 Uninitialized = BadConversion + 1
538 };
539
540 /// ConversionKind - The kind of implicit conversion sequence.
541 unsigned ConversionKind : 31;
542
543 // Whether the initializer list was of an incomplete array.
544 unsigned InitializerListOfIncompleteArray : 1;
545
546 /// When initializing an array or std::initializer_list from an
547 /// initializer-list, this is the array or std::initializer_list type being
548 /// initialized. The remainder of the conversion sequence, including ToType,
549 /// describe the worst conversion of an initializer to an element of the
550 /// array or std::initializer_list. (Note, 'worst' is not well defined.)
551 QualType InitializerListContainerType;
552
553 void setKind(Kind K) {
554 destruct();
555 ConversionKind = K;
556 }
557
558 void destruct() {
559 if (ConversionKind == AmbiguousConversion) Ambiguous.destruct();
560 }
561
562 public:
563 union {
564 /// When ConversionKind == StandardConversion, provides the
565 /// details of the standard conversion sequence.
567
568 /// When ConversionKind == UserDefinedConversion, provides the
569 /// details of the user-defined conversion sequence.
571
572 /// When ConversionKind == AmbiguousConversion, provides the
573 /// details of the ambiguous conversion.
575
576 /// When ConversionKind == BadConversion, provides the details
577 /// of the bad conversion.
579 };
580
582 : ConversionKind(Uninitialized),
583 InitializerListOfIncompleteArray(false) {
585 }
586
588 : ConversionKind(Other.ConversionKind),
589 InitializerListOfIncompleteArray(
590 Other.InitializerListOfIncompleteArray),
591 InitializerListContainerType(Other.InitializerListContainerType) {
592 switch (ConversionKind) {
593 case Uninitialized: break;
594 case StandardConversion: Standard = Other.Standard; break;
596 break;
597 case UserDefinedConversion: UserDefined = Other.UserDefined; break;
598 case AmbiguousConversion: Ambiguous.copyFrom(Other.Ambiguous); break;
599 case EllipsisConversion: break;
600 case BadConversion: Bad = Other.Bad; break;
601 }
602 }
603
606 destruct();
607 new (this) ImplicitConversionSequence(Other);
608 return *this;
609 }
610
612 destruct();
613 }
614
615 Kind getKind() const {
616 assert(isInitialized() && "querying uninitialized conversion");
617 return Kind(ConversionKind);
618 }
619
620 /// Return a ranking of the implicit conversion sequence
621 /// kind, where smaller ranks represent better conversion
622 /// sequences.
623 ///
624 /// In particular, this routine gives user-defined conversion
625 /// sequences and ambiguous conversion sequences the same rank,
626 /// per C++ [over.best.ics]p10.
627 unsigned getKindRank() const {
628 switch (getKind()) {
631 return 0;
632
635 return 1;
636
638 return 2;
639
640 case BadConversion:
641 return 3;
642 }
643
644 llvm_unreachable("Invalid ImplicitConversionSequence::Kind!");
645 }
646
647 bool isBad() const { return getKind() == BadConversion; }
648 bool isStandard() const { return getKind() == StandardConversion; }
651 }
652 bool isEllipsis() const { return getKind() == EllipsisConversion; }
653 bool isAmbiguous() const { return getKind() == AmbiguousConversion; }
654 bool isUserDefined() const { return getKind() == UserDefinedConversion; }
655 bool isFailure() const { return isBad() || isAmbiguous(); }
656
657 /// Determines whether this conversion sequence has been
658 /// initialized. Most operations should never need to query
659 /// uninitialized conversions and should assert as above.
660 bool isInitialized() const { return ConversionKind != Uninitialized; }
661
662 /// Sets this sequence as a bad conversion for an explicit argument.
664 Expr *FromExpr, QualType ToType) {
665 setKind(BadConversion);
666 Bad.init(Failure, FromExpr, ToType);
667 }
668
669 /// Sets this sequence as a bad conversion for an implicit argument.
671 QualType FromType, QualType ToType) {
672 setKind(BadConversion);
673 Bad.init(Failure, FromType, ToType);
674 }
675
676 void setStandard() { setKind(StandardConversion); }
678 void setEllipsis() { setKind(EllipsisConversion); }
680
682 if (ConversionKind == AmbiguousConversion) return;
683 ConversionKind = AmbiguousConversion;
685 }
686
688 setStandard();
692 }
693
694 // True iff this is a conversion sequence from an initializer list to an
695 // array or std::initializer.
697 return !InitializerListContainerType.isNull();
698 }
700 InitializerListContainerType = T;
701 InitializerListOfIncompleteArray = IA;
702 }
704 return InitializerListOfIncompleteArray;
705 }
708 "not initializer list container");
709 return InitializerListContainerType;
710 }
711
712 /// Form an "implicit" conversion sequence from nullptr_t to bool, for a
713 /// direct-initialization of a bool object from nullptr_t.
715 QualType DestType,
716 bool NeedLValToRVal) {
718 ICS.setStandard();
720 ICS.Standard.setFromType(SourceType);
721 if (NeedLValToRVal)
723 ICS.Standard.setToType(0, SourceType);
725 ICS.Standard.setToType(1, DestType);
726 ICS.Standard.setToType(2, DestType);
727 return ICS;
728 }
729
730 // The result of a comparison between implicit conversion
731 // sequences. Use Sema::CompareImplicitConversionSequences to
732 // actually perform the comparison.
734 Better = -1,
736 Worse = 1
737 };
738
740 SourceLocation CaretLoc,
741 const PartialDiagnostic &PDiag) const;
742
743 void dump() const;
744 };
745
751
752 /// This conversion candidate was not considered because it
753 /// duplicates the work of a trivial or derived-to-base
754 /// conversion.
756
757 /// This conversion candidate was not considered because it is
758 /// an illegal instantiation of a constructor temploid: it is
759 /// callable with one argument, we only have one argument, and
760 /// its first parameter type is exactly the type of the class.
761 ///
762 /// Defining such a constructor directly is illegal, and
763 /// template-argument deduction is supposed to ignore such
764 /// instantiations, but we can still get one with the right
765 /// kind of implicit instantiation.
767
768 /// This conversion candidate is not viable because its result
769 /// type is not implicitly convertible to the desired type.
771
772 /// This conversion function template specialization candidate is not
773 /// viable because the final conversion was not an exact match.
775
776 /// (CUDA) This candidate was not viable because the callee
777 /// was not accessible from the caller's target (i.e. host->device,
778 /// global->host, device->host).
780
781 /// This candidate function was not viable because an enable_if
782 /// attribute disabled it.
784
785 /// This candidate constructor or conversion function is explicit but
786 /// the context doesn't permit explicit functions.
788
789 /// This candidate was not viable because its address could not be taken.
791
792 /// This inherited constructor is not viable because it would slice the
793 /// argument.
795
796 /// This candidate was not viable because it is a non-default multiversioned
797 /// function.
799
800 /// This constructor/conversion candidate fail due to an address space
801 /// mismatch between the object being constructed and the overload
802 /// candidate.
804
805 /// This candidate was not viable because its associated constraints were
806 /// not satisfied.
808
809 /// This candidate was not viable because it has internal linkage and is
810 /// from a different module unit than the use.
812 };
813
814 /// A list of implicit conversion sequences for the arguments of an
815 /// OverloadCandidate.
818
819 /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
821 /// Function - The actual function that this candidate
822 /// represents. When NULL, this is a built-in candidate
823 /// (C++ [over.oper]) or a surrogate for a conversion to a
824 /// function pointer or reference (C++ [over.call.object]).
826
827 /// FoundDecl - The original declaration that was looked up /
828 /// invented / otherwise found, together with its access.
829 /// Might be a UsingShadowDecl or a FunctionTemplateDecl.
831
832 /// BuiltinParamTypes - Provides the parameter types of a built-in overload
833 /// candidate. Only valid when Function is NULL.
835
836 /// Surrogate - The conversion function for which this candidate
837 /// is a surrogate, but only if IsSurrogate is true.
839
840 /// The conversion sequences used to convert the function arguments
841 /// to the function parameters. Note that these are indexed by argument,
842 /// so may not match the parameter order of Function.
844
845 /// The FixIt hints which can be used to fix the Bad candidate.
847
848 /// Viable - True to indicate that this overload candidate is viable.
849 bool Viable : 1;
850
851 /// Whether this candidate is the best viable function, or tied for being
852 /// the best viable function.
853 ///
854 /// For an ambiguous overload resolution, indicates whether this candidate
855 /// was part of the ambiguity kernel: the minimal non-empty set of viable
856 /// candidates such that all elements of the ambiguity kernel are better
857 /// than all viable candidates not in the ambiguity kernel.
858 bool Best : 1;
859
860 /// IsSurrogate - True to indicate that this candidate is a
861 /// surrogate for a conversion to a function pointer or reference
862 /// (C++ [over.call.object]).
863 bool IsSurrogate : 1;
864
865 /// IgnoreObjectArgument - True to indicate that the first
866 /// argument's conversion, which for this function represents the
867 /// implicit object argument, should be ignored. This will be true
868 /// when the candidate is a static member function (where the
869 /// implicit object argument is just a placeholder) or a
870 /// non-static member function when the call doesn't have an
871 /// object argument.
873
874 /// True if the candidate was found using ADL.
876
877 /// Whether this is a rewritten candidate, and if so, of what kind?
878 unsigned RewriteKind : 2;
879
880 /// FailureKind - The reason why this candidate is not viable.
881 /// Actually an OverloadFailureKind.
882 unsigned char FailureKind;
883
884 /// The number of call arguments that were explicitly provided,
885 /// to be used while performing partial ordering of function templates.
887
888 union {
890
891 /// FinalConversion - For a conversion function (where Function is
892 /// a CXXConversionDecl), the standard conversion that occurs
893 /// after the call to the overload candidate to convert the result
894 /// of calling the conversion function to the required type.
896 };
897
898 /// Get RewriteKind value in OverloadCandidateRewriteKind type (This
899 /// function is to workaround the spurious GCC bitfield enum warning)
901 return static_cast<OverloadCandidateRewriteKind>(RewriteKind);
902 }
903
904 bool isReversed() const { return getRewriteKind() & CRK_Reversed; }
905
906 /// hasAmbiguousConversion - Returns whether this overload
907 /// candidate requires an ambiguous conversion or not.
909 for (auto &C : Conversions) {
910 if (!C.isInitialized()) return false;
911 if (C.isAmbiguous()) return true;
912 }
913 return false;
914 }
915
916 bool TryToFixBadConversion(unsigned Idx, Sema &S) {
917 bool CanFix = Fix.tryToFixConversion(
918 Conversions[Idx].Bad.FromExpr,
919 Conversions[Idx].Bad.getFromType(),
920 Conversions[Idx].Bad.getToType(), S);
921
922 // If at least one conversion fails, the candidate cannot be fixed.
923 if (!CanFix)
924 Fix.clear();
925
926 return CanFix;
927 }
928
929 unsigned getNumParams() const {
930 if (IsSurrogate) {
932 while (STy->isPointerType() || STy->isReferenceType())
933 STy = STy->getPointeeType();
934 return STy->castAs<FunctionProtoType>()->getNumParams();
935 }
936 if (Function)
937 return Function->getNumParams();
939 }
940
942
943 private:
947 };
948
949 /// OverloadCandidateSet - A set of overload candidates, used in C++
950 /// overload resolution (C++ 13.3).
952 public:
954 /// Normal lookup.
956
957 /// C++ [over.match.oper]:
958 /// Lookup of operator function candidates in a call using operator
959 /// syntax. Candidates that have no parameters of class type will be
960 /// skipped unless there is a parameter of (reference to) enum type and
961 /// the corresponding argument is of the same enum type.
963
964 /// C++ [over.match.copy]:
965 /// Copy-initialization of an object of class type by user-defined
966 /// conversion.
968
969 /// C++ [over.match.ctor], [over.match.list]
970 /// Initialization of an object of class type by constructor,
971 /// using either a parenthesized or braced list of arguments.
973 };
974
975 /// Information about operator rewrites to consider when adding operator
976 /// functions to a candidate set.
981 bool AllowRewritten)
983 AllowRewrittenCandidates(AllowRewritten) {}
984
985 /// The original operator as written in the source.
987 /// The source location of the operator.
989 /// Whether we should include rewritten candidates in the overload set.
991
992 /// Would use of this function result in a rewrite using a different
993 /// operator?
995 return OriginalOperator &&
997 }
998
1000 if (!OriginalOperator)
1001 return true;
1002
1003 // For an overloaded operator, we can have candidates with a different
1004 // name in our unqualified lookup set. Make sure we only consider the
1005 // ones we're supposed to.
1008 return OO && (OO == OriginalOperator ||
1011 }
1012
1013 /// Determine the kind of rewrite that should be performed for this
1014 /// candidate.
1018 if (isRewrittenOperator(FD))
1022 return CRK;
1023 }
1024 /// Determines whether this operator could be implemented by a function
1025 /// with reversed parameter order.
1030 }
1031
1032 /// Determine whether reversing parameter order is allowed for operator
1033 /// Op.
1035
1036 /// Determine whether we should add a rewritten candidate for \p FD with
1037 /// reversed parameter order.
1038 /// \param OriginalArgs are the original non reversed arguments.
1039 bool shouldAddReversed(Sema &S, ArrayRef<Expr *> OriginalArgs,
1040 FunctionDecl *FD);
1041 };
1042
1043 private:
1046
1047 // Allocator for ConversionSequenceLists. We store the first few of these
1048 // inline to avoid allocation for small sets.
1049 llvm::BumpPtrAllocator SlabAllocator;
1050
1051 SourceLocation Loc;
1052 CandidateSetKind Kind;
1053 OperatorRewriteInfo RewriteInfo;
1054
1055 constexpr static unsigned NumInlineBytes =
1056 24 * sizeof(ImplicitConversionSequence);
1057 unsigned NumInlineBytesUsed = 0;
1058 alignas(void *) char InlineSpace[NumInlineBytes];
1059
1060 // Address space of the object being constructed.
1061 LangAS DestAS = LangAS::Default;
1062
1063 /// If we have space, allocates from inline storage. Otherwise, allocates
1064 /// from the slab allocator.
1065 /// FIXME: It would probably be nice to have a SmallBumpPtrAllocator
1066 /// instead.
1067 /// FIXME: Now that this only allocates ImplicitConversionSequences, do we
1068 /// want to un-generalize this?
1069 template <typename T>
1070 T *slabAllocate(unsigned N) {
1071 // It's simpler if this doesn't need to consider alignment.
1072 static_assert(alignof(T) == alignof(void *),
1073 "Only works for pointer-aligned types.");
1074 static_assert(std::is_trivial<T>::value ||
1075 std::is_same<ImplicitConversionSequence, T>::value,
1076 "Add destruction logic to OverloadCandidateSet::clear().");
1077
1078 unsigned NBytes = sizeof(T) * N;
1079 if (NBytes > NumInlineBytes - NumInlineBytesUsed)
1080 return SlabAllocator.Allocate<T>(N);
1081 char *FreeSpaceStart = InlineSpace + NumInlineBytesUsed;
1082 assert(uintptr_t(FreeSpaceStart) % alignof(void *) == 0 &&
1083 "Misaligned storage!");
1084
1085 NumInlineBytesUsed += NBytes;
1086 return reinterpret_cast<T *>(FreeSpaceStart);
1087 }
1088
1089 void destroyCandidates();
1090
1091 public:
1093 OperatorRewriteInfo RewriteInfo = {})
1094 : Loc(Loc), Kind(CSK), RewriteInfo(RewriteInfo) {}
1097 ~OverloadCandidateSet() { destroyCandidates(); }
1098
1099 SourceLocation getLocation() const { return Loc; }
1100 CandidateSetKind getKind() const { return Kind; }
1101 OperatorRewriteInfo getRewriteInfo() const { return RewriteInfo; }
1102
1103 /// Whether diagnostics should be deferred.
1105
1106 /// Determine when this overload candidate will be new to the
1107 /// overload set.
1110 uintptr_t Key = reinterpret_cast<uintptr_t>(F->getCanonicalDecl());
1111 Key |= static_cast<uintptr_t>(PO);
1112 return Functions.insert(Key).second;
1113 }
1114
1115 /// Exclude a function from being considered by overload resolution.
1116 void exclude(Decl *F) {
1119 }
1120
1121 /// Clear out all of the candidates.
1122 void clear(CandidateSetKind CSK);
1123
1125
1126 iterator begin() { return Candidates.begin(); }
1127 iterator end() { return Candidates.end(); }
1128
1129 size_t size() const { return Candidates.size(); }
1130 bool empty() const { return Candidates.empty(); }
1131
1132 /// Allocate storage for conversion sequences for NumConversions
1133 /// conversions.
1135 allocateConversionSequences(unsigned NumConversions) {
1136 ImplicitConversionSequence *Conversions =
1137 slabAllocate<ImplicitConversionSequence>(NumConversions);
1138
1139 // Construct the new objects.
1140 for (unsigned I = 0; I != NumConversions; ++I)
1141 new (&Conversions[I]) ImplicitConversionSequence();
1142
1143 return ConversionSequenceList(Conversions, NumConversions);
1144 }
1145
1146 /// Add a new candidate with NumConversions conversion sequence slots
1147 /// to the overload set.
1149 addCandidate(unsigned NumConversions = 0,
1150 ConversionSequenceList Conversions = std::nullopt) {
1151 assert((Conversions.empty() || Conversions.size() == NumConversions) &&
1152 "preallocated conversion sequence has wrong length");
1153
1154 Candidates.push_back(OverloadCandidate());
1155 OverloadCandidate &C = Candidates.back();
1156 C.Conversions = Conversions.empty()
1157 ? allocateConversionSequences(NumConversions)
1158 : Conversions;
1159 return C;
1160 }
1161
1162 /// Find the best viable function on this overload set, if it exists.
1165
1169 llvm::function_ref<bool(OverloadCandidate &)> Filter =
1170 [](OverloadCandidate &) { return true; });
1171
1172 void NoteCandidates(
1174 ArrayRef<Expr *> Args, StringRef Opc = "",
1175 SourceLocation Loc = SourceLocation(),
1176 llvm::function_ref<bool(OverloadCandidate &)> Filter =
1177 [](OverloadCandidate &) { return true; });
1178
1179 void NoteCandidates(Sema &S, ArrayRef<Expr *> Args,
1180 ArrayRef<OverloadCandidate *> Cands,
1181 StringRef Opc = "",
1182 SourceLocation OpLoc = SourceLocation());
1183
1184 LangAS getDestAS() { return DestAS; }
1185
1187 assert((Kind == CSK_InitByConstructor ||
1189 "can't set the destination address space when not constructing an "
1190 "object");
1191 DestAS = AS;
1192 }
1193
1194 };
1195
1196 bool isBetterOverloadCandidate(Sema &S,
1197 const OverloadCandidate &Cand1,
1198 const OverloadCandidate &Cand2,
1199 SourceLocation Loc,
1201
1206
1207 explicit operator bool() const { return Constructor; }
1208 };
1209
1210 // FIXME: Add an AddOverloadCandidate / AddTemplateOverloadCandidate overload
1211 // that takes one of these.
1213 if (isa<UsingDecl>(ND))
1214 return ConstructorInfo{};
1215
1216 // For constructors, the access check is performed against the underlying
1217 // declaration, not the found declaration.
1218 auto *D = ND->getUnderlyingDecl();
1219 ConstructorInfo Info = {DeclAccessPair::make(ND, D->getAccess()), nullptr,
1220 nullptr};
1221 Info.ConstructorTmpl = dyn_cast<FunctionTemplateDecl>(D);
1222 if (Info.ConstructorTmpl)
1224 Info.Constructor = dyn_cast<CXXConstructorDecl>(D);
1225 return Info;
1226 }
1227
1228 // Returns false if signature help is relevant despite number of arguments
1229 // exceeding parameters. Specifically, it returns false when
1230 // PartialOverloading is true and one of the following:
1231 // * Function is variadic
1232 // * Function is template variadic
1233 // * Function is an instantiation of template variadic function
1234 // The last case may seem strange. The idea is that if we added one more
1235 // argument, we'd end up with a function similar to Function. Since, in the
1236 // context of signature help and/or code completion, we do not know what the
1237 // type of the next argument (that the user is typing) will be, this is as
1238 // good candidate as we can get, despite the fact that it takes one less
1239 // parameter.
1240 bool shouldEnforceArgLimit(bool PartialOverloading, FunctionDecl *Function);
1241
1242} // namespace clang
1243
1244#endif // LLVM_CLANG_SEMA_OVERLOAD_H
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.
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:182
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2470
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2797
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Definition: DeclCXX.h:2837
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2812
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:83
AccessSpecifier getAccess() const
Definition: DeclBase.h:491
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:943
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:1917
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3489
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4041
Declaration of a template function.
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:517
void dump() const
dump - Print this implicit conversion sequence to standard error.
ImplicitConversionSequence & operator=(const ImplicitConversionSequence &Other)
Definition: Overload.h:605
Kind
Kind - The kind of implicit conversion sequence.
Definition: Overload.h:526
StandardConversionSequence Standard
When ConversionKind == StandardConversion, provides the details of the standard conversion sequence.
Definition: Overload.h:566
void setBad(BadConversionSequence::FailureKind Failure, Expr *FromExpr, QualType ToType)
Sets this sequence as a bad conversion for an explicit argument.
Definition: Overload.h:663
UserDefinedConversionSequence UserDefined
When ConversionKind == UserDefinedConversion, provides the details of the user-defined conversion seq...
Definition: Overload.h:570
ImplicitConversionSequence(const ImplicitConversionSequence &Other)
Definition: Overload.h:587
bool isInitialized() const
Determines whether this conversion sequence has been initialized.
Definition: Overload.h:660
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:714
AmbiguousConversionSequence Ambiguous
When ConversionKind == AmbiguousConversion, provides the details of the ambiguous conversion.
Definition: Overload.h:574
void setInitializerListContainerType(QualType T, bool IA)
Definition: Overload.h:699
bool hasInitializerListContainerType() const
Definition: Overload.h:696
unsigned getKindRank() const
Return a ranking of the implicit conversion sequence kind, where smaller ranks represent better conve...
Definition: Overload.h:627
bool isInitializerListOfIncompleteArray() const
Definition: Overload.h:703
BadConversionSequence Bad
When ConversionKind == BadConversion, provides the details of the bad conversion.
Definition: Overload.h:578
QualType getInitializerListContainerType() const
Definition: Overload.h:706
void setAsIdentityConversion(QualType T)
Definition: Overload.h:687
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:670
This represents a decl that may have a name.
Definition: Decl.h:247
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:457
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:313
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
Definition: Overload.h:951
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:1108
void setDestAS(LangAS AS)
Definition: Overload.h:1186
ConversionSequenceList allocateConversionSequences(unsigned NumConversions)
Allocate storage for conversion sequences for NumConversions conversions.
Definition: Overload.h:1135
OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK, OperatorRewriteInfo RewriteInfo={})
Definition: Overload.h:1092
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:1149
OperatorRewriteInfo getRewriteInfo() const
Definition: Overload.h:1101
@ CSK_InitByConstructor
C++ [over.match.ctor], [over.match.list] Initialization of an object of class type by constructor,...
Definition: Overload.h:972
@ CSK_InitByUserDefinedConversion
C++ [over.match.copy]: Copy-initialization of an object of class type by user-defined conversion.
Definition: Overload.h:967
@ CSK_Normal
Normal lookup.
Definition: Overload.h:955
@ CSK_Operator
C++ [over.match.oper]: Lookup of operator function candidates in a call using operator syntax.
Definition: Overload.h:962
SmallVectorImpl< OverloadCandidate >::iterator iterator
Definition: Overload.h:1124
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:1116
SourceLocation getLocation() const
Definition: Overload.h:1099
CandidateSetKind getKind() const
Definition: Overload.h:1100
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:736
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:785
void * getAsOpaquePtr() const
Definition: Type.h:783
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:356
Encodes a location in the source.
StandardConversionSequence - represents a standard conversion sequence (C++ 13.3.3....
Definition: Overload.h:258
void dump() const
dump - Print this standard conversion sequence to standard error.
void setFromType(QualType T)
Definition: Overload.h:332
DeclAccessPair FoundCopyConstructor
Definition: Overload.h:330
void * FromTypePtr
FromType - The type that this conversion is converting from.
Definition: Overload.h:317
unsigned BindsToRvalue
Whether we're binding to an rvalue.
Definition: Overload.h:304
ImplicitConversionKind Second
Second - The second conversion can be an integral promotion, floating point promotion,...
Definition: Overload.h:269
QualType getFromType() const
Definition: Overload.h:345
ImplicitConversionKind First
First – The first conversion can be an lvalue-to-rvalue conversion, array-to-pointer conversion,...
Definition: Overload.h:263
unsigned BindsImplicitObjectArgumentWithoutRefQualifier
Whether this binds an implicit object argument to a non-static member function without a ref-qualifie...
Definition: Overload.h:308
unsigned ReferenceBinding
ReferenceBinding - True when this is a reference binding (C++ [over.ics.ref]).
Definition: Overload.h:290
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:278
CXXConstructorDecl * CopyConstructor
CopyConstructor - The copy constructor that is used to perform this conversion, when the conversion i...
Definition: Overload.h:329
unsigned IncompatibleObjC
IncompatibleObjC - Whether this is an Objective-C conversion that we should warn about (if we actuall...
Definition: Overload.h:286
unsigned ObjCLifetimeConversionBinding
Whether this binds a reference to an object with a different Objective-C lifetime qualifier.
Definition: Overload.h:312
ImplicitConversionKind Third
Third - The third conversion can be a qualification conversion or a function conversion.
Definition: Overload.h:273
unsigned QualificationIncludesObjCLifetime
Whether the qualification conversion involves a change in the Objective-C lifetime (for automatic ref...
Definition: Overload.h:282
void setToType(unsigned Idx, QualType T)
Definition: Overload.h:334
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:322
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:298
unsigned BindsToFunctionLvalue
Whether we're binding to a function lvalue.
Definition: Overload.h:301
unsigned DirectBinding
DirectBinding - True when this is a reference binding that is a direct binding (C++ [dcl....
Definition: Overload.h:294
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:339
QualType getToType(unsigned Idx) const
Definition: Overload.h:349
bool isPointerType() const
Definition: Type.h:6910
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7491
bool isReferenceType() const
Definition: Type.h:6922
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:629
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:817
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:746
@ ovl_fail_final_conversion_not_exact
This conversion function template specialization candidate is not viable because the final conversion...
Definition: Overload.h:774
@ ovl_fail_enable_if
This candidate function was not viable because an enable_if attribute disabled it.
Definition: Overload.h:783
@ ovl_fail_illegal_constructor
This conversion candidate was not considered because it is an illegal instantiation of a constructor ...
Definition: Overload.h:766
@ ovl_fail_bad_final_conversion
This conversion candidate is not viable because its result type is not implicitly convertible to the ...
Definition: Overload.h:770
@ 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:811
@ ovl_fail_too_few_arguments
Definition: Overload.h:748
@ ovl_fail_addr_not_available
This candidate was not viable because its address could not be taken.
Definition: Overload.h:790
@ ovl_fail_too_many_arguments
Definition: Overload.h:747
@ ovl_non_default_multiversion_function
This candidate was not viable because it is a non-default multiversioned function.
Definition: Overload.h:798
@ ovl_fail_constraints_not_satisfied
This candidate was not viable because its associated constraints were not satisfied.
Definition: Overload.h:807
@ ovl_fail_bad_conversion
Definition: Overload.h:749
@ ovl_fail_bad_target
(CUDA) This candidate was not viable because the callee was not accessible from the caller's target (...
Definition: Overload.h:779
@ ovl_fail_bad_deduction
Definition: Overload.h:750
@ ovl_fail_inhctor_slice
This inherited constructor is not viable because it would slice the argument.
Definition: Overload.h:794
@ ovl_fail_object_addrspace_mismatch
This constructor/conversion candidate fail due to an address space mismatch between the object being ...
Definition: Overload.h:803
@ ovl_fail_explicit
This candidate constructor or conversion function is explicit but the context doesn't permit explicit...
Definition: Overload.h:787
@ ovl_fail_trivial_conversion
This conversion candidate was not considered because it duplicates the work of a trivial or derived-t...
Definition: Overload.h:755
ImplicitConversionRank
ImplicitConversionRank - The rank of an implicit conversion kind.
Definition: Overload.h:200
@ ICR_Conversion
Conversion.
Definition: Overload.h:208
@ ICR_Writeback_Conversion
ObjC ARC writeback conversion.
Definition: Overload.h:217
@ ICR_C_Conversion
Conversion only allowed in the C standard (e.g. void* to char*).
Definition: Overload.h:220
@ ICR_OCL_Scalar_Widening
OpenCL Scalar Widening.
Definition: Overload.h:211
@ ICR_Complex_Real_Conversion
Complex <-> Real conversion.
Definition: Overload.h:214
@ ICR_Promotion
Promotion.
Definition: Overload.h:205
@ ICR_Exact_Match
Exact Match.
Definition: Overload.h:202
@ ICR_C_Conversion_Extension
Conversion not allowed by the C standard, but that we accept as an extension anyway.
Definition: Overload.h:224
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
@ C
Languages that the frontend can parse and compile.
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_Vector_Conversion
Vector conversions.
Definition: Overload.h:160
@ ICK_Block_Pointer_Conversion
Block Pointer conversions.
Definition: Overload.h:172
@ 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_SVE_Vector_Conversion
Arm SVE Vector conversions.
Definition: Overload.h:163
@ ICK_Incompatible_Pointer_Conversion
C-only conversion between pointers with incompatible types.
Definition: Overload.h:190
@ ICK_Array_To_Pointer
Array-to-pointer conversion (C++ [conv.array])
Definition: Overload.h:112
@ ICK_Complex_Promotion
Complex promotions (Clang extension)
Definition: Overload.h:130
@ ICK_Num_Conversion_Kinds
The number of conversion kinds.
Definition: Overload.h:193
@ 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:166
@ ICK_Zero_Queue_Conversion
Zero constant to queue.
Definition: Overload.h:184
@ 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:175
@ 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:187
@ ICK_Writeback_Conversion
Objective-C ARC writeback conversion.
Definition: Overload.h:178
@ ICK_Zero_Event_Conversion
Zero constant to event (OpenCL1.2 6.12.10)
Definition: Overload.h:181
@ ICK_Complex_Real
Complex-real conversions (C99 6.3.1.7)
Definition: Overload.h:169
@ 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...
bool shouldEnforceArgLimit(bool PartialOverloading, FunctionDecl *Function)
NarrowingKind
NarrowingKind - The kind of narrowing conversion being performed by a standard conversion sequence ac...
Definition: Overload.h:231
@ NK_Not_Narrowing
Not a narrowing conversion.
Definition: Overload.h:233
@ NK_Constant_Narrowing
A narrowing conversion, because a constant expression got narrowed.
Definition: Overload.h:239
@ NK_Dependent_Narrowing
Cannot tell whether this is a narrowing conversion because the expression is value-dependent.
Definition: Overload.h:247
@ NK_Type_Narrowing
A narrowing conversion by virtue of the source and destination types.
Definition: Overload.h:236
@ NK_Variable_Narrowing
A narrowing conversion, because a non-constant-expression variable might have got narrowed.
Definition: Overload.h:243
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
ConstructorInfo getConstructorInfo(NamedDecl *ND)
Definition: Overload.h:1212
ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind)
GetConversionRank - Retrieve the implicit conversion rank corresponding to the given implicit convers...
__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:22
#define bool
Definition: stdbool.h:20
Represents an ambiguous user-defined conversion sequence.
Definition: Overload.h:417
ConversionSet::const_iterator const_iterator
Definition: Overload.h:453
const ConversionSet & conversions() const
Definition: Overload.h:440
ConversionSet & conversions()
Definition: Overload.h:436
const_iterator end() const
Definition: Overload.h:456
void addConversion(NamedDecl *Found, FunctionDecl *D)
Definition: Overload.h:444
SmallVector< std::pair< NamedDecl *, FunctionDecl * >, 4 > ConversionSet
Definition: Overload.h:419
char Buffer[sizeof(ConversionSet)]
Definition: Overload.h:423
void copyFrom(const AmbiguousConversionSequence &)
ConversionSet::iterator iterator
Definition: Overload.h:448
const_iterator begin() const
Definition: Overload.h:455
BadConversionSequence - Records information about an invalid conversion sequence.
Definition: Overload.h:465
void setToType(QualType T)
Definition: Overload.h:510
void setFromType(QualType T)
Definition: Overload.h:509
void init(FailureKind K, Expr *From, QualType To)
Definition: Overload.h:489
void init(FailureKind K, QualType From, QualType To)
Definition: Overload.h:494
QualType getToType() const
Definition: Overload.h:502
void setFromExpr(Expr *E)
Definition: Overload.h:504
QualType getFromType() const
Definition: Overload.h:501
FunctionTemplateDecl * ConstructorTmpl
Definition: Overload.h:1205
CXXConstructorDecl * Constructor
Definition: Overload.h:1204
DeclAccessPair FoundDecl
Definition: Overload.h:1203
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:977
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:980
bool isRewrittenOperator(const FunctionDecl *FD)
Would use of this function result in a rewrite using a different operator?
Definition: Overload.h:994
SourceLocation OpLoc
The source location of the operator.
Definition: Overload.h:988
bool AllowRewrittenCandidates
Whether we should include rewritten candidates in the overload set.
Definition: Overload.h:990
bool isReversible()
Determines whether this operator could be implemented by a function with reversed parameter order.
Definition: Overload.h:1026
OverloadedOperatorKind OriginalOperator
The original operator as written in the source.
Definition: Overload.h:986
bool isAcceptableCandidate(const FunctionDecl *FD)
Definition: Overload.h:999
OverloadCandidateRewriteKind getRewriteKind(const FunctionDecl *FD, OverloadCandidateParamOrder PO)
Determine the kind of rewrite that should be performed for this candidate.
Definition: Overload.h:1016
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
Definition: Overload.h:820
CallExpr::ADLCallKind IsADLCandidate
True if the candidate was found using ADL.
Definition: Overload.h:875
bool TryToFixBadConversion(unsigned Idx, Sema &S)
Definition: Overload.h:916
bool NotValidBecauseConstraintExprHasError() const
bool isReversed() const
Definition: Overload.h:904
bool IsSurrogate
IsSurrogate - True to indicate that this candidate is a surrogate for a conversion to a function poin...
Definition: Overload.h:863
QualType BuiltinParamTypes[3]
BuiltinParamTypes - Provides the parameter types of a built-in overload candidate.
Definition: Overload.h:834
bool hasAmbiguousConversion() const
hasAmbiguousConversion - Returns whether this overload candidate requires an ambiguous conversion or ...
Definition: Overload.h:908
bool IgnoreObjectArgument
IgnoreObjectArgument - True to indicate that the first argument's conversion, which for this function...
Definition: Overload.h:872
DeclAccessPair FoundDecl
FoundDecl - The original declaration that was looked up / invented / otherwise found,...
Definition: Overload.h:830
FunctionDecl * Function
Function - The actual function that this candidate represents.
Definition: Overload.h:825
bool Viable
Viable - True to indicate that this overload candidate is viable.
Definition: Overload.h:849
unsigned RewriteKind
Whether this is a rewritten candidate, and if so, of what kind?
Definition: Overload.h:878
ConversionFixItGenerator Fix
The FixIt hints which can be used to fix the Bad candidate.
Definition: Overload.h:846
StandardConversionSequence FinalConversion
FinalConversion - For a conversion function (where Function is a CXXConversionDecl),...
Definition: Overload.h:895
unsigned getNumParams() const
Definition: Overload.h:929
unsigned ExplicitCallArguments
The number of call arguments that were explicitly provided, to be used while performing partial order...
Definition: Overload.h:886
unsigned char FailureKind
FailureKind - The reason why this candidate is not viable.
Definition: Overload.h:882
ConversionSequenceList Conversions
The conversion sequences used to convert the function arguments to the function parameters.
Definition: Overload.h:843
DeductionFailureInfo DeductionFailure
Definition: Overload.h:889
bool Best
Whether this candidate is the best viable function, or tied for being the best viable function.
Definition: Overload.h:858
CXXConversionDecl * Surrogate
Surrogate - The conversion function for which this candidate is a surrogate, but only if IsSurrogate ...
Definition: Overload.h:838
OverloadCandidateRewriteKind getRewriteKind() const
Get RewriteKind value in OverloadCandidateRewriteKind type (This function is to workaround the spurio...
Definition: Overload.h:900
UserDefinedConversionSequence - Represents a user-defined conversion sequence (C++ 13....
Definition: Overload.h:372
StandardConversionSequence Before
Represents the standard conversion that occurs before the actual user-defined conversion.
Definition: Overload.h:384
FunctionDecl * ConversionFunction
ConversionFunction - The function that will perform the user-defined conversion.
Definition: Overload.h:406
bool HadMultipleCandidates
HadMultipleCandidates - When this is true, it means that the conversion function was resolved from an...
Definition: Overload.h:397
StandardConversionSequence After
After - Represents the standard conversion that occurs after the actual user-defined conversion.
Definition: Overload.h:401
bool EllipsisConversion
EllipsisConversion - When this is true, it means user-defined conversion sequence starts with a ....
Definition: Overload.h:392
DeclAccessPair FoundConversionFunction
The declaration that we found via name lookup, which might be the same as ConversionFunction or it mi...
Definition: Overload.h:411
void dump() const
dump - Print this user-defined conversion sequence to standard error.