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");
222 ToTypePtrs[1] = ToTypePtrs[0];
223 ToTypePtrs[2] = ToTypePtrs[0];
230 assert(Idx < 3 &&
"To type index is out of range");
301 char Buffer[
sizeof(ConversionSet)];
313 return *
reinterpret_cast<ConversionSet*
>(Buffer);
317 return *
reinterpret_cast<const ConversionSet*
>(Buffer);
321 conversions().push_back(std::make_pair(Found, D));
325 iterator
begin() {
return conversions().begin(); }
326 iterator
end() {
return conversions().end(); }
329 const_iterator
begin()
const {
return conversions().begin(); }
330 const_iterator
end()
const {
return conversions().end(); }
394 StandardConversion = 0,
407 unsigned ConversionKind : 30;
411 unsigned StdInitializerListElement : 1;
413 void setKind(
Kind K) {
419 if (ConversionKind == AmbiguousConversion) Ambiguous.destruct();
443 Standard.setAsIdentityConversion();
449 : ConversionKind(Other.ConversionKind),
450 StdInitializerListElement(Other.StdInitializerListElement)
452 switch (ConversionKind) {
454 case StandardConversion: Standard = Other.
Standard;
break;
455 case UserDefinedConversion: UserDefined = Other.
UserDefined;
break;
456 case AmbiguousConversion: Ambiguous.copyFrom(Other.
Ambiguous);
break;
457 case EllipsisConversion:
break;
458 case BadConversion: Bad = Other.
Bad;
break;
470 assert(isInitialized() &&
"querying uninitialized conversion");
471 return Kind(ConversionKind);
483 case StandardConversion:
486 case UserDefinedConversion:
487 case AmbiguousConversion:
490 case EllipsisConversion:
497 llvm_unreachable(
"Invalid ImplicitConversionSequence::Kind!");
505 bool isFailure()
const {
return isBad() || isAmbiguous(); }
515 setKind(BadConversion);
516 Bad.init(Failure, FromExpr, ToType);
522 setKind(BadConversion);
523 Bad.init(Failure, FromType, ToType);
530 if (ConversionKind == AmbiguousConversion)
return;
531 ConversionKind = AmbiguousConversion;
532 Ambiguous.construct();
537 Standard.setAsIdentityConversion();
538 Standard.setFromType(T);
539 Standard.setAllToTypes(T);
545 return StdInitializerListElement;
549 StdInitializerListElement = V;
557 Indistinguishable = 0,
561 void DiagnoseAmbiguousConversion(
Sema &S,
689 for (
auto &
C : Conversions) {
690 if (!
C.isInitialized())
return false;
691 if (
C.isAmbiguous())
return true;
698 Conversions[Idx].Bad.FromExpr,
699 Conversions[Idx].Bad.getFromType(),
700 Conversions[Idx].Bad.getToType(), S);
712 while (STy->isPointerType() || STy->isReferenceType())
718 return ExplicitCallArguments;
747 llvm::SmallPtrSet<Decl *, 16> Functions;
751 llvm::BumpPtrAllocator SlabAllocator;
756 constexpr
static unsigned NumInlineBytes =
758 unsigned NumInlineBytesUsed;
759 llvm::AlignedCharArray<alignof(void *), NumInlineBytes> InlineSpace;
767 template <
typename T>
768 T *slabAllocate(
unsigned N) {
770 static_assert(
alignof(
T) ==
alignof(
void *),
771 "Only works for pointer-aligned types.");
772 static_assert(std::is_trivial<T>::value ||
773 std::is_same<ImplicitConversionSequence, T>::value,
774 "Add destruction logic to OverloadCandidateSet::clear().");
776 unsigned NBytes =
sizeof(
T) * N;
777 if (NBytes > NumInlineBytes - NumInlineBytesUsed)
778 return SlabAllocator.Allocate<
T>(N);
779 char *FreeSpaceStart = InlineSpace.buffer + NumInlineBytesUsed;
780 assert(
uintptr_t(FreeSpaceStart) %
alignof(
void *) == 0 &&
781 "Misaligned storage!");
783 NumInlineBytesUsed += NBytes;
784 return reinterpret_cast<T *
>(FreeSpaceStart);
790 void destroyCandidates();
794 : Loc(Loc), Kind(CSK), NumInlineBytesUsed(0) {}
810 iterator
begin() {
return Candidates.begin(); }
811 iterator
end() {
return Candidates.end(); }
813 size_t size()
const {
return Candidates.size(); }
814 bool empty()
const {
return Candidates.empty(); }
821 slabAllocate<ImplicitConversionSequence>(NumConversions);
824 for (
unsigned I = 0; I != NumConversions; ++I)
834 assert((Conversions.empty() || Conversions.size() == NumConversions) &&
835 "preallocated conversion sequence has wrong length");
840 ? allocateConversionSequences(NumConversions)
849 void NoteCandidates(
Sema &S,
868 explicit operator bool()
const {
return Constructor; }
873 if (isa<UsingDecl>(ND))
889 #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)
An instance of this class is created to represent 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.
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...
ConversionSet::iterator iterator
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++ 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.
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++ 4.8)
ConversionSequenceList allocateConversionSequences(unsigned NumConversions)
Allocate storage for conversion sequences for NumConversions conversions.
OverloadCandidateDisplayKind
Floating point promotions (C++ 4.6)
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)
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++ 4.4)
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++ 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.
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 inherited constructor is not viable because it would slice the argument.
const FunctionProtoType * T
SourceLocation getLocation() const
StandardConversionSequence After
After - Represents the standard conversion that occurs after the actual user-defined conversion...
SmallVectorImpl< OverloadCandidate >::iterator iterator
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++ 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)
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++ 4.1)
unsigned ObjCLifetimeConversionBinding
Whether this binds a reference to an object with a different Objective-C lifetime qualifier...
CXXConstructorDecl * Constructor
Integral conversions (C++ 4.7)
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...
SmallVector< std::pair< NamedDecl *, FunctionDecl * >, 4 > ConversionSet
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
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...
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...
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++ 4.10)
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()
ConversionSet::const_iterator const_iterator
AccessSpecifier getAccess() 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.
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.
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)
Function-to-pointer (C++ 4.3)
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
NamedDecl - This represents a decl with a name.
void dump() const
dump - Print this standard conversion sequence to standard error.
Pointer-to-member conversions (C++ 4.11)
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).