15 #ifndef LLVM_CLANG_SEMA_OVERLOAD_H 16 #define LLVM_CLANG_SEMA_OVERLOAD_H 29 #include "llvm/ADT/ArrayRef.h" 30 #include "llvm/ADT/None.h" 31 #include "llvm/ADT/STLExtras.h" 32 #include "llvm/ADT/SmallPtrSet.h" 33 #include "llvm/ADT/SmallVector.h" 34 #include "llvm/ADT/StringRef.h" 35 #include "llvm/Support/AlignOf.h" 36 #include "llvm/Support/Allocator.h" 37 #include "llvm/Support/Casting.h" 38 #include "llvm/Support/ErrorHandling.h" 307 assert(Idx < 3 &&
"To type index is out of range");
313 ToTypePtrs[1] = ToTypePtrs[0];
314 ToTypePtrs[2] = ToTypePtrs[0];
322 assert(Idx < 3 &&
"To type index is out of range");
336 bool IgnoreFloatToIntegralConversion =
false)
const;
417 conversions().push_back(std::make_pair(Found, D));
494 StandardConversion = 0,
507 unsigned ConversionKind : 30;
511 unsigned StdInitializerListElement : 1;
513 void setKind(
Kind K) {
519 if (ConversionKind == AmbiguousConversion) Ambiguous.destruct();
543 Standard.setAsIdentityConversion();
547 : ConversionKind(Other.ConversionKind),
548 StdInitializerListElement(Other.StdInitializerListElement) {
549 switch (ConversionKind) {
551 case StandardConversion: Standard = Other.
Standard;
break;
552 case UserDefinedConversion: UserDefined = Other.
UserDefined;
break;
553 case AmbiguousConversion: Ambiguous.copyFrom(Other.
Ambiguous);
break;
554 case EllipsisConversion:
break;
555 case BadConversion: Bad = Other.
Bad;
break;
571 assert(isInitialized() &&
"querying uninitialized conversion");
572 return Kind(ConversionKind);
584 case StandardConversion:
587 case UserDefinedConversion:
588 case AmbiguousConversion:
591 case EllipsisConversion:
598 llvm_unreachable(
"Invalid ImplicitConversionSequence::Kind!");
606 bool isFailure()
const {
return isBad() || isAmbiguous(); }
616 setKind(BadConversion);
617 Bad.init(Failure, FromExpr, ToType);
623 setKind(BadConversion);
624 Bad.init(Failure, FromType, ToType);
632 if (ConversionKind == AmbiguousConversion)
return;
633 ConversionKind = AmbiguousConversion;
634 Ambiguous.construct();
639 Standard.setAsIdentityConversion();
640 Standard.setFromType(T);
641 Standard.setAllToTypes(T);
647 return StdInitializerListElement;
651 StdInitializerListElement = V;
659 Indistinguishable = 0,
663 void DiagnoseAmbiguousConversion(
Sema &S,
795 for (
auto &
C : Conversions) {
796 if (!
C.isInitialized())
return false;
797 if (
C.isAmbiguous())
return true;
804 Conversions[Idx].Bad.FromExpr,
805 Conversions[Idx].Bad.getFromType(),
806 Conversions[Idx].Bad.getToType(), S);
818 while (STy->isPointerType() || STy->isReferenceType())
824 return ExplicitCallArguments;
856 llvm::SmallPtrSet<Decl *, 16> Functions;
860 llvm::BumpPtrAllocator SlabAllocator;
865 constexpr
static unsigned NumInlineBytes =
867 unsigned NumInlineBytesUsed = 0;
868 llvm::AlignedCharArray<alignof(void *), NumInlineBytes> InlineSpace;
876 template <
typename T>
877 T *slabAllocate(
unsigned N) {
879 static_assert(
alignof(T) ==
alignof(
void *),
880 "Only works for pointer-aligned types.");
881 static_assert(std::is_trivial<T>::value ||
882 std::is_same<ImplicitConversionSequence, T>::value,
883 "Add destruction logic to OverloadCandidateSet::clear().");
885 unsigned NBytes =
sizeof(T) * N;
886 if (NBytes > NumInlineBytes - NumInlineBytesUsed)
887 return SlabAllocator.Allocate<T>(N);
888 char *FreeSpaceStart = InlineSpace.buffer + NumInlineBytesUsed;
889 assert(
uintptr_t(FreeSpaceStart) %
alignof(
void *) == 0 &&
890 "Misaligned storage!");
892 NumInlineBytesUsed += NBytes;
893 return reinterpret_cast<T *
>(FreeSpaceStart);
896 void destroyCandidates();
900 : Loc(Loc), Kind(CSK) {}
922 size_t size()
const {
return Candidates.size(); }
923 bool empty()
const {
return Candidates.empty(); }
930 slabAllocate<ImplicitConversionSequence>(NumConversions);
933 for (
unsigned I = 0; I != NumConversions; ++I)
943 assert((Conversions.empty() || Conversions.size() == NumConversions) &&
944 "preallocated conversion sequence has wrong length");
949 ? allocateConversionSequences(NumConversions)
958 void NoteCandidates(
Sema &S,
978 explicit operator bool()
const {
return Constructor; }
984 if (isa<UsingDecl>(ND))
1001 #endif // LLVM_CLANG_SEMA_OVERLOAD_H unsigned ExplicitCallArguments
The number of call arguments that were explicitly provided, to be used while performing partial order...
DeclAccessPair FoundConversionFunction
The declaration that we found via name lookup, which might be the same as ConversionFunction or it mi...
Function pointer conversion (C++17 [conv.fctptr])
unsigned DeprecatedStringLiteralToCharPtr
Whether this is the deprecated conversion of a string literal to a pointer to non-const character dat...
(CUDA) This candidate was not viable because the callee was not accessible from the caller's target (...
void setFromType(QualType T)
Represents a function declaration or definition.
void setStdInitializerListElement(bool V=true)
bool EllipsisConversion
EllipsisConversion - When this is true, it means user-defined conversion sequence starts with a ...
A (possibly-)qualified type.
void setToType(QualType T)
ImplicitConversionKind
ImplicitConversionKind - The kind of implicit conversion used to convert an argument to a parameter's...
void setFromType(QualType T)
Conversion not allowed by the C standard, but that we accept as an extension anyway.
llvm::MutableArrayRef< ImplicitConversionSequence > ConversionSequenceList
A list of implicit conversion sequences for the arguments of an OverloadCandidate.
QualType getToType() const
A structure used to record information about a failed template argument deduction, for diagnosis.
Cannot tell whether this is a narrowing conversion because the expression is value-dependent.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
C Language Family Type Representation.
bool tryToFixConversion(const Expr *FromExpr, const QualType FromQTy, const QualType ToQTy, Sema &S)
If possible, generates and stores a fix for the given conversion.
ConversionSet::const_iterator const_iterator
Complex conversions (C99 6.3.1.6)
UserDefinedConversionSequence UserDefined
When ConversionKind == UserDefinedConversion, provides the details of the user-defined conversion seq...
ImplicitConversionSequence()
ConstructorInfo getConstructorInfo(NamedDecl *ND)
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...
Decl - This represents one declaration (or definition), e.g.
Defines the C++ template declaration subclasses.
Not a narrowing conversion.
ImplicitConversionRank
ImplicitConversionRank - The rank of an implicit conversion kind.
unsigned IncompatibleObjC
IncompatibleObjC - Whether this is an Objective-C conversion that we should warn about (if we actuall...
Ambiguous candidates found.
Conversions between compatible types in C99.
bool IgnoreObjectArgument
IgnoreObjectArgument - True to indicate that the first argument's conversion, which for this function...
QualType getConversionType() const
Returns the type that this conversion function is converting to.
unsigned DirectBinding
DirectBinding - True when this is a reference binding that is a direct binding (C++ [dcl...
Represents a C++ constructor within a class.
bool hasAmbiguousConversion() const
hasAmbiguousConversion - Returns whether this overload candidate requires an ambiguous conversion or ...
QualType getFromType() const
bool isUserDefined() const
const T * getAs() const
Member-template getAs<specific type>'.
bool IsSurrogate
IsSurrogate - True to indicate that this candidate is a surrogate for a conversion to a function poin...
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
bool HadMultipleCandidates
HadMultipleCandidates - When this is true, it means that the conversion function was resolved from an...
void * ToTypePtrs[3]
ToType - The types that this conversion is converting to in each step.
OverloadCandidate & addCandidate(unsigned NumConversions=0, ConversionSequenceList Conversions=None)
Add a new candidate with NumConversions conversion sequence slots to the overload set...
ImplicitConversionSequence(const ImplicitConversionSequence &Other)
QualType getFromType() const
Boolean conversions (C++ [conv.bool])
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
unsigned BindsToFunctionLvalue
Whether we're binding to a function lvalue.
C++ [over.match.copy]: Copy-initialization of an object of class type by user-defined conversion...
BadConversionSequence Bad
When ConversionKind == BadConversion, provides the details of the bad conversion. ...
Identity conversion (no conversion)
bool isStdInitializerListElement() const
Whether the target is really a std::initializer_list, and the sequence only represents the worst elem...
Kind
Kind - The kind of implicit conversion sequence.
ConversionSet & conversions()
BadConversionSequence - Records information about an invalid conversion sequence. ...
Floating point conversions (C++ [conv.double].
ConversionSequenceList allocateConversionSequences(unsigned NumConversions)
Allocate storage for conversion sequences for NumConversions conversions.
OverloadCandidateDisplayKind
Floating point promotions (C++ [conv.fpprom])
bool isInitialized() const
Determines whether this conversion sequence has been initialized.
unsigned BindsToRvalue
Whether we're binding to an rvalue.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
Succeeded, but refers to a deleted function.
ImplicitConversionSequence & operator=(const ImplicitConversionSequence &Other)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
unsigned QualificationIncludesObjCLifetime
Whether the qualification conversion involves a change in the Objective-C lifetime (for automatic ref...
QualType getToType(unsigned Idx) const
This candidate function was not viable because an enable_if attribute disabled it.
ImplicitConversionKind Second
Second - The second conversion can be an integral promotion, floating point promotion, integral conversion, floating point conversion, floating-integral conversion, pointer conversion, pointer-to-member conversion, or boolean conversion.
A narrowing conversion, because a constant expression got narrowed.
unsigned IsLvalueReference
Whether this is an lvalue reference binding (otherwise, it's an rvalue reference binding).
NarrowingKind
NarrowingKind - The kind of narrowing conversion being performed by a standard conversion sequence ac...
Qualification conversions (C++ [conv.qual])
void setFromType(QualType T)
void * getAsOpaquePtr() const
The number of conversion kinds.
ImplicitConversionKind Third
Third - The third conversion can be a qualification conversion or a function conversion.
Complex <-> Real conversion.
bool Viable
Viable - True to indicate that this overload candidate is viable.
ConversionSequenceList Conversions
The conversion sequences used to convert the function arguments to the function parameters.
Integral promotions (C++ [conv.prom])
This conversion function template specialization candidate is not viable because the final conversion...
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
void setAsIdentityConversion(QualType T)
C-only conversion between pointers with incompatible types.
Sema - This implements semantic analysis and AST building for C.
Represents a prototype with parameter type info, e.g.
Transparent Union Conversions.
This conversion candidate was not considered because it duplicates the work of a trivial or derived-t...
CandidateSetKind getKind() const
bool isNewCandidate(Decl *F)
Determine when this overload candidate will be new to the overload set.
A narrowing conversion by virtue of the source and destination types.
StandardConversionSequence FinalConversion
FinalConversion - For a conversion function (where Function is a CXXConversionDecl), the standard conversion that occurs after the call to the overload candidate to convert the result of calling the conversion function to the required type.
ObjC ARC writeback conversion.
Expr - This represents one expression.
Represents an ambiguous user-defined conversion sequence.
This candidate was not viable because it is a non-default multiversioned function.
This inherited constructor is not viable because it would slice the argument.
SourceLocation getLocation() const
StandardConversionSequence After
After - Represents the standard conversion that occurs after the actual user-defined conversion...
CXXConstructorDecl * CopyConstructor
CopyConstructor - The copy constructor that is used to perform this conversion, when the conversion i...
Overload resolution succeeded.
unsigned ReferenceBinding
ReferenceBinding - True when this is a reference binding (C++ [over.ics.ref]).
Floating-integral conversions (C++ [conv.fpint])
void init(FailureKind K, Expr *From, QualType To)
This conversion candidate was not considered because it is an illegal instantiation of a constructor ...
bool TryToFixBadConversion(unsigned Idx, Sema &S)
CXXConversionDecl * Surrogate
Surrogate - The conversion function for which this candidate is a surrogate, but only if IsSurrogate ...
UserDefinedConversionSequence - Represents a user-defined conversion sequence (C++ 13...
This candidate was not viable because its address could not be taken.
const ConversionSet & conversions() const
StandardConversionSequence Standard
When ConversionKind == StandardConversion, provides the details of the standard conversion sequence...
Represents a C++ conversion function within a class.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
A narrowing conversion, because a non-constant-expression variable might have got narrowed...
QualType getFromType() const
Lvalue-to-rvalue conversion (C++ [conv.lval])
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 ObjCLifetimeConversionBinding
Whether this binds a reference to an object with a different Objective-C lifetime qualifier...
CXXConstructorDecl * Constructor
Integral conversions (C++ [conv.integral])
SmallVectorImpl< OverloadCandidate >::iterator iterator
Complex promotions (Clang extension)
ImplicitConversionSequence - Represents an implicit conversion sequence, which may be a standard conv...
bool isPointerConversionToVoidPointer(ASTContext &Context) const
isPointerConversionToVoidPointer - Determines whether this conversion is a conversion of a pointer to...
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Encodes a location in the source.
C++ [over.match.ctor], [over.match.list] Initialization of an object of class type by constructor...
ConversionSet::iterator iterator
bool isIdentityConversion() const
A vector splat from an arithmetic type.
OverloadingResult
OverloadingResult - Capture the result of performing overload resolution.
Objective-C ARC writeback conversion.
void init(FailureKind K, QualType From, QualType To)
void setAsIdentityConversion()
StandardConversionSequence - Set the standard conversion sequence to the identity conversion...
Pointer conversions (C++ [conv.ptr])
C++ [over.match.oper]: Lookup of operator function candidates in a call using operator syntax...
Requests that all candidates be shown.
Derived-to-base (C++ [over.best.ics])
Complex-real conversions (C99 6.3.1.7)
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13...
void setBad(BadConversionSequence::FailureKind Failure, Expr *FromExpr, QualType ToType)
Sets this sequence as a bad conversion for an explicit argument.
static QualType getFromOpaquePtr(const void *Ptr)
void setFromExpr(Expr *E)
unsigned getNumParams() const
bool isPointerConversionToBool() const
isPointerConversionToBool - Determines whether this conversion is a conversion of a pointer or pointe...
A POD class for pairing a NamedDecl* with an access specifier.
ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind)
GetConversionRank - Retrieve the implicit conversion rank corresponding to the given implicit convers...
DeclAccessPair FoundCopyConstructor
OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK)
Dataflow Directional Tag Classes.
~ImplicitConversionSequence()
AccessSpecifier getAccess() const
Conversions allowed in C, but not C++.
Array-to-pointer conversion (C++ [conv.array])
StandardConversionSequence Before
Represents the standard conversion that occurs before the actual user-defined conversion.
Requests that only viable candidates be shown.
FunctionDecl * Function
Function - The actual function that this candidate represents.
FunctionDecl * ConversionFunction
ConversionFunction - The function that will perform the user-defined conversion.
Conversion only allowed in the C standard (e.g. void* to char*).
void setToType(QualType T)
void setAllToTypes(QualType T)
unsigned getKindRank() const
Return a ranking of the implicit conversion sequence kind, where smaller ranks represent better conve...
This candidate was not viable because its OpenCL extension is disabled.
unsigned BindsImplicitObjectArgumentWithoutRefQualifier
Whether this binds an implicit object argument to a non-static member function without a ref-qualifie...
unsigned char FailureKind
FailureKind - The reason why this candidate is not viable.
void setBad(BadConversionSequence::FailureKind Failure, QualType FromType, QualType ToType)
Sets this sequence as a bad conversion for an implicit argument.
DeclAccessPair FoundDecl
FoundDecl - The original declaration that was looked up / invented / otherwise found, together with its access.
Block Pointer conversions.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
ConversionFixItGenerator Fix
The FixIt hints which can be used to fix the Bad candidate.
AmbiguousConversionSequence Ambiguous
When ConversionKind == AmbiguousConversion, provides the details of the ambiguous conversion...
void addConversion(NamedDecl *Found, FunctionDecl *D)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Function-to-pointer (C++ [conv.array])
Defines the clang::SourceLocation class and associated facilities.
QualType getToType() const
FunctionTemplateDecl * ConstructorTmpl
const_iterator begin() const
void * FromTypePtr
FromType - The type that this conversion is converting from.
ImplicitConversionRank getRank() const
getRank - Retrieve the rank of this standard conversion sequence (C++ 13.3.3.1.1p3).
static Decl::Kind getKind(const Decl *D)
The class facilities generation and storage of conversion FixIts.
Zero constant to event (OpenCL1.2 6.12.10)
ImplicitConversionKind First
First – The first conversion can be an lvalue-to-rvalue conversion, array-to-pointer conversion...
No viable function found.
DeductionFailureInfo DeductionFailure
This represents a decl that may have a name.
void dump() const
dump - Print this standard conversion sequence to standard error.
Pointer-to-member conversions (C++ [conv.mem])
void setToType(unsigned Idx, QualType T)
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
This conversion candidate is not viable because its result type is not implicitly convertible to the ...
const_iterator end() const
Declaration of a template function.
StandardConversionSequence - represents a standard conversion sequence (C++ 13.3.3.1.1).