14 #ifndef LLVM_CLANG_SEMA_OVERLOAD_H 15 #define LLVM_CLANG_SEMA_OVERLOAD_H 28 #include "llvm/ADT/ArrayRef.h" 29 #include "llvm/ADT/None.h" 30 #include "llvm/ADT/STLExtras.h" 31 #include "llvm/ADT/SmallPtrSet.h" 32 #include "llvm/ADT/SmallVector.h" 33 #include "llvm/ADT/StringRef.h" 34 #include "llvm/Support/AlignOf.h" 35 #include "llvm/Support/Allocator.h" 36 #include "llvm/Support/Casting.h" 37 #include "llvm/Support/ErrorHandling.h" 333 assert(Idx < 3 &&
"To type index is out of range");
339 ToTypePtrs[1] = ToTypePtrs[0];
340 ToTypePtrs[2] = ToTypePtrs[0];
348 assert(Idx < 3 &&
"To type index is out of range");
352 void setAsIdentityConversion();
362 bool IgnoreFloatToIntegralConversion =
false)
const;
363 bool isPointerConversionToBool()
const;
364 bool isPointerConversionToVoidPointer(
ASTContext& Context)
const;
443 conversions().push_back(std::make_pair(Found, D));
520 StandardConversion = 0,
533 unsigned ConversionKind : 30;
537 unsigned StdInitializerListElement : 1;
539 void setKind(
Kind K) {
545 if (ConversionKind == AmbiguousConversion) Ambiguous.destruct();
569 Standard.setAsIdentityConversion();
573 : ConversionKind(Other.ConversionKind),
574 StdInitializerListElement(Other.StdInitializerListElement) {
575 switch (ConversionKind) {
577 case StandardConversion: Standard = Other.
Standard;
break;
578 case UserDefinedConversion: UserDefined = Other.
UserDefined;
break;
579 case AmbiguousConversion: Ambiguous.copyFrom(Other.
Ambiguous);
break;
580 case EllipsisConversion:
break;
581 case BadConversion: Bad = Other.
Bad;
break;
597 assert(isInitialized() &&
"querying uninitialized conversion");
598 return Kind(ConversionKind);
610 case StandardConversion:
613 case UserDefinedConversion:
614 case AmbiguousConversion:
617 case EllipsisConversion:
624 llvm_unreachable(
"Invalid ImplicitConversionSequence::Kind!");
632 bool isFailure()
const {
return isBad() || isAmbiguous(); }
642 setKind(BadConversion);
643 Bad.init(Failure, FromExpr, ToType);
649 setKind(BadConversion);
650 Bad.init(Failure, FromType, ToType);
658 if (ConversionKind == AmbiguousConversion)
return;
659 ConversionKind = AmbiguousConversion;
660 Ambiguous.construct();
665 Standard.setAsIdentityConversion();
666 Standard.setFromType(T);
667 Standard.setAllToTypes(T);
673 return StdInitializerListElement;
677 StdInitializerListElement =
V;
685 Indistinguishable = 0,
689 void DiagnoseAmbiguousConversion(
Sema &S,
856 for (
auto &
C : Conversions) {
857 if (!
C.isInitialized())
return false;
858 if (
C.isAmbiguous())
return true;
865 Conversions[Idx].Bad.FromExpr,
866 Conversions[Idx].Bad.getFromType(),
867 Conversions[Idx].Bad.getToType(), S);
885 return ExplicitCallArguments;
924 : OriginalOperator(
OO_None), AllowRewrittenCandidates(
false) {}
926 : OriginalOperator(Op), AllowRewrittenCandidates(AllowRewritten) {}
936 return OriginalOperator &&
941 if (!OriginalOperator)
949 return OO && (OO == OriginalOperator ||
950 (AllowRewrittenCandidates &&
959 if (isRewrittenOperator(FD))
977 llvm::SmallPtrSet<uintptr_t, 16> Functions;
981 llvm::BumpPtrAllocator SlabAllocator;
987 constexpr
static unsigned NumInlineBytes =
989 unsigned NumInlineBytesUsed = 0;
990 alignas(
void *)
char InlineSpace[NumInlineBytes];
1001 template <
typename T>
1002 T *slabAllocate(
unsigned N) {
1004 static_assert(
alignof(T) ==
alignof(
void *),
1005 "Only works for pointer-aligned types.");
1006 static_assert(std::is_trivial<T>::value ||
1007 std::is_same<ImplicitConversionSequence, T>::value,
1008 "Add destruction logic to OverloadCandidateSet::clear().");
1010 unsigned NBytes =
sizeof(T) * N;
1011 if (NBytes > NumInlineBytes - NumInlineBytesUsed)
1012 return SlabAllocator.Allocate<T>(N);
1013 char *FreeSpaceStart = InlineSpace + NumInlineBytesUsed;
1014 assert(
uintptr_t(FreeSpaceStart) %
alignof(
void *) == 0 &&
1015 "Misaligned storage!");
1017 NumInlineBytesUsed += NBytes;
1018 return reinterpret_cast<T *
>(FreeSpaceStart);
1021 void destroyCandidates();
1026 : Loc(Loc),
Kind(CSK), RewriteInfo(RewriteInfo) {}
1041 return Functions.insert(Key).second;
1058 size_t size()
const {
return Candidates.size(); }
1059 bool empty()
const {
return Candidates.empty(); }
1066 slabAllocate<ImplicitConversionSequence>(NumConversions);
1069 for (
unsigned I = 0; I != NumConversions; ++I)
1079 assert((Conversions.empty() || Conversions.size() == NumConversions) &&
1080 "preallocated conversion sequence has wrong length");
1085 ? allocateConversionSequences(NumConversions)
1100 void NoteCandidates(
1115 assert((Kind == CSK_InitByConstructor ||
1116 Kind == CSK_InitByUserDefinedConversion) &&
1117 "can't set the destination address space when not constructing an " 1135 explicit operator bool()
const {
return Constructor; }
1141 if (isa<UsingDecl>(ND))
1158 #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)
Candidate is not a rewritten candidate.
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.
Information about operator rewrites to consider when adding operator functions to a candidate set...
OverloadCandidateParamOrder
The parameter ordering that will be used for the candidate.
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.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
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
OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK, OperatorRewriteInfo RewriteInfo={})
bool isUserDefined() const
bool IsSurrogate
IsSurrogate - True to indicate that this candidate is a surrogate for a conversion to a function poin...
LangAS
Defines the address space values used by the address space qualifier of QualType. ...
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...
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)
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
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)
CallExpr::ADLCallKind IsADLCandidate
True if the candidate was found using ADL.
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. ...
bool isNewCandidate(Decl *F, OverloadCandidateParamOrder PO=OverloadCandidateParamOrder::Normal)
Determine when this overload candidate will be new to the overload set.
Floating point conversions (C++ [conv.double].
bool isReferenceType() const
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.
OverloadCandidateRewriteKind getRewriteKind(const FunctionDecl *FD, OverloadCandidateParamOrder PO)
Determine the kind of rewrite that should be performed for this candidate.
unsigned BindsToRvalue
Whether we're binding to an rvalue.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
void setDestAS(LangAS AS)
Succeeded, but refers to a deleted function.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
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
OverloadCandidateRewriteKind getRewriteKind() const
Get RewriteKind value in OverloadCandidateRewriteKind type (This function is to workaround the spurio...
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.
This candidate was not viable because its associated constraints were not satisfied.
Sema - This implements semantic analysis and AST building for C.
bool AllowRewrittenCandidates
Whether we should include rewritten candidates in the overload set.
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
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.
OverloadedOperatorKind OriginalOperator
The original operator as written in the source.
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.
Candidate is a rewritten candidate with a reversed order of parameters.
SourceLocation getLocation() const
StandardConversionSequence After
After - Represents the standard conversion that occurs after the actual user-defined conversion...
const T * castAs() const
Member-template castAs<specific type>.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
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)
OperatorRewriteInfo(OverloadedOperatorKind Op, bool AllowRewritten)
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...
bool isRewrittenOperator(const FunctionDecl *FD)
Would use of this function result in a rewrite using a different operator?
bool isAcceptableCandidate(const FunctionDecl *FD)
Represents a C++ conversion function within a class.
void exclude(Decl *F)
Exclude a function from being considered by overload resolution.
OverloadCandidateRewriteKind
The kinds of rewrite we perform on overload candidates.
A narrowing conversion, because a non-constant-expression variable might have got narrowed...
QualType getFromType() const
Lvalue-to-rvalue conversion (C++ [conv.lval])
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...
OverloadedOperatorKind getRewrittenOverloadedOperator(OverloadedOperatorKind Kind)
Get the other overloaded operator that the given operator can be rewritten into, if any such operator...
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...
bool isIdentityConversion() const
Requests that only tied-for-best candidates be shown.
A vector splat from an arithmetic type.
OverloadingResult
OverloadingResult - Capture the result of performing overload resolution.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs. ...
Objective-C ARC writeback conversion.
OperatorRewriteInfo getRewriteInfo() const
void init(FailureKind K, QualType From, QualType To)
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)
This constructor/conversion candidate fail due to an address space mismatch between the object being ...
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
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
Dataflow Directional Tag Classes.
~ImplicitConversionSequence()
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
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)
Not an overloaded operator.
void setAllToTypes(QualType T)
Candidate is a rewritten candidate with a different operator name.
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
This candidate constructor or conversion function is explicit but the context doesn't permit explicit...
void * FromTypePtr
FromType - The type that this conversion is converting from.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
static Decl::Kind getKind(const Decl *D)
The class facilities generation and storage of conversion FixIts.
bool isPointerType() const
Zero constant to event (OpenCL1.2 6.12.10)
unsigned RewriteKind
Whether this is a rewritten candidate, and if so, of what kind?
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.
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.
bool Best
Whether this candidate is the best viable function, or tied for being the best viable function...
StandardConversionSequence - represents a standard conversion sequence (C++ 13.3.3.1.1).