15 #ifndef LLVM_CLANG_SEMA_OVERLOAD_H
16 #define LLVM_CLANG_SEMA_OVERLOAD_H
26 #include "llvm/ADT/SmallPtrSet.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/Support/AlignOf.h"
29 #include "llvm/Support/Allocator.h"
33 class CXXConstructorDecl;
34 class CXXConversionDecl;
217 assert(Idx < 3 &&
"To type index is out of range");
230 assert(Idx < 3 &&
"To type index is out of range");
407 unsigned ConversionKind : 30;
411 unsigned StdInitializerListElement : 1;
413 void setKind(
Kind K) {
442 : ConversionKind(Uninitialized), StdInitializerListElement(
false) {
449 : ConversionKind(Other.ConversionKind),
450 StdInitializerListElement(Other.StdInitializerListElement)
452 switch (ConversionKind) {
453 case Uninitialized:
break;
470 assert(
isInitialized() &&
"querying uninitialized conversion");
471 return Kind(ConversionKind);
497 llvm_unreachable(
"Invalid ImplicitConversionSequence::Kind!");
516 Bad.
init(Failure, FromExpr, ToType);
523 Bad.
init(Failure, FromType, ToType);
545 return StdInitializerListElement;
549 StdInitializerListElement = V;
690 if (!C.isInitialized())
return false;
691 if (C.isAmbiguous())
return true;
712 while (STy->isPointerType() || STy->isReferenceType())
738 llvm::SmallPtrSet<Decl *, 16> Functions;
742 llvm::BumpPtrAllocator SlabAllocator;
747 constexpr
static unsigned NumInlineBytes =
749 unsigned NumInlineBytesUsed;
750 llvm::AlignedCharArray<alignof(void *), NumInlineBytes> InlineSpace;
758 template <
typename T>
759 T *slabAllocate(
unsigned N) {
761 static_assert(
alignof(T) ==
alignof(
void *),
762 "Only works for pointer-aligned types.");
763 static_assert(std::is_trivial<T>::value ||
764 std::is_same<ImplicitConversionSequence, T>::value,
765 "Add destruction logic to OverloadCandidateSet::clear().");
767 unsigned NBytes =
sizeof(T) * N;
768 if (NBytes > NumInlineBytes - NumInlineBytesUsed)
769 return SlabAllocator.Allocate<T>(N);
770 char *FreeSpaceStart = InlineSpace.buffer + NumInlineBytesUsed;
771 assert(
uintptr_t(FreeSpaceStart) %
alignof(
void *) == 0 &&
772 "Misaligned storage!");
774 NumInlineBytesUsed += NBytes;
775 return reinterpret_cast<T *
>(FreeSpaceStart);
778 OverloadCandidateSet(
const OverloadCandidateSet &) =
delete;
779 void operator=(
const OverloadCandidateSet &) =
delete;
781 void destroyCandidates();
785 : Loc(Loc),
Kind(CSK), NumInlineBytesUsed(0) {}
804 size_t size()
const {
return Candidates.size(); }
805 bool empty()
const {
return Candidates.empty(); }
812 slabAllocate<ImplicitConversionSequence>(NumConversions);
815 for (
unsigned I = 0;
I != NumConversions; ++
I)
825 assert((Conversions.empty() || Conversions.size() == NumConversions) &&
826 "preallocated conversion sequence has wrong length");
839 bool UserDefinedConversion =
false);
851 const OverloadCandidate& Cand1,
852 const OverloadCandidate& Cand2,
854 bool UserDefinedConversion =
false);
865 if (isa<UsingDecl>(ND))
881 #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 4.13)
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)
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
char Buffer[sizeof(ConversionSet)]
void setStdInitializerListElement(bool V=true)
bool EllipsisConversion
EllipsisConversion - When this is true, it means user-defined conversion sequence starts with a ...
QualType getToType() const
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)
QualType getConversionType() const
Returns the type that this conversion function is converting to.
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.
void NoteCandidates(Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr * > Args, StringRef Opc="", SourceLocation Loc=SourceLocation(), llvm::function_ref< bool(OverloadCandidate &)> Filter=[](OverloadCandidate &){return true;})
PrintOverloadCandidates - When overload resolution fails, prints diagnostic messages containing the c...
A structure used to record information about a failed template argument deduction, for diagnosis.
void dump() const
dump - Print this standard conversion sequence to standard error.
Cannot tell whether this is a narrowing conversion because the expression is value-dependent.
C Language Family Type Representation.
bool tryToFixConversion(const Expr *FromExpr, const QualType FromQTy, const QualType ToQTy, Sema &S)
If possible, generates and stores a fix for the given conversion.
Complex conversions (C99 6.3.1.6)
UserDefinedConversionSequence UserDefined
When ConversionKind == UserDefinedConversion, provides the details of the user-defined conversion seq...
ImplicitConversionSequence()
ConstructorInfo getConstructorInfo(NamedDecl *ND)
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...
ConversionSet::iterator iterator
unsigned DirectBinding
DirectBinding - True when this is a reference binding that is a direct binding (C++ [dcl...
Represents a C++ constructor within a class.
void * getAsOpaquePtr() const
AccessSpecifier getAccess() const
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)
Boolean conversions (C++ 4.12)
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.
BadConversionSequence Bad
When ConversionKind == BadConversion, provides the details of the bad conversion. ...
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Identity conversion (no conversion)
Kind
Kind - The kind of implicit conversion sequence.
ConversionSet & conversions()
BadConversionSequence - Records information about an invalid conversion sequence. ...
QualType getToType() const
Floating point conversions (C++ 4.8)
const_iterator end() const
ConversionSequenceList allocateConversionSequences(unsigned NumConversions)
Allocate storage for conversion sequences for NumConversions conversions.
OverloadCandidateDisplayKind
Floating point promotions (C++ 4.6)
ImplicitConversionRank getRank() const
getRank - Retrieve the rank of this standard conversion sequence (C++ 13.3.3.1.1p3).
unsigned BindsToRvalue
Whether we're binding to an rvalue.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
Succeeded, but refers to a deleted function.
ImplicitConversionSequence & operator=(const ImplicitConversionSequence &Other)
unsigned QualificationIncludesObjCLifetime
Whether the qualification conversion involves a change in the Objective-C lifetime (for automatic ref...
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++ 4.4)
void setFromType(QualType T)
NarrowingKind getNarrowingKind(ASTContext &Context, const Expr *Converted, APValue &ConstantValue, QualType &ConstantType) const
Check if this standard conversion sequence represents a narrowing conversion, according to C++11 [dcl...
The number of conversion kinds.
ImplicitConversionKind Third
Third - The third conversion can be a qualification conversion or a function conversion.
detail::InMemoryDirectory::const_iterator I
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++ 4.5)
This conversion function template specialization candidate is not viable because the final conversion...
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
QualType BuiltinParamTypes[3]
BuiltinParamTypes - Provides the parameter types of a built-in overload candidate.
void setAsIdentityConversion(QualType T)
C-only conversion between pointers with incompatible types.
Sema - This implements semantic analysis and AST building for C.
bool isBetterOverloadCandidate(Sema &S, const OverloadCandidate &Cand1, const OverloadCandidate &Cand2, SourceLocation Loc, bool UserDefinedConversion=false)
isBetterOverloadCandidate - Determines whether the first overload candidate is a better candidate tha...
Represents a prototype with parameter type info, e.g.
Transparent Union Conversions.
This conversion candidate was not considered because it duplicates the work of a trivial or derived-t...
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.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
ObjC ARC writeback conversion.
bool hasAmbiguousConversion() const
hasAmbiguousConversion - Returns whether this overload candidate requires an ambiguous conversion or ...
void dump() const
dump - Print this user-defined conversion sequence to standard error.
Expr - This represents one expression.
Represents an ambiguous user-defined conversion sequence.
This inherited constructor is not viable because it would slice the argument.
StandardConversionSequence After
After - Represents the standard conversion that occurs after the actual user-defined conversion...
SmallVectorImpl< OverloadCandidate >::iterator iterator
void copyFrom(const AmbiguousConversionSequence &)
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]).
QualType getFromType() const
Floating-integral conversions (C++ 4.9)
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)
QualType getFromType() const
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.
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...
Lvalue-to-rvalue conversion (C++ 4.1)
unsigned ObjCLifetimeConversionBinding
Whether this binds a reference to an object with a different Objective-C lifetime qualifier...
bool isIdentityConversion() const
CXXConstructorDecl * Constructor
QualType getFromType() const
Integral conversions (C++ 4.7)
Complex promotions (Clang extension)
ImplicitConversionSequence - Represents an implicit conversion sequence, which may be a standard conv...
bool isInitialized() const
Determines whether this conversion sequence has been initialized.
SmallVector< std::pair< NamedDecl *, FunctionDecl * >, 4 > ConversionSet
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
Encodes a location in the source.
unsigned getNumParams() const
getNumParams - Return the number of parameters this function must have based on its FunctionType...
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 dump() const
dump - Print this implicit conversion sequence to standard error.
bool isStdInitializerListElement() const
Whether the target is really a std::initializer_list, and the sequence only represents the worst elem...
void setAsIdentityConversion()
StandardConversionSequence - Set the standard conversion sequence to the identity conversion...
Pointer conversions (C++ 4.10)
Lookup for candidates for a call using operator syntax.
CandidateSetKind getKind() const
QualType getToType(unsigned Idx) const
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)
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...
void DiagnoseAmbiguousConversion(Sema &S, SourceLocation CaretLoc, const PartialDiagnostic &PDiag) const
Diagnoses an ambiguous conversion.
DeclAccessPair FoundCopyConstructor
OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK)
~ImplicitConversionSequence()
ConversionSet::const_iterator const_iterator
const ConversionSet & conversions() const
Conversions allowed in C, but not C++.
Array-to-pointer conversion (C++ 4.2)
StandardConversionSequence Before
Represents the standard conversion that occurs before the actual user-defined conversion.
Requests that only viable candidates be shown.
detail::InMemoryDirectory::const_iterator E
FunctionDecl * Function
Function - The actual function that this candidate represents.
unsigned getNumParams() const
bool isPointerConversionToBool() const
isPointerConversionToBool - Determines whether this conversion is a conversion of a pointer or pointe...
FunctionDecl * ConversionFunction
ConversionFunction - The function that will perform the user-defined conversion.
Conversion only allowed in the C standard.
void setToType(QualType T)
void setAllToTypes(QualType T)
const T * getAs() const
Member-template getAs<specific type>'.
This candidate was not viable because its OpenCL extension is disabled.
unsigned getKindRank() const
Return a ranking of the implicit conversion sequence kind, where smaller ranks represent better conve...
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)
const_iterator begin() const
Function-to-pointer (C++ 4.3)
FunctionTemplateDecl * ConstructorTmpl
void * FromTypePtr
FromType - The type that this conversion is converting from.
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best, bool UserDefinedConversion=false)
Find the best viable function on this overload set, if it exists.
bool isUserDefined() const
The class facilities generation and storage of conversion FixIts.
Zero constant to event (OpenCL1.2 6.12.10)
void clear()
Clear out all of the candidates.
ImplicitConversionKind First
First – The first conversion can be an lvalue-to-rvalue conversion, array-to-pointer conversion...
No viable function found.
DeductionFailureInfo DeductionFailure
NamedDecl - This represents a decl with a name.
Pointer-to-member conversions (C++ 4.11)
void setToType(unsigned Idx, QualType T)
bool isPointerConversionToVoidPointer(ASTContext &Context) const
isPointerConversionToVoidPointer - Determines whether this conversion is a conversion of a pointer to...
This conversion candidate is not viable because its result type is not implicitly convertible to the ...
Declaration of a template function.
SourceLocation getLocation() const
StandardConversionSequence - represents a standard conversion sequence (C++ 13.3.3.1.1).