38
38
#include < cstddef>
39
39
#include < cstdint>
40
40
#include < utility>
41
+ #include < variant>
41
42
42
43
namespace clang {
43
44
@@ -743,6 +744,12 @@ class Sema;
743
744
Standard.setAllToTypes (T);
744
745
}
745
746
747
+ bool isPerfect (const ASTContext &C) const {
748
+ return (isStandard () && Standard.isIdentityConversion () &&
749
+ C.hasSameType (Standard.getFromType (), Standard.getToType (2 ))) ||
750
+ getKind () == StaticObjectArgumentConversion;
751
+ }
752
+
746
753
// True iff this is a conversion sequence from an initializer list to an
747
754
// array or std::initializer.
748
755
bool hasInitializerListContainerType () const {
@@ -979,6 +986,18 @@ class Sema;
979
986
return false ;
980
987
}
981
988
989
+ bool isPerfectMatch (const ASTContext &Ctx) const {
990
+ if (!Viable)
991
+ return false ;
992
+ for (auto &C : Conversions) {
993
+ if (!C.isInitialized ())
994
+ return false ;
995
+ if (!C.isPerfect (Ctx))
996
+ return false ;
997
+ }
998
+ return true ;
999
+ }
1000
+
982
1001
bool TryToFixBadConversion (unsigned Idx, Sema &S) {
983
1002
bool CanFix = Fix.tryToFixConversion (
984
1003
Conversions[Idx].Bad .FromExpr ,
@@ -1015,6 +1034,61 @@ class Sema;
1015
1034
RewriteKind(CRK_None) {}
1016
1035
};
1017
1036
1037
+ struct NonDeducedConversionTemplateOverloadCandidate {
1038
+ FunctionTemplateDecl *FunctionTemplate;
1039
+ DeclAccessPair FoundDecl;
1040
+ CXXRecordDecl *ActingContext;
1041
+ Expr *From;
1042
+ QualType ToType;
1043
+
1044
+ LLVM_PREFERRED_TYPE (bool )
1045
+ unsigned AllowObjCConversionOnExplicit : 1 ;
1046
+ LLVM_PREFERRED_TYPE (bool )
1047
+ unsigned AllowExplicit : 1 ;
1048
+ LLVM_PREFERRED_TYPE (bool )
1049
+ unsigned AllowResultConversion : 1 ;
1050
+ };
1051
+
1052
+ struct NonDeducedMethodTemplateOverloadCandidate {
1053
+ FunctionTemplateDecl *FunctionTemplate;
1054
+ DeclAccessPair FoundDecl;
1055
+ ArrayRef<Expr *> Args;
1056
+ CXXRecordDecl *ActingContext;
1057
+ Expr::Classification ObjectClassification;
1058
+ QualType ObjectType;
1059
+
1060
+ OverloadCandidateParamOrder PO;
1061
+ LLVM_PREFERRED_TYPE (bool )
1062
+ unsigned SuppressUserConversions : 1 ;
1063
+ LLVM_PREFERRED_TYPE (bool )
1064
+ unsigned PartialOverloading : 1 ;
1065
+ };
1066
+
1067
+ struct NonDeducedFunctionTemplateOverloadCandidate {
1068
+ FunctionTemplateDecl *FunctionTemplate;
1069
+ DeclAccessPair FoundDecl;
1070
+ ArrayRef<Expr *> Args;
1071
+
1072
+ CallExpr::ADLCallKind IsADLCandidate;
1073
+ OverloadCandidateParamOrder PO;
1074
+ LLVM_PREFERRED_TYPE (bool )
1075
+ unsigned SuppressUserConversions : 1 ;
1076
+ LLVM_PREFERRED_TYPE (bool )
1077
+ unsigned PartialOverloading : 1 ;
1078
+ LLVM_PREFERRED_TYPE (bool )
1079
+ unsigned AllowExplicit : 1 ;
1080
+ LLVM_PREFERRED_TYPE (bool )
1081
+ unsigned AggregateCandidateDeduction : 1 ;
1082
+ };
1083
+
1084
+ using NonDeducedTemplateOverloadCandidate =
1085
+ std::variant<NonDeducedConversionTemplateOverloadCandidate,
1086
+ NonDeducedMethodTemplateOverloadCandidate,
1087
+ NonDeducedFunctionTemplateOverloadCandidate>;
1088
+
1089
+ static_assert (
1090
+ std::is_trivially_destructible_v<NonDeducedTemplateOverloadCandidate>);
1091
+
1018
1092
// / OverloadCandidateSet - A set of overload candidates, used in C++
1019
1093
// / overload resolution (C++ 13.3).
1020
1094
class OverloadCandidateSet {
@@ -1043,6 +1117,8 @@ class Sema;
1043
1117
// / C++ [over.match.call.general]
1044
1118
// / Resolve a call through the address of an overload set.
1045
1119
CSK_AddressOfOverloadSet,
1120
+
1121
+ CSK_CodeCompletion,
1046
1122
};
1047
1123
1048
1124
// / Information about operator rewrites to consider when adding operator
@@ -1116,6 +1192,7 @@ class Sema;
1116
1192
private:
1117
1193
SmallVector<OverloadCandidate, 16 > Candidates;
1118
1194
llvm::SmallPtrSet<uintptr_t , 16 > Functions;
1195
+ SmallVector<NonDeducedTemplateOverloadCandidate, 8 > NonDeducedCandidates;
1119
1196
1120
1197
// Allocator for ConversionSequenceLists. We store the first few of these
1121
1198
// inline to avoid allocation for small sets.
@@ -1126,7 +1203,7 @@ class Sema;
1126
1203
OperatorRewriteInfo RewriteInfo;
1127
1204
1128
1205
constexpr static unsigned NumInlineBytes =
1129
- 24 * sizeof (ImplicitConversionSequence);
1206
+ 32 * sizeof (ImplicitConversionSequence);
1130
1207
unsigned NumInlineBytesUsed = 0 ;
1131
1208
alignas (void *) char InlineSpace[NumInlineBytes];
1132
1209
@@ -1144,8 +1221,8 @@ class Sema;
1144
1221
// It's simpler if this doesn't need to consider alignment.
1145
1222
static_assert (alignof (T) == alignof (void *),
1146
1223
" Only works for pointer-aligned types." );
1147
- static_assert (std::is_trivial <T>::value ||
1148
- std::is_same <ImplicitConversionSequence, T>::value ,
1224
+ static_assert (std::is_trivially_destructible_v <T> ||
1225
+ ( std::is_same_v <ImplicitConversionSequence, T>) ,
1149
1226
" Add destruction logic to OverloadCandidateSet::clear()." );
1150
1227
1151
1228
unsigned NBytes = sizeof (T) * N;
@@ -1199,8 +1276,12 @@ class Sema;
1199
1276
iterator begin () { return Candidates.begin (); }
1200
1277
iterator end () { return Candidates.end (); }
1201
1278
1202
- size_t size () const { return Candidates.size (); }
1203
- bool empty () const { return Candidates.empty (); }
1279
+ size_t size () const {
1280
+ return Candidates.size () + NonDeducedCandidates.size ();
1281
+ }
1282
+ bool empty () const {
1283
+ return Candidates.empty () && NonDeducedCandidates.empty ();
1284
+ }
1204
1285
1205
1286
// / Allocate storage for conversion sequences for NumConversions
1206
1287
// / conversions.
@@ -1216,6 +1297,19 @@ class Sema;
1216
1297
return ConversionSequenceList (Conversions, NumConversions);
1217
1298
}
1218
1299
1300
+ llvm::MutableArrayRef<Expr *> getPersistentArgsArray (unsigned N) {
1301
+ Expr **Exprs = slabAllocate<Expr *>(N);
1302
+ return llvm::MutableArrayRef<Expr *>(Exprs, N);
1303
+ }
1304
+
1305
+ template <typename ... T>
1306
+ llvm::MutableArrayRef<Expr *> getPersistentArgsArray (T *...Exprs) {
1307
+ llvm::MutableArrayRef<Expr *> Arr =
1308
+ getPersistentArgsArray (sizeof ...(Exprs));
1309
+ llvm::copy (std::initializer_list<Expr *>{Exprs...}, Arr.data ());
1310
+ return Arr;
1311
+ }
1312
+
1219
1313
// / Add a new candidate with NumConversions conversion sequence slots
1220
1314
// / to the overload set.
1221
1315
OverloadCandidate &addCandidate (unsigned NumConversions = 0 ,
@@ -1231,10 +1325,36 @@ class Sema;
1231
1325
return C;
1232
1326
}
1233
1327
1328
+ void AddNonDeducedTemplateCandidate (
1329
+ FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl,
1330
+ ArrayRef<Expr *> Args, bool SuppressUserConversions,
1331
+ bool PartialOverloading, bool AllowExplicit,
1332
+ CallExpr::ADLCallKind IsADLCandidate, OverloadCandidateParamOrder PO,
1333
+ bool AggregateCandidateDeduction);
1334
+
1335
+ void AddNonDeducedMethodTemplateCandidate (
1336
+ FunctionTemplateDecl *MethodTmpl, DeclAccessPair FoundDecl,
1337
+ CXXRecordDecl *ActingContext, QualType ObjectType,
1338
+ Expr::Classification ObjectClassification, ArrayRef<Expr *> Args,
1339
+ bool SuppressUserConversions, bool PartialOverloading,
1340
+ OverloadCandidateParamOrder PO);
1341
+
1342
+ void AddNonDeducedConversionTemplateCandidate (
1343
+ FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl,
1344
+ CXXRecordDecl *ActingContext, Expr *From, QualType ToType,
1345
+ bool AllowObjCConversionOnExplicit, bool AllowExplicit,
1346
+ bool AllowResultConversion);
1347
+
1348
+ void InjectNonDeducedTemplateCandidates (Sema &S);
1349
+
1234
1350
// / Find the best viable function on this overload set, if it exists.
1235
1351
OverloadingResult BestViableFunction (Sema &S, SourceLocation Loc,
1236
1352
OverloadCandidateSet::iterator& Best);
1237
1353
1354
+ OverloadingResult
1355
+ BestViableFunctionImpl (Sema &S, SourceLocation Loc,
1356
+ OverloadCandidateSet::iterator &Best);
1357
+
1238
1358
SmallVector<OverloadCandidate *, 32 > CompleteCandidates (
1239
1359
Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef<Expr *> Args,
1240
1360
SourceLocation OpLoc = SourceLocation(),
0 commit comments