1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #include "clang/Sema/Overload.h" |
14 | #include "clang/AST/ASTContext.h" |
15 | #include "clang/AST/CXXInheritance.h" |
16 | #include "clang/AST/DeclObjC.h" |
17 | #include "clang/AST/Expr.h" |
18 | #include "clang/AST/ExprCXX.h" |
19 | #include "clang/AST/ExprObjC.h" |
20 | #include "clang/AST/TypeOrdering.h" |
21 | #include "clang/Basic/Diagnostic.h" |
22 | #include "clang/Basic/DiagnosticOptions.h" |
23 | #include "clang/Basic/PartialDiagnostic.h" |
24 | #include "clang/Basic/TargetInfo.h" |
25 | #include "clang/Sema/Initialization.h" |
26 | #include "clang/Sema/Lookup.h" |
27 | #include "clang/Sema/SemaInternal.h" |
28 | #include "clang/Sema/Template.h" |
29 | #include "clang/Sema/TemplateDeduction.h" |
30 | #include "llvm/ADT/DenseSet.h" |
31 | #include "llvm/ADT/Optional.h" |
32 | #include "llvm/ADT/STLExtras.h" |
33 | #include "llvm/ADT/SmallPtrSet.h" |
34 | #include "llvm/ADT/SmallString.h" |
35 | #include <algorithm> |
36 | #include <cstdlib> |
37 | |
38 | using namespace clang; |
39 | using namespace sema; |
40 | |
41 | static bool functionHasPassObjectSizeParams(const FunctionDecl *FD) { |
42 | return llvm::any_of(FD->parameters(), [](const ParmVarDecl *P) { |
43 | return P->hasAttr<PassObjectSizeAttr>(); |
44 | }); |
45 | } |
46 | |
47 | |
48 | static ExprResult |
49 | CreateFunctionRefExpr(Sema &S, FunctionDecl *Fn, NamedDecl *FoundDecl, |
50 | const Expr *Base, bool HadMultipleCandidates, |
51 | SourceLocation Loc = SourceLocation(), |
52 | const DeclarationNameLoc &LocInfo = DeclarationNameLoc()){ |
53 | if (S.DiagnoseUseOfDecl(FoundDecl, Loc)) |
54 | return ExprError(); |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | if (FoundDecl != Fn && S.DiagnoseUseOfDecl(Fn, Loc)) |
62 | return ExprError(); |
63 | if (auto *FPT = Fn->getType()->getAs<FunctionProtoType>()) |
64 | S.ResolveExceptionSpec(Loc, FPT); |
65 | DeclRefExpr *DRE = new (S.Context) |
66 | DeclRefExpr(S.Context, Fn, false, Fn->getType(), VK_LValue, Loc, LocInfo); |
67 | if (HadMultipleCandidates) |
68 | DRE->setHadMultipleCandidates(true); |
69 | |
70 | S.MarkDeclRefReferenced(DRE, Base); |
71 | return S.ImpCastExprToType(DRE, S.Context.getPointerType(DRE->getType()), |
72 | CK_FunctionToPointerDecay); |
73 | } |
74 | |
75 | static bool IsStandardConversion(Sema &S, Expr* From, QualType ToType, |
76 | bool InOverloadResolution, |
77 | StandardConversionSequence &SCS, |
78 | bool CStyle, |
79 | bool AllowObjCWritebackConversion); |
80 | |
81 | static bool IsTransparentUnionStandardConversion(Sema &S, Expr* From, |
82 | QualType &ToType, |
83 | bool InOverloadResolution, |
84 | StandardConversionSequence &SCS, |
85 | bool CStyle); |
86 | static OverloadingResult |
87 | IsUserDefinedConversion(Sema &S, Expr *From, QualType ToType, |
88 | UserDefinedConversionSequence& User, |
89 | OverloadCandidateSet& Conversions, |
90 | bool AllowExplicit, |
91 | bool AllowObjCConversionOnExplicit); |
92 | |
93 | |
94 | static ImplicitConversionSequence::CompareKind |
95 | CompareStandardConversionSequences(Sema &S, SourceLocation Loc, |
96 | const StandardConversionSequence& SCS1, |
97 | const StandardConversionSequence& SCS2); |
98 | |
99 | static ImplicitConversionSequence::CompareKind |
100 | CompareQualificationConversions(Sema &S, |
101 | const StandardConversionSequence& SCS1, |
102 | const StandardConversionSequence& SCS2); |
103 | |
104 | static ImplicitConversionSequence::CompareKind |
105 | CompareDerivedToBaseConversions(Sema &S, SourceLocation Loc, |
106 | const StandardConversionSequence& SCS1, |
107 | const StandardConversionSequence& SCS2); |
108 | |
109 | |
110 | |
111 | ImplicitConversionRank clang::GetConversionRank(ImplicitConversionKind Kind) { |
112 | static const ImplicitConversionRank |
113 | Rank[(int)ICK_Num_Conversion_Kinds] = { |
114 | ICR_Exact_Match, |
115 | ICR_Exact_Match, |
116 | ICR_Exact_Match, |
117 | ICR_Exact_Match, |
118 | ICR_Exact_Match, |
119 | ICR_Exact_Match, |
120 | ICR_Promotion, |
121 | ICR_Promotion, |
122 | ICR_Promotion, |
123 | ICR_Conversion, |
124 | ICR_Conversion, |
125 | ICR_Conversion, |
126 | ICR_Conversion, |
127 | ICR_Conversion, |
128 | ICR_Conversion, |
129 | ICR_Conversion, |
130 | ICR_Conversion, |
131 | ICR_Conversion, |
132 | ICR_Conversion, |
133 | ICR_OCL_Scalar_Widening, |
134 | ICR_Complex_Real_Conversion, |
135 | ICR_Conversion, |
136 | ICR_Conversion, |
137 | ICR_Writeback_Conversion, |
138 | ICR_Exact_Match, |
139 | |
140 | |
141 | ICR_C_Conversion, |
142 | ICR_C_Conversion_Extension |
143 | }; |
144 | return Rank[(int)Kind]; |
145 | } |
146 | |
147 | |
148 | |
149 | static const char* GetImplicitConversionName(ImplicitConversionKind Kind) { |
150 | static const char* const Name[(int)ICK_Num_Conversion_Kinds] = { |
151 | "No conversion", |
152 | "Lvalue-to-rvalue", |
153 | "Array-to-pointer", |
154 | "Function-to-pointer", |
155 | "Function pointer conversion", |
156 | "Qualification", |
157 | "Integral promotion", |
158 | "Floating point promotion", |
159 | "Complex promotion", |
160 | "Integral conversion", |
161 | "Floating conversion", |
162 | "Complex conversion", |
163 | "Floating-integral conversion", |
164 | "Pointer conversion", |
165 | "Pointer-to-member conversion", |
166 | "Boolean conversion", |
167 | "Compatible-types conversion", |
168 | "Derived-to-base conversion", |
169 | "Vector conversion", |
170 | "Vector splat", |
171 | "Complex-real conversion", |
172 | "Block Pointer conversion", |
173 | "Transparent Union Conversion", |
174 | "Writeback conversion", |
175 | "OpenCL Zero Event Conversion", |
176 | "C specific type conversion", |
177 | "Incompatible pointer conversion" |
178 | }; |
179 | return Name[Kind]; |
180 | } |
181 | |
182 | |
183 | |
184 | void StandardConversionSequence::setAsIdentityConversion() { |
185 | First = ICK_Identity; |
186 | Second = ICK_Identity; |
187 | Third = ICK_Identity; |
188 | DeprecatedStringLiteralToCharPtr = false; |
189 | QualificationIncludesObjCLifetime = false; |
190 | ReferenceBinding = false; |
191 | DirectBinding = false; |
192 | IsLvalueReference = true; |
193 | BindsToFunctionLvalue = false; |
194 | BindsToRvalue = false; |
195 | BindsImplicitObjectArgumentWithoutRefQualifier = false; |
196 | ObjCLifetimeConversionBinding = false; |
197 | CopyConstructor = nullptr; |
198 | } |
199 | |
200 | |
201 | |
202 | |
203 | ImplicitConversionRank StandardConversionSequence::getRank() const { |
204 | ImplicitConversionRank Rank = ICR_Exact_Match; |
205 | if (GetConversionRank(First) > Rank) |
206 | Rank = GetConversionRank(First); |
207 | if (GetConversionRank(Second) > Rank) |
208 | Rank = GetConversionRank(Second); |
209 | if (GetConversionRank(Third) > Rank) |
210 | Rank = GetConversionRank(Third); |
211 | return Rank; |
212 | } |
213 | |
214 | |
215 | |
216 | |
217 | |
218 | bool StandardConversionSequence::isPointerConversionToBool() const { |
219 | |
220 | |
221 | |
222 | |
223 | if (getToType(1)->isBooleanType() && |
224 | (getFromType()->isPointerType() || |
225 | getFromType()->isMemberPointerType() || |
226 | getFromType()->isObjCObjectPointerType() || |
227 | getFromType()->isBlockPointerType() || |
228 | getFromType()->isNullPtrType() || |
229 | First == ICK_Array_To_Pointer || First == ICK_Function_To_Pointer)) |
230 | return true; |
231 | |
232 | return false; |
233 | } |
234 | |
235 | |
236 | |
237 | |
238 | |
239 | bool |
240 | StandardConversionSequence:: |
241 | isPointerConversionToVoidPointer(ASTContext& Context) const { |
242 | QualType FromType = getFromType(); |
243 | QualType ToType = getToType(1); |
244 | |
245 | |
246 | |
247 | |
248 | if (First == ICK_Array_To_Pointer) |
249 | FromType = Context.getArrayDecayedType(FromType); |
250 | |
251 | if (Second == ICK_Pointer_Conversion && FromType->isAnyPointerType()) |
252 | if (const PointerType* ToPtrType = ToType->getAs<PointerType>()) |
253 | return ToPtrType->getPointeeType()->isVoidType(); |
254 | |
255 | return false; |
256 | } |
257 | |
258 | |
259 | |
260 | static const Expr *IgnoreNarrowingConversion(const Expr *Converted) { |
261 | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Converted)) { |
262 | switch (ICE->getCastKind()) { |
263 | case CK_NoOp: |
264 | case CK_IntegralCast: |
265 | case CK_IntegralToBoolean: |
266 | case CK_IntegralToFloating: |
267 | case CK_BooleanToSignedIntegral: |
268 | case CK_FloatingToIntegral: |
269 | case CK_FloatingToBoolean: |
270 | case CK_FloatingCast: |
271 | Converted = ICE->getSubExpr(); |
272 | continue; |
273 | |
274 | default: |
275 | return Converted; |
276 | } |
277 | } |
278 | |
279 | return Converted; |
280 | } |
281 | |
282 | |
283 | |
284 | |
285 | |
286 | |
287 | |
288 | |
289 | |
290 | |
291 | |
292 | |
293 | NarrowingKind StandardConversionSequence::getNarrowingKind( |
294 | ASTContext &Ctx, const Expr *Converted, APValue &ConstantValue, |
295 | QualType &ConstantType, bool IgnoreFloatToIntegralConversion) const { |
296 | (0) . __assert_fail ("Ctx.getLangOpts().CPlusPlus && \"narrowing check outside C++\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 296, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Ctx.getLangOpts().CPlusPlus && "narrowing check outside C++"); |
297 | |
298 | |
299 | |
300 | QualType FromType = getToType(0); |
301 | QualType ToType = getToType(1); |
302 | |
303 | |
304 | |
305 | |
306 | if (auto *ET = ToType->getAs<EnumType>()) |
307 | ToType = ET->getDecl()->getIntegerType(); |
308 | |
309 | switch (Second) { |
310 | |
311 | case ICK_Boolean_Conversion: |
312 | if (FromType->isRealFloatingType()) |
313 | goto FloatingIntegralConversion; |
314 | if (FromType->isIntegralOrUnscopedEnumerationType()) |
315 | goto IntegralConversion; |
316 | |
317 | |
318 | return NK_Not_Narrowing; |
319 | |
320 | |
321 | |
322 | |
323 | |
324 | |
325 | |
326 | case ICK_Floating_Integral: |
327 | FloatingIntegralConversion: |
328 | if (FromType->isRealFloatingType() && ToType->isIntegralType(Ctx)) { |
329 | return NK_Type_Narrowing; |
330 | } else if (FromType->isIntegralOrUnscopedEnumerationType() && |
331 | ToType->isRealFloatingType()) { |
332 | if (IgnoreFloatToIntegralConversion) |
333 | return NK_Not_Narrowing; |
334 | llvm::APSInt IntConstantValue; |
335 | const Expr *Initializer = IgnoreNarrowingConversion(Converted); |
336 | (0) . __assert_fail ("Initializer && \"Unknown conversion expression\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 336, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Initializer && "Unknown conversion expression"); |
337 | |
338 | |
339 | if (Initializer->isValueDependent()) |
340 | return NK_Dependent_Narrowing; |
341 | |
342 | if (Initializer->isIntegerConstantExpr(IntConstantValue, Ctx)) { |
343 | |
344 | llvm::APFloat Result(Ctx.getFloatTypeSemantics(ToType)); |
345 | Result.convertFromAPInt(IntConstantValue, IntConstantValue.isSigned(), |
346 | llvm::APFloat::rmNearestTiesToEven); |
347 | |
348 | llvm::APSInt ConvertedValue = IntConstantValue; |
349 | bool ignored; |
350 | Result.convertToInteger(ConvertedValue, |
351 | llvm::APFloat::rmTowardZero, &ignored); |
352 | |
353 | if (IntConstantValue != ConvertedValue) { |
354 | ConstantValue = APValue(IntConstantValue); |
355 | ConstantType = Initializer->getType(); |
356 | return NK_Constant_Narrowing; |
357 | } |
358 | } else { |
359 | |
360 | return NK_Variable_Narrowing; |
361 | } |
362 | } |
363 | return NK_Not_Narrowing; |
364 | |
365 | |
366 | |
367 | |
368 | |
369 | case ICK_Floating_Conversion: |
370 | if (FromType->isRealFloatingType() && ToType->isRealFloatingType() && |
371 | Ctx.getFloatingTypeOrder(FromType, ToType) == 1) { |
372 | |
373 | const Expr *Initializer = IgnoreNarrowingConversion(Converted); |
374 | |
375 | |
376 | if (Initializer->isValueDependent()) |
377 | return NK_Dependent_Narrowing; |
378 | |
379 | if (Initializer->isCXX11ConstantExpr(Ctx, &ConstantValue)) { |
380 | |
381 | assert(ConstantValue.isFloat()); |
382 | llvm::APFloat FloatVal = ConstantValue.getFloat(); |
383 | |
384 | bool ignored; |
385 | llvm::APFloat::opStatus ConvertStatus = FloatVal.convert( |
386 | Ctx.getFloatTypeSemantics(ToType), |
387 | llvm::APFloat::rmNearestTiesToEven, &ignored); |
388 | |
389 | |
390 | if (ConvertStatus & llvm::APFloat::opOverflow) { |
391 | ConstantType = Initializer->getType(); |
392 | return NK_Constant_Narrowing; |
393 | } |
394 | } else { |
395 | return NK_Variable_Narrowing; |
396 | } |
397 | } |
398 | return NK_Not_Narrowing; |
399 | |
400 | |
401 | |
402 | |
403 | |
404 | |
405 | case ICK_Integral_Conversion: |
406 | IntegralConversion: { |
407 | isIntegralOrUnscopedEnumerationType()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 407, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(FromType->isIntegralOrUnscopedEnumerationType()); |
408 | isIntegralOrUnscopedEnumerationType()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 408, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ToType->isIntegralOrUnscopedEnumerationType()); |
409 | const bool FromSigned = FromType->isSignedIntegerOrEnumerationType(); |
410 | const unsigned FromWidth = Ctx.getIntWidth(FromType); |
411 | const bool ToSigned = ToType->isSignedIntegerOrEnumerationType(); |
412 | const unsigned ToWidth = Ctx.getIntWidth(ToType); |
413 | |
414 | if (FromWidth > ToWidth || |
415 | (FromWidth == ToWidth && FromSigned != ToSigned) || |
416 | (FromSigned && !ToSigned)) { |
417 | |
418 | llvm::APSInt InitializerValue; |
419 | const Expr *Initializer = IgnoreNarrowingConversion(Converted); |
420 | |
421 | |
422 | if (Initializer->isValueDependent()) |
423 | return NK_Dependent_Narrowing; |
424 | |
425 | if (!Initializer->isIntegerConstantExpr(InitializerValue, Ctx)) { |
426 | |
427 | return NK_Variable_Narrowing; |
428 | } |
429 | bool Narrowing = false; |
430 | if (FromWidth < ToWidth) { |
431 | |
432 | |
433 | if (InitializerValue.isSigned() && InitializerValue.isNegative()) |
434 | Narrowing = true; |
435 | } else { |
436 | |
437 | |
438 | InitializerValue = InitializerValue.extend( |
439 | InitializerValue.getBitWidth() + 1); |
440 | |
441 | llvm::APSInt ConvertedValue = InitializerValue; |
442 | ConvertedValue = ConvertedValue.trunc(ToWidth); |
443 | ConvertedValue.setIsSigned(ToSigned); |
444 | ConvertedValue = ConvertedValue.extend(InitializerValue.getBitWidth()); |
445 | ConvertedValue.setIsSigned(InitializerValue.isSigned()); |
446 | |
447 | if (ConvertedValue != InitializerValue) |
448 | Narrowing = true; |
449 | } |
450 | if (Narrowing) { |
451 | ConstantType = Initializer->getType(); |
452 | ConstantValue = APValue(InitializerValue); |
453 | return NK_Constant_Narrowing; |
454 | } |
455 | } |
456 | return NK_Not_Narrowing; |
457 | } |
458 | |
459 | default: |
460 | |
461 | return NK_Not_Narrowing; |
462 | } |
463 | } |
464 | |
465 | |
466 | |
467 | LLVM_DUMP_METHOD void StandardConversionSequence::dump() const { |
468 | raw_ostream &OS = llvm::errs(); |
469 | bool PrintedSomething = false; |
470 | if (First != ICK_Identity) { |
471 | OS << GetImplicitConversionName(First); |
472 | PrintedSomething = true; |
473 | } |
474 | |
475 | if (Second != ICK_Identity) { |
476 | if (PrintedSomething) { |
477 | OS << " -> "; |
478 | } |
479 | OS << GetImplicitConversionName(Second); |
480 | |
481 | if (CopyConstructor) { |
482 | OS << " (by copy constructor)"; |
483 | } else if (DirectBinding) { |
484 | OS << " (direct reference binding)"; |
485 | } else if (ReferenceBinding) { |
486 | OS << " (reference binding)"; |
487 | } |
488 | PrintedSomething = true; |
489 | } |
490 | |
491 | if (Third != ICK_Identity) { |
492 | if (PrintedSomething) { |
493 | OS << " -> "; |
494 | } |
495 | OS << GetImplicitConversionName(Third); |
496 | PrintedSomething = true; |
497 | } |
498 | |
499 | if (!PrintedSomething) { |
500 | OS << "No conversions required"; |
501 | } |
502 | } |
503 | |
504 | |
505 | |
506 | void UserDefinedConversionSequence::dump() const { |
507 | raw_ostream &OS = llvm::errs(); |
508 | if (Before.First || Before.Second || Before.Third) { |
509 | Before.dump(); |
510 | OS << " -> "; |
511 | } |
512 | if (ConversionFunction) |
513 | OS << '\'' << *ConversionFunction << '\''; |
514 | else |
515 | OS << "aggregate initialization"; |
516 | if (After.First || After.Second || After.Third) { |
517 | OS << " -> "; |
518 | After.dump(); |
519 | } |
520 | } |
521 | |
522 | |
523 | |
524 | void ImplicitConversionSequence::dump() const { |
525 | raw_ostream &OS = llvm::errs(); |
526 | if (isStdInitializerListElement()) |
527 | OS << "Worst std::initializer_list element conversion: "; |
528 | switch (ConversionKind) { |
529 | case StandardConversion: |
530 | OS << "Standard conversion: "; |
531 | Standard.dump(); |
532 | break; |
533 | case UserDefinedConversion: |
534 | OS << "User-defined conversion: "; |
535 | UserDefined.dump(); |
536 | break; |
537 | case EllipsisConversion: |
538 | OS << "Ellipsis conversion"; |
539 | break; |
540 | case AmbiguousConversion: |
541 | OS << "Ambiguous conversion"; |
542 | break; |
543 | case BadConversion: |
544 | OS << "Bad conversion"; |
545 | break; |
546 | } |
547 | |
548 | OS << "\n"; |
549 | } |
550 | |
551 | void AmbiguousConversionSequence::construct() { |
552 | new (&conversions()) ConversionSet(); |
553 | } |
554 | |
555 | void AmbiguousConversionSequence::destruct() { |
556 | conversions().~ConversionSet(); |
557 | } |
558 | |
559 | void |
560 | AmbiguousConversionSequence::copyFrom(const AmbiguousConversionSequence &O) { |
561 | FromTypePtr = O.FromTypePtr; |
562 | ToTypePtr = O.ToTypePtr; |
563 | new (&conversions()) ConversionSet(O.conversions()); |
564 | } |
565 | |
566 | namespace { |
567 | |
568 | |
569 | struct DFIArguments { |
570 | TemplateArgument FirstArg; |
571 | TemplateArgument SecondArg; |
572 | }; |
573 | |
574 | |
575 | struct DFIParamWithArguments : DFIArguments { |
576 | TemplateParameter Param; |
577 | }; |
578 | |
579 | |
580 | struct DFIDeducedMismatchArgs : DFIArguments { |
581 | TemplateArgumentList *TemplateArgs; |
582 | unsigned CallArgIndex; |
583 | }; |
584 | } |
585 | |
586 | |
587 | |
588 | DeductionFailureInfo |
589 | clang::MakeDeductionFailureInfo(ASTContext &Context, |
590 | Sema::TemplateDeductionResult TDK, |
591 | TemplateDeductionInfo &Info) { |
592 | DeductionFailureInfo Result; |
593 | Result.Result = static_cast<unsigned>(TDK); |
594 | Result.HasDiagnostic = false; |
595 | switch (TDK) { |
596 | case Sema::TDK_Invalid: |
597 | case Sema::TDK_InstantiationDepth: |
598 | case Sema::TDK_TooManyArguments: |
599 | case Sema::TDK_TooFewArguments: |
600 | case Sema::TDK_MiscellaneousDeductionFailure: |
601 | case Sema::TDK_CUDATargetMismatch: |
602 | Result.Data = nullptr; |
603 | break; |
604 | |
605 | case Sema::TDK_Incomplete: |
606 | case Sema::TDK_InvalidExplicitArguments: |
607 | Result.Data = Info.Param.getOpaqueValue(); |
608 | break; |
609 | |
610 | case Sema::TDK_DeducedMismatch: |
611 | case Sema::TDK_DeducedMismatchNested: { |
612 | |
613 | auto *Saved = new (Context) DFIDeducedMismatchArgs; |
614 | Saved->FirstArg = Info.FirstArg; |
615 | Saved->SecondArg = Info.SecondArg; |
616 | Saved->TemplateArgs = Info.take(); |
617 | Saved->CallArgIndex = Info.CallArgIndex; |
618 | Result.Data = Saved; |
619 | break; |
620 | } |
621 | |
622 | case Sema::TDK_NonDeducedMismatch: { |
623 | |
624 | DFIArguments *Saved = new (Context) DFIArguments; |
625 | Saved->FirstArg = Info.FirstArg; |
626 | Saved->SecondArg = Info.SecondArg; |
627 | Result.Data = Saved; |
628 | break; |
629 | } |
630 | |
631 | case Sema::TDK_IncompletePack: |
632 | |
633 | case Sema::TDK_Inconsistent: |
634 | case Sema::TDK_Underqualified: { |
635 | |
636 | DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments; |
637 | Saved->Param = Info.Param; |
638 | Saved->FirstArg = Info.FirstArg; |
639 | Saved->SecondArg = Info.SecondArg; |
640 | Result.Data = Saved; |
641 | break; |
642 | } |
643 | |
644 | case Sema::TDK_SubstitutionFailure: |
645 | Result.Data = Info.take(); |
646 | if (Info.hasSFINAEDiagnostic()) { |
647 | PartialDiagnosticAt *Diag = new (Result.Diagnostic) PartialDiagnosticAt( |
648 | SourceLocation(), PartialDiagnostic::NullDiagnostic()); |
649 | Info.takeSFINAEDiagnostic(*Diag); |
650 | Result.HasDiagnostic = true; |
651 | } |
652 | break; |
653 | |
654 | case Sema::TDK_Success: |
655 | case Sema::TDK_NonDependentConversionFailure: |
656 | llvm_unreachable("not a deduction failure"); |
657 | } |
658 | |
659 | return Result; |
660 | } |
661 | |
662 | void DeductionFailureInfo::Destroy() { |
663 | switch (static_cast<Sema::TemplateDeductionResult>(Result)) { |
664 | case Sema::TDK_Success: |
665 | case Sema::TDK_Invalid: |
666 | case Sema::TDK_InstantiationDepth: |
667 | case Sema::TDK_Incomplete: |
668 | case Sema::TDK_TooManyArguments: |
669 | case Sema::TDK_TooFewArguments: |
670 | case Sema::TDK_InvalidExplicitArguments: |
671 | case Sema::TDK_CUDATargetMismatch: |
672 | case Sema::TDK_NonDependentConversionFailure: |
673 | break; |
674 | |
675 | case Sema::TDK_IncompletePack: |
676 | case Sema::TDK_Inconsistent: |
677 | case Sema::TDK_Underqualified: |
678 | case Sema::TDK_DeducedMismatch: |
679 | case Sema::TDK_DeducedMismatchNested: |
680 | case Sema::TDK_NonDeducedMismatch: |
681 | |
682 | Data = nullptr; |
683 | break; |
684 | |
685 | case Sema::TDK_SubstitutionFailure: |
686 | |
687 | Data = nullptr; |
688 | if (PartialDiagnosticAt *Diag = getSFINAEDiagnostic()) { |
689 | Diag->~PartialDiagnosticAt(); |
690 | HasDiagnostic = false; |
691 | } |
692 | break; |
693 | |
694 | |
695 | case Sema::TDK_MiscellaneousDeductionFailure: |
696 | break; |
697 | } |
698 | } |
699 | |
700 | PartialDiagnosticAt *DeductionFailureInfo::getSFINAEDiagnostic() { |
701 | if (HasDiagnostic) |
702 | return static_cast<PartialDiagnosticAt*>(static_cast<void*>(Diagnostic)); |
703 | return nullptr; |
704 | } |
705 | |
706 | TemplateParameter DeductionFailureInfo::getTemplateParameter() { |
707 | switch (static_cast<Sema::TemplateDeductionResult>(Result)) { |
708 | case Sema::TDK_Success: |
709 | case Sema::TDK_Invalid: |
710 | case Sema::TDK_InstantiationDepth: |
711 | case Sema::TDK_TooManyArguments: |
712 | case Sema::TDK_TooFewArguments: |
713 | case Sema::TDK_SubstitutionFailure: |
714 | case Sema::TDK_DeducedMismatch: |
715 | case Sema::TDK_DeducedMismatchNested: |
716 | case Sema::TDK_NonDeducedMismatch: |
717 | case Sema::TDK_CUDATargetMismatch: |
718 | case Sema::TDK_NonDependentConversionFailure: |
719 | return TemplateParameter(); |
720 | |
721 | case Sema::TDK_Incomplete: |
722 | case Sema::TDK_InvalidExplicitArguments: |
723 | return TemplateParameter::getFromOpaqueValue(Data); |
724 | |
725 | case Sema::TDK_IncompletePack: |
726 | case Sema::TDK_Inconsistent: |
727 | case Sema::TDK_Underqualified: |
728 | return static_cast<DFIParamWithArguments*>(Data)->Param; |
729 | |
730 | |
731 | case Sema::TDK_MiscellaneousDeductionFailure: |
732 | break; |
733 | } |
734 | |
735 | return TemplateParameter(); |
736 | } |
737 | |
738 | TemplateArgumentList *DeductionFailureInfo::getTemplateArgumentList() { |
739 | switch (static_cast<Sema::TemplateDeductionResult>(Result)) { |
740 | case Sema::TDK_Success: |
741 | case Sema::TDK_Invalid: |
742 | case Sema::TDK_InstantiationDepth: |
743 | case Sema::TDK_TooManyArguments: |
744 | case Sema::TDK_TooFewArguments: |
745 | case Sema::TDK_Incomplete: |
746 | case Sema::TDK_IncompletePack: |
747 | case Sema::TDK_InvalidExplicitArguments: |
748 | case Sema::TDK_Inconsistent: |
749 | case Sema::TDK_Underqualified: |
750 | case Sema::TDK_NonDeducedMismatch: |
751 | case Sema::TDK_CUDATargetMismatch: |
752 | case Sema::TDK_NonDependentConversionFailure: |
753 | return nullptr; |
754 | |
755 | case Sema::TDK_DeducedMismatch: |
756 | case Sema::TDK_DeducedMismatchNested: |
757 | return static_cast<DFIDeducedMismatchArgs*>(Data)->TemplateArgs; |
758 | |
759 | case Sema::TDK_SubstitutionFailure: |
760 | return static_cast<TemplateArgumentList*>(Data); |
761 | |
762 | |
763 | case Sema::TDK_MiscellaneousDeductionFailure: |
764 | break; |
765 | } |
766 | |
767 | return nullptr; |
768 | } |
769 | |
770 | const TemplateArgument *DeductionFailureInfo::getFirstArg() { |
771 | switch (static_cast<Sema::TemplateDeductionResult>(Result)) { |
772 | case Sema::TDK_Success: |
773 | case Sema::TDK_Invalid: |
774 | case Sema::TDK_InstantiationDepth: |
775 | case Sema::TDK_Incomplete: |
776 | case Sema::TDK_TooManyArguments: |
777 | case Sema::TDK_TooFewArguments: |
778 | case Sema::TDK_InvalidExplicitArguments: |
779 | case Sema::TDK_SubstitutionFailure: |
780 | case Sema::TDK_CUDATargetMismatch: |
781 | case Sema::TDK_NonDependentConversionFailure: |
782 | return nullptr; |
783 | |
784 | case Sema::TDK_IncompletePack: |
785 | case Sema::TDK_Inconsistent: |
786 | case Sema::TDK_Underqualified: |
787 | case Sema::TDK_DeducedMismatch: |
788 | case Sema::TDK_DeducedMismatchNested: |
789 | case Sema::TDK_NonDeducedMismatch: |
790 | return &static_cast<DFIArguments*>(Data)->FirstArg; |
791 | |
792 | |
793 | case Sema::TDK_MiscellaneousDeductionFailure: |
794 | break; |
795 | } |
796 | |
797 | return nullptr; |
798 | } |
799 | |
800 | const TemplateArgument *DeductionFailureInfo::getSecondArg() { |
801 | switch (static_cast<Sema::TemplateDeductionResult>(Result)) { |
802 | case Sema::TDK_Success: |
803 | case Sema::TDK_Invalid: |
804 | case Sema::TDK_InstantiationDepth: |
805 | case Sema::TDK_Incomplete: |
806 | case Sema::TDK_IncompletePack: |
807 | case Sema::TDK_TooManyArguments: |
808 | case Sema::TDK_TooFewArguments: |
809 | case Sema::TDK_InvalidExplicitArguments: |
810 | case Sema::TDK_SubstitutionFailure: |
811 | case Sema::TDK_CUDATargetMismatch: |
812 | case Sema::TDK_NonDependentConversionFailure: |
813 | return nullptr; |
814 | |
815 | case Sema::TDK_Inconsistent: |
816 | case Sema::TDK_Underqualified: |
817 | case Sema::TDK_DeducedMismatch: |
818 | case Sema::TDK_DeducedMismatchNested: |
819 | case Sema::TDK_NonDeducedMismatch: |
820 | return &static_cast<DFIArguments*>(Data)->SecondArg; |
821 | |
822 | |
823 | case Sema::TDK_MiscellaneousDeductionFailure: |
824 | break; |
825 | } |
826 | |
827 | return nullptr; |
828 | } |
829 | |
830 | llvm::Optional<unsigned> DeductionFailureInfo::getCallArgIndex() { |
831 | switch (static_cast<Sema::TemplateDeductionResult>(Result)) { |
832 | case Sema::TDK_DeducedMismatch: |
833 | case Sema::TDK_DeducedMismatchNested: |
834 | return static_cast<DFIDeducedMismatchArgs*>(Data)->CallArgIndex; |
835 | |
836 | default: |
837 | return llvm::None; |
838 | } |
839 | } |
840 | |
841 | void OverloadCandidateSet::destroyCandidates() { |
842 | for (iterator i = begin(), e = end(); i != e; ++i) { |
843 | for (auto &C : i->Conversions) |
844 | C.~ImplicitConversionSequence(); |
845 | if (!i->Viable && i->FailureKind == ovl_fail_bad_deduction) |
846 | i->DeductionFailure.Destroy(); |
847 | } |
848 | } |
849 | |
850 | void OverloadCandidateSet::clear(CandidateSetKind CSK) { |
851 | destroyCandidates(); |
852 | SlabAllocator.Reset(); |
853 | NumInlineBytesUsed = 0; |
854 | Candidates.clear(); |
855 | Functions.clear(); |
856 | Kind = CSK; |
857 | } |
858 | |
859 | namespace { |
860 | class UnbridgedCastsSet { |
861 | struct Entry { |
862 | Expr **Addr; |
863 | Expr *Saved; |
864 | }; |
865 | SmallVector<Entry, 2> Entries; |
866 | |
867 | public: |
868 | void save(Sema &S, Expr *&E) { |
869 | hasPlaceholderType(BuiltinType..ARCUnbridgedCast)", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 869, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(E->hasPlaceholderType(BuiltinType::ARCUnbridgedCast)); |
870 | Entry entry = { &E, E }; |
871 | Entries.push_back(entry); |
872 | E = S.stripARCUnbridgedCast(E); |
873 | } |
874 | |
875 | void restore() { |
876 | for (SmallVectorImpl<Entry>::iterator |
877 | i = Entries.begin(), e = Entries.end(); i != e; ++i) |
878 | *i->Addr = i->Saved; |
879 | } |
880 | }; |
881 | } |
882 | |
883 | |
884 | |
885 | |
886 | |
887 | |
888 | |
889 | |
890 | static bool |
891 | checkPlaceholderForOverload(Sema &S, Expr *&E, |
892 | UnbridgedCastsSet *unbridgedCasts = nullptr) { |
893 | if (const BuiltinType *placeholder = E->getType()->getAsPlaceholderType()) { |
894 | |
895 | |
896 | if (placeholder->getKind() == BuiltinType::Overload) return false; |
897 | |
898 | |
899 | |
900 | if (placeholder->getKind() == BuiltinType::ARCUnbridgedCast && |
901 | unbridgedCasts) { |
902 | unbridgedCasts->save(S, E); |
903 | return false; |
904 | } |
905 | |
906 | |
907 | ExprResult result = S.CheckPlaceholderExpr(E); |
908 | if (result.isInvalid()) |
909 | return true; |
910 | |
911 | E = result.get(); |
912 | return false; |
913 | } |
914 | |
915 | |
916 | return false; |
917 | } |
918 | |
919 | |
920 | |
921 | static bool checkArgPlaceholdersForOverload(Sema &S, |
922 | MultiExprArg Args, |
923 | UnbridgedCastsSet &unbridged) { |
924 | for (unsigned i = 0, e = Args.size(); i != e; ++i) |
925 | if (checkPlaceholderForOverload(S, Args[i], &unbridged)) |
926 | return true; |
927 | |
928 | return false; |
929 | } |
930 | |
931 | |
932 | |
933 | |
934 | |
935 | |
936 | |
937 | |
938 | |
939 | |
940 | |
941 | |
942 | |
943 | |
944 | |
945 | |
946 | |
947 | |
948 | |
949 | |
950 | |
951 | |
952 | |
953 | |
954 | |
955 | |
956 | |
957 | |
958 | |
959 | |
960 | |
961 | |
962 | |
963 | |
964 | Sema::OverloadKind |
965 | Sema::CheckOverload(Scope *S, FunctionDecl *New, const LookupResult &Old, |
966 | NamedDecl *&Match, bool NewIsUsingDecl) { |
967 | for (LookupResult::iterator I = Old.begin(), E = Old.end(); |
968 | I != E; ++I) { |
969 | NamedDecl *OldD = *I; |
970 | |
971 | bool OldIsUsingDecl = false; |
972 | if (isa<UsingShadowDecl>(OldD)) { |
973 | OldIsUsingDecl = true; |
974 | |
975 | |
976 | |
977 | if (NewIsUsingDecl) continue; |
978 | |
979 | OldD = cast<UsingShadowDecl>(OldD)->getTargetDecl(); |
980 | } |
981 | |
982 | |
983 | |
984 | if ((OldIsUsingDecl || NewIsUsingDecl) && !isVisible(*I)) |
985 | continue; |
986 | |
987 | |
988 | |
989 | |
990 | |
991 | |
992 | bool UseMemberUsingDeclRules = |
993 | (OldIsUsingDecl || NewIsUsingDecl) && CurContext->isRecord() && |
994 | !New->getFriendObjectKind(); |
995 | |
996 | if (FunctionDecl *OldF = OldD->getAsFunction()) { |
997 | if (!IsOverload(New, OldF, UseMemberUsingDeclRules)) { |
998 | if (UseMemberUsingDeclRules && OldIsUsingDecl) { |
999 | HideUsingShadowDecl(S, cast<UsingShadowDecl>(*I)); |
1000 | continue; |
1001 | } |
1002 | |
1003 | if (!isa<FunctionTemplateDecl>(OldD) && |
1004 | !shouldLinkPossiblyHiddenDecl(*I, New)) |
1005 | continue; |
1006 | |
1007 | Match = *I; |
1008 | return Ovl_Match; |
1009 | } |
1010 | |
1011 | |
1012 | |
1013 | if (!getASTContext().canBuiltinBeRedeclared(OldF)) { |
1014 | Match = *I; |
1015 | return Ovl_NonFunction; |
1016 | } |
1017 | } else if (isa<UsingDecl>(OldD) || isa<UsingPackDecl>(OldD)) { |
1018 | |
1019 | |
1020 | assert(Old.getLookupKind() == LookupUsingDeclName); |
1021 | } else if (isa<TagDecl>(OldD)) { |
1022 | |
1023 | } else if (auto *UUD = dyn_cast<UnresolvedUsingValueDecl>(OldD)) { |
1024 | |
1025 | |
1026 | |
1027 | |
1028 | |
1029 | |
1030 | if (UUD->getQualifier()->isDependent() && !UUD->isCXXClassMember()) { |
1031 | Match = *I; |
1032 | return Ovl_NonFunction; |
1033 | } |
1034 | } else { |
1035 | |
1036 | |
1037 | |
1038 | Match = *I; |
1039 | return Ovl_NonFunction; |
1040 | } |
1041 | } |
1042 | |
1043 | |
1044 | |
1045 | |
1046 | |
1047 | |
1048 | |
1049 | |
1050 | |
1051 | |
1052 | |
1053 | |
1054 | |
1055 | |
1056 | |
1057 | |
1058 | if (New->getFriendObjectKind() && New->getQualifier() && |
1059 | !New->getDependentSpecializationInfo() && |
1060 | !New->getType()->isDependentType()) { |
1061 | LookupResult TemplateSpecResult(LookupResult::Temporary, Old); |
1062 | TemplateSpecResult.addAllDecls(Old); |
1063 | if (CheckFunctionTemplateSpecialization(New, nullptr, TemplateSpecResult, |
1064 | )) { |
1065 | New->setInvalidDecl(); |
1066 | return Ovl_Overload; |
1067 | } |
1068 | |
1069 | Match = TemplateSpecResult.getAsSingle<FunctionDecl>(); |
1070 | return Ovl_Match; |
1071 | } |
1072 | |
1073 | return Ovl_Overload; |
1074 | } |
1075 | |
1076 | bool Sema::IsOverload(FunctionDecl *New, FunctionDecl *Old, |
1077 | bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs) { |
1078 | |
1079 | if (New->isMain()) |
1080 | return false; |
1081 | |
1082 | |
1083 | if (New->isMSVCRTEntryPoint()) |
1084 | return false; |
1085 | |
1086 | FunctionTemplateDecl *OldTemplate = Old->getDescribedFunctionTemplate(); |
1087 | FunctionTemplateDecl *NewTemplate = New->getDescribedFunctionTemplate(); |
1088 | |
1089 | |
1090 | |
1091 | |
1092 | if ((OldTemplate == nullptr) != (NewTemplate == nullptr)) |
1093 | return true; |
1094 | |
1095 | |
1096 | QualType OldQType = Context.getCanonicalType(Old->getType()); |
1097 | QualType NewQType = Context.getCanonicalType(New->getType()); |
1098 | |
1099 | |
1100 | |
1101 | |
1102 | |
1103 | |
1104 | |
1105 | if (isa<FunctionNoProtoType>(OldQType.getTypePtr()) || |
1106 | isa<FunctionNoProtoType>(NewQType.getTypePtr())) |
1107 | return false; |
1108 | |
1109 | const FunctionProtoType *OldType = cast<FunctionProtoType>(OldQType); |
1110 | const FunctionProtoType *NewType = cast<FunctionProtoType>(NewQType); |
1111 | |
1112 | |
1113 | |
1114 | |
1115 | if (OldQType != NewQType && |
1116 | (OldType->getNumParams() != NewType->getNumParams() || |
1117 | OldType->isVariadic() != NewType->isVariadic() || |
1118 | !FunctionParamTypesAreEqual(OldType, NewType))) |
1119 | return true; |
1120 | |
1121 | |
1122 | |
1123 | |
1124 | |
1125 | |
1126 | |
1127 | |
1128 | |
1129 | |
1130 | |
1131 | |
1132 | |
1133 | if (!UseMemberUsingDeclRules && NewTemplate && |
1134 | (!TemplateParameterListsAreEqual(NewTemplate->getTemplateParameters(), |
1135 | OldTemplate->getTemplateParameters(), |
1136 | false, TPL_TemplateMatch) || |
1137 | !Context.hasSameType(Old->getDeclaredReturnType(), |
1138 | New->getDeclaredReturnType()))) |
1139 | return true; |
1140 | |
1141 | |
1142 | |
1143 | |
1144 | |
1145 | |
1146 | |
1147 | |
1148 | |
1149 | CXXMethodDecl *OldMethod = dyn_cast<CXXMethodDecl>(Old); |
1150 | CXXMethodDecl *NewMethod = dyn_cast<CXXMethodDecl>(New); |
1151 | if (OldMethod && NewMethod && |
1152 | !OldMethod->isStatic() && !NewMethod->isStatic()) { |
1153 | if (OldMethod->getRefQualifier() != NewMethod->getRefQualifier()) { |
1154 | if (!UseMemberUsingDeclRules && |
1155 | (OldMethod->getRefQualifier() == RQ_None || |
1156 | NewMethod->getRefQualifier() == RQ_None)) { |
1157 | |
1158 | |
1159 | |
1160 | |
1161 | |
1162 | |
1163 | Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload) |
1164 | << NewMethod->getRefQualifier() << OldMethod->getRefQualifier(); |
1165 | Diag(OldMethod->getLocation(), diag::note_previous_declaration); |
1166 | } |
1167 | return true; |
1168 | } |
1169 | |
1170 | |
1171 | |
1172 | |
1173 | |
1174 | auto OldQuals = OldMethod->getMethodQualifiers(); |
1175 | auto NewQuals = NewMethod->getMethodQualifiers(); |
1176 | if (!getLangOpts().CPlusPlus14 && NewMethod->isConstexpr() && |
1177 | !isa<CXXConstructorDecl>(NewMethod)) |
1178 | NewQuals.addConst(); |
1179 | |
1180 | OldQuals.removeRestrict(); |
1181 | NewQuals.removeRestrict(); |
1182 | if (OldQuals != NewQuals) |
1183 | return true; |
1184 | } |
1185 | |
1186 | |
1187 | |
1188 | |
1189 | |
1190 | if (functionHasPassObjectSizeParams(New) != |
1191 | functionHasPassObjectSizeParams(Old)) |
1192 | return true; |
1193 | |
1194 | |
1195 | for (specific_attr_iterator<EnableIfAttr> |
1196 | NewI = New->specific_attr_begin<EnableIfAttr>(), |
1197 | NewE = New->specific_attr_end<EnableIfAttr>(), |
1198 | OldI = Old->specific_attr_begin<EnableIfAttr>(), |
1199 | OldE = Old->specific_attr_end<EnableIfAttr>(); |
1200 | NewI != NewE || OldI != OldE; ++NewI, ++OldI) { |
1201 | if (NewI == NewE || OldI == OldE) |
1202 | return true; |
1203 | llvm::FoldingSetNodeID NewID, OldID; |
1204 | NewI->getCond()->Profile(NewID, Context, true); |
1205 | OldI->getCond()->Profile(OldID, Context, true); |
1206 | if (NewID != OldID) |
1207 | return true; |
1208 | } |
1209 | |
1210 | if (getLangOpts().CUDA && ConsiderCudaAttrs) { |
1211 | |
1212 | |
1213 | if (isa<CXXDestructorDecl>(New)) |
1214 | return false; |
1215 | |
1216 | CUDAFunctionTarget NewTarget = IdentifyCUDATarget(New), |
1217 | OldTarget = IdentifyCUDATarget(Old); |
1218 | if (NewTarget == CFT_InvalidTarget) |
1219 | return false; |
1220 | |
1221 | (0) . __assert_fail ("(OldTarget != CFT_InvalidTarget) && \"Unexpected invalid target.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 1221, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((OldTarget != CFT_InvalidTarget) && "Unexpected invalid target."); |
1222 | |
1223 | |
1224 | |
1225 | return NewTarget != OldTarget; |
1226 | } |
1227 | |
1228 | |
1229 | return false; |
1230 | } |
1231 | |
1232 | |
1233 | |
1234 | |
1235 | |
1236 | static ImplicitConversionSequence |
1237 | TryUserDefinedConversion(Sema &S, Expr *From, QualType ToType, |
1238 | bool SuppressUserConversions, |
1239 | bool AllowExplicit, |
1240 | bool InOverloadResolution, |
1241 | bool CStyle, |
1242 | bool AllowObjCWritebackConversion, |
1243 | bool AllowObjCConversionOnExplicit) { |
1244 | ImplicitConversionSequence ICS; |
1245 | |
1246 | if (SuppressUserConversions) { |
1247 | |
1248 | |
1249 | ICS.setBad(BadConversionSequence::no_conversion, From, ToType); |
1250 | return ICS; |
1251 | } |
1252 | |
1253 | |
1254 | OverloadCandidateSet Conversions(From->getExprLoc(), |
1255 | OverloadCandidateSet::CSK_Normal); |
1256 | switch (IsUserDefinedConversion(S, From, ToType, ICS.UserDefined, |
1257 | Conversions, AllowExplicit, |
1258 | AllowObjCConversionOnExplicit)) { |
1259 | case OR_Success: |
1260 | case OR_Deleted: |
1261 | ICS.setUserDefined(); |
1262 | |
1263 | |
1264 | |
1265 | |
1266 | |
1267 | |
1268 | |
1269 | if (CXXConstructorDecl *Constructor |
1270 | = dyn_cast<CXXConstructorDecl>(ICS.UserDefined.ConversionFunction)) { |
1271 | QualType FromCanon |
1272 | = S.Context.getCanonicalType(From->getType().getUnqualifiedType()); |
1273 | QualType ToCanon |
1274 | = S.Context.getCanonicalType(ToType).getUnqualifiedType(); |
1275 | if (Constructor->isCopyConstructor() && |
1276 | (FromCanon == ToCanon || |
1277 | S.IsDerivedFrom(From->getBeginLoc(), FromCanon, ToCanon))) { |
1278 | |
1279 | |
1280 | DeclAccessPair Found = ICS.UserDefined.FoundConversionFunction; |
1281 | ICS.setStandard(); |
1282 | ICS.Standard.setAsIdentityConversion(); |
1283 | ICS.Standard.setFromType(From->getType()); |
1284 | ICS.Standard.setAllToTypes(ToType); |
1285 | ICS.Standard.CopyConstructor = Constructor; |
1286 | ICS.Standard.FoundCopyConstructor = Found; |
1287 | if (ToCanon != FromCanon) |
1288 | ICS.Standard.Second = ICK_Derived_To_Base; |
1289 | } |
1290 | } |
1291 | break; |
1292 | |
1293 | case OR_Ambiguous: |
1294 | ICS.setAmbiguous(); |
1295 | ICS.Ambiguous.setFromType(From->getType()); |
1296 | ICS.Ambiguous.setToType(ToType); |
1297 | for (OverloadCandidateSet::iterator Cand = Conversions.begin(); |
1298 | Cand != Conversions.end(); ++Cand) |
1299 | if (Cand->Viable) |
1300 | ICS.Ambiguous.addConversion(Cand->FoundDecl, Cand->Function); |
1301 | break; |
1302 | |
1303 | |
1304 | case OR_No_Viable_Function: |
1305 | ICS.setBad(BadConversionSequence::no_conversion, From, ToType); |
1306 | break; |
1307 | } |
1308 | |
1309 | return ICS; |
1310 | } |
1311 | |
1312 | |
1313 | |
1314 | |
1315 | |
1316 | |
1317 | |
1318 | |
1319 | |
1320 | |
1321 | |
1322 | |
1323 | |
1324 | |
1325 | |
1326 | |
1327 | |
1328 | |
1329 | |
1330 | |
1331 | |
1332 | |
1333 | |
1334 | |
1335 | |
1336 | |
1337 | |
1338 | |
1339 | static ImplicitConversionSequence |
1340 | TryImplicitConversion(Sema &S, Expr *From, QualType ToType, |
1341 | bool SuppressUserConversions, |
1342 | bool AllowExplicit, |
1343 | bool InOverloadResolution, |
1344 | bool CStyle, |
1345 | bool AllowObjCWritebackConversion, |
1346 | bool AllowObjCConversionOnExplicit) { |
1347 | ImplicitConversionSequence ICS; |
1348 | if (IsStandardConversion(S, From, ToType, InOverloadResolution, |
1349 | ICS.Standard, CStyle, AllowObjCWritebackConversion)){ |
1350 | ICS.setStandard(); |
1351 | return ICS; |
1352 | } |
1353 | |
1354 | if (!S.getLangOpts().CPlusPlus) { |
1355 | ICS.setBad(BadConversionSequence::no_conversion, From, ToType); |
1356 | return ICS; |
1357 | } |
1358 | |
1359 | |
1360 | |
1361 | |
1362 | |
1363 | |
1364 | |
1365 | |
1366 | QualType FromType = From->getType(); |
1367 | if (ToType->getAs<RecordType>() && FromType->getAs<RecordType>() && |
1368 | (S.Context.hasSameUnqualifiedType(FromType, ToType) || |
1369 | S.IsDerivedFrom(From->getBeginLoc(), FromType, ToType))) { |
1370 | ICS.setStandard(); |
1371 | ICS.Standard.setAsIdentityConversion(); |
1372 | ICS.Standard.setFromType(FromType); |
1373 | ICS.Standard.setAllToTypes(ToType); |
1374 | |
1375 | |
1376 | |
1377 | |
1378 | |
1379 | ICS.Standard.CopyConstructor = nullptr; |
1380 | |
1381 | |
1382 | if (!S.Context.hasSameUnqualifiedType(FromType, ToType)) |
1383 | ICS.Standard.Second = ICK_Derived_To_Base; |
1384 | |
1385 | return ICS; |
1386 | } |
1387 | |
1388 | return TryUserDefinedConversion(S, From, ToType, SuppressUserConversions, |
1389 | AllowExplicit, InOverloadResolution, CStyle, |
1390 | AllowObjCWritebackConversion, |
1391 | AllowObjCConversionOnExplicit); |
1392 | } |
1393 | |
1394 | ImplicitConversionSequence |
1395 | Sema::TryImplicitConversion(Expr *From, QualType ToType, |
1396 | bool SuppressUserConversions, |
1397 | bool AllowExplicit, |
1398 | bool InOverloadResolution, |
1399 | bool CStyle, |
1400 | bool AllowObjCWritebackConversion) { |
1401 | return ::TryImplicitConversion(*this, From, ToType, |
1402 | SuppressUserConversions, AllowExplicit, |
1403 | InOverloadResolution, CStyle, |
1404 | AllowObjCWritebackConversion, |
1405 | ); |
1406 | } |
1407 | |
1408 | |
1409 | |
1410 | |
1411 | |
1412 | |
1413 | ExprResult |
1414 | Sema::PerformImplicitConversion(Expr *From, QualType ToType, |
1415 | AssignmentAction Action, bool AllowExplicit) { |
1416 | ImplicitConversionSequence ICS; |
1417 | return PerformImplicitConversion(From, ToType, Action, AllowExplicit, ICS); |
1418 | } |
1419 | |
1420 | ExprResult |
1421 | Sema::PerformImplicitConversion(Expr *From, QualType ToType, |
1422 | AssignmentAction Action, bool AllowExplicit, |
1423 | ImplicitConversionSequence& ICS) { |
1424 | if (checkPlaceholderForOverload(*this, From)) |
1425 | return ExprError(); |
1426 | |
1427 | |
1428 | bool AllowObjCWritebackConversion |
1429 | = getLangOpts().ObjCAutoRefCount && |
1430 | (Action == AA_Passing || Action == AA_Sending); |
1431 | if (getLangOpts().ObjC) |
1432 | CheckObjCBridgeRelatedConversions(From->getBeginLoc(), ToType, |
1433 | From->getType(), From); |
1434 | ICS = ::TryImplicitConversion(*this, From, ToType, |
1435 | , |
1436 | AllowExplicit, |
1437 | , |
1438 | , |
1439 | AllowObjCWritebackConversion, |
1440 | ); |
1441 | return PerformImplicitConversion(From, ToType, ICS, Action); |
1442 | } |
1443 | |
1444 | |
1445 | |
1446 | |
1447 | bool Sema::IsFunctionConversion(QualType FromType, QualType ToType, |
1448 | QualType &ResultTy) { |
1449 | if (Context.hasSameUnqualifiedType(FromType, ToType)) |
1450 | return false; |
1451 | |
1452 | |
1453 | |
1454 | |
1455 | |
1456 | |
1457 | |
1458 | |
1459 | CanQualType CanTo = Context.getCanonicalType(ToType); |
1460 | CanQualType CanFrom = Context.getCanonicalType(FromType); |
1461 | Type::TypeClass TyClass = CanTo->getTypeClass(); |
1462 | if (TyClass != CanFrom->getTypeClass()) return false; |
1463 | if (TyClass != Type::FunctionProto && TyClass != Type::FunctionNoProto) { |
1464 | if (TyClass == Type::Pointer) { |
1465 | CanTo = CanTo.getAs<PointerType>()->getPointeeType(); |
1466 | CanFrom = CanFrom.getAs<PointerType>()->getPointeeType(); |
1467 | } else if (TyClass == Type::BlockPointer) { |
1468 | CanTo = CanTo.getAs<BlockPointerType>()->getPointeeType(); |
1469 | CanFrom = CanFrom.getAs<BlockPointerType>()->getPointeeType(); |
1470 | } else if (TyClass == Type::MemberPointer) { |
1471 | auto ToMPT = CanTo.getAs<MemberPointerType>(); |
1472 | auto FromMPT = CanFrom.getAs<MemberPointerType>(); |
1473 | |
1474 | if (ToMPT->getClass() != FromMPT->getClass()) |
1475 | return false; |
1476 | CanTo = ToMPT->getPointeeType(); |
1477 | CanFrom = FromMPT->getPointeeType(); |
1478 | } else { |
1479 | return false; |
1480 | } |
1481 | |
1482 | TyClass = CanTo->getTypeClass(); |
1483 | if (TyClass != CanFrom->getTypeClass()) return false; |
1484 | if (TyClass != Type::FunctionProto && TyClass != Type::FunctionNoProto) |
1485 | return false; |
1486 | } |
1487 | |
1488 | const auto *FromFn = cast<FunctionType>(CanFrom); |
1489 | FunctionType::ExtInfo FromEInfo = FromFn->getExtInfo(); |
1490 | |
1491 | const auto *ToFn = cast<FunctionType>(CanTo); |
1492 | FunctionType::ExtInfo ToEInfo = ToFn->getExtInfo(); |
1493 | |
1494 | bool Changed = false; |
1495 | |
1496 | |
1497 | if (FromEInfo.getNoReturn() && !ToEInfo.getNoReturn()) { |
1498 | FromFn = Context.adjustFunctionType(FromFn, FromEInfo.withNoReturn(false)); |
1499 | Changed = true; |
1500 | } |
1501 | |
1502 | |
1503 | if (const auto *FromFPT = dyn_cast<FunctionProtoType>(FromFn)) { |
1504 | const auto *ToFPT = cast<FunctionProtoType>(ToFn); |
1505 | if (FromFPT->isNothrow() && !ToFPT->isNothrow()) { |
1506 | FromFn = cast<FunctionType>( |
1507 | Context.getFunctionTypeWithExceptionSpec(QualType(FromFPT, 0), |
1508 | EST_None) |
1509 | .getTypePtr()); |
1510 | Changed = true; |
1511 | } |
1512 | |
1513 | |
1514 | |
1515 | |
1516 | SmallVector<FunctionProtoType::ExtParameterInfo, 4> NewParamInfos; |
1517 | bool CanUseToFPT, CanUseFromFPT; |
1518 | if (Context.mergeExtParameterInfo(ToFPT, FromFPT, CanUseToFPT, |
1519 | CanUseFromFPT, NewParamInfos) && |
1520 | CanUseToFPT && !CanUseFromFPT) { |
1521 | FunctionProtoType::ExtProtoInfo ExtInfo = FromFPT->getExtProtoInfo(); |
1522 | ExtInfo.ExtParameterInfos = |
1523 | NewParamInfos.empty() ? nullptr : NewParamInfos.data(); |
1524 | QualType QT = Context.getFunctionType(FromFPT->getReturnType(), |
1525 | FromFPT->getParamTypes(), ExtInfo); |
1526 | FromFn = QT->getAs<FunctionType>(); |
1527 | Changed = true; |
1528 | } |
1529 | } |
1530 | |
1531 | if (!Changed) |
1532 | return false; |
1533 | |
1534 | assert(QualType(FromFn, 0).isCanonical()); |
1535 | if (QualType(FromFn, 0) != CanTo) return false; |
1536 | |
1537 | ResultTy = ToType; |
1538 | return true; |
1539 | } |
1540 | |
1541 | |
1542 | |
1543 | |
1544 | |
1545 | |
1546 | static bool IsVectorConversion(Sema &S, QualType FromType, |
1547 | QualType ToType, ImplicitConversionKind &ICK) { |
1548 | |
1549 | |
1550 | if (!ToType->isVectorType() && !FromType->isVectorType()) |
1551 | return false; |
1552 | |
1553 | |
1554 | if (S.Context.hasSameUnqualifiedType(FromType, ToType)) |
1555 | return false; |
1556 | |
1557 | |
1558 | if (ToType->isExtVectorType()) { |
1559 | |
1560 | |
1561 | if (FromType->isExtVectorType()) |
1562 | return false; |
1563 | |
1564 | |
1565 | if (FromType->isArithmeticType()) { |
1566 | ICK = ICK_Vector_Splat; |
1567 | return true; |
1568 | } |
1569 | } |
1570 | |
1571 | |
1572 | |
1573 | |
1574 | |
1575 | if (ToType->isVectorType() && FromType->isVectorType()) { |
1576 | if (S.Context.areCompatibleVectorTypes(FromType, ToType) || |
1577 | S.isLaxVectorConversion(FromType, ToType)) { |
1578 | ICK = ICK_Vector_Conversion; |
1579 | return true; |
1580 | } |
1581 | } |
1582 | |
1583 | return false; |
1584 | } |
1585 | |
1586 | static bool tryAtomicConversion(Sema &S, Expr *From, QualType ToType, |
1587 | bool InOverloadResolution, |
1588 | StandardConversionSequence &SCS, |
1589 | bool CStyle); |
1590 | |
1591 | |
1592 | |
1593 | |
1594 | |
1595 | |
1596 | |
1597 | |
1598 | |
1599 | static bool IsStandardConversion(Sema &S, Expr* From, QualType ToType, |
1600 | bool InOverloadResolution, |
1601 | StandardConversionSequence &SCS, |
1602 | bool CStyle, |
1603 | bool AllowObjCWritebackConversion) { |
1604 | QualType FromType = From->getType(); |
1605 | |
1606 | |
1607 | SCS.setAsIdentityConversion(); |
1608 | SCS.IncompatibleObjC = false; |
1609 | SCS.setFromType(FromType); |
1610 | SCS.CopyConstructor = nullptr; |
1611 | |
1612 | |
1613 | |
1614 | if (S.getLangOpts().CPlusPlus && |
1615 | (FromType->isRecordType() || ToType->isRecordType())) |
1616 | return false; |
1617 | |
1618 | |
1619 | |
1620 | |
1621 | |
1622 | if (FromType == S.Context.OverloadTy) { |
1623 | DeclAccessPair AccessPair; |
1624 | if (FunctionDecl *Fn |
1625 | = S.ResolveAddressOfOverloadedFunction(From, ToType, false, |
1626 | AccessPair)) { |
1627 | |
1628 | |
1629 | FromType = Fn->getType(); |
1630 | SCS.setFromType(FromType); |
1631 | |
1632 | |
1633 | |
1634 | if (!S.Context.hasSameUnqualifiedType( |
1635 | S.ExtractUnqualifiedFunctionType(ToType), FromType)) { |
1636 | QualType resultTy; |
1637 | |
1638 | if (!S.IsFunctionConversion(FromType, |
1639 | S.ExtractUnqualifiedFunctionType(ToType), resultTy)) |
1640 | |
1641 | if (!ToType->isBooleanType()) |
1642 | return false; |
1643 | } |
1644 | |
1645 | |
1646 | |
1647 | |
1648 | |
1649 | CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Fn); |
1650 | if (Method && !Method->isStatic()) { |
1651 | (0) . __assert_fail ("isa(From->IgnoreParens()) && \"Non-unary operator on non-static member address\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 1652, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<UnaryOperator>(From->IgnoreParens()) && |
1652 | (0) . __assert_fail ("isa(From->IgnoreParens()) && \"Non-unary operator on non-static member address\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 1652, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Non-unary operator on non-static member address"); |
1653 | (0) . __assert_fail ("cast(From->IgnoreParens())->getOpcode() == UO_AddrOf && \"Non-address-of operator on non-static member address\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 1655, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(cast<UnaryOperator>(From->IgnoreParens())->getOpcode() |
1654 | (0) . __assert_fail ("cast(From->IgnoreParens())->getOpcode() == UO_AddrOf && \"Non-address-of operator on non-static member address\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 1655, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> == UO_AddrOf && |
1655 | (0) . __assert_fail ("cast(From->IgnoreParens())->getOpcode() == UO_AddrOf && \"Non-address-of operator on non-static member address\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 1655, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Non-address-of operator on non-static member address"); |
1656 | const Type *ClassType |
1657 | = S.Context.getTypeDeclType(Method->getParent()).getTypePtr(); |
1658 | FromType = S.Context.getMemberPointerType(FromType, ClassType); |
1659 | } else if (isa<UnaryOperator>(From->IgnoreParens())) { |
1660 | (0) . __assert_fail ("cast(From->IgnoreParens())->getOpcode() == UO_AddrOf && \"Non-address-of operator for overloaded function expression\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 1662, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(cast<UnaryOperator>(From->IgnoreParens())->getOpcode() == |
1661 | (0) . __assert_fail ("cast(From->IgnoreParens())->getOpcode() == UO_AddrOf && \"Non-address-of operator for overloaded function expression\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 1662, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> UO_AddrOf && |
1662 | (0) . __assert_fail ("cast(From->IgnoreParens())->getOpcode() == UO_AddrOf && \"Non-address-of operator for overloaded function expression\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 1662, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Non-address-of operator for overloaded function expression"); |
1663 | FromType = S.Context.getPointerType(FromType); |
1664 | } |
1665 | |
1666 | |
1667 | |
1668 | |
1669 | getType())", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 1671, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(S.Context.hasSameType( |
1670 | getType())", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 1671, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> FromType, |
1671 | getType())", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 1671, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> S.FixOverloadedFunctionReference(From, AccessPair, Fn)->getType())); |
1672 | } else { |
1673 | return false; |
1674 | } |
1675 | } |
1676 | |
1677 | |
1678 | |
1679 | bool argIsLValue = From->isGLValue(); |
1680 | if (argIsLValue && |
1681 | !FromType->isFunctionType() && !FromType->isArrayType() && |
1682 | S.Context.getCanonicalType(FromType) != S.Context.OverloadTy) { |
1683 | SCS.First = ICK_Lvalue_To_Rvalue; |
1684 | |
1685 | |
1686 | |
1687 | |
1688 | if (const AtomicType *Atomic = FromType->getAs<AtomicType>()) |
1689 | FromType = Atomic->getValueType(); |
1690 | |
1691 | |
1692 | |
1693 | |
1694 | |
1695 | FromType = FromType.getUnqualifiedType(); |
1696 | } else if (FromType->isArrayType()) { |
1697 | |
1698 | SCS.First = ICK_Array_To_Pointer; |
1699 | |
1700 | |
1701 | |
1702 | |
1703 | FromType = S.Context.getArrayDecayedType(FromType); |
1704 | |
1705 | if (S.IsStringLiteralToNonConstPointerConversion(From, ToType)) { |
1706 | |
1707 | SCS.DeprecatedStringLiteralToCharPtr = true; |
1708 | |
1709 | |
1710 | |
1711 | |
1712 | |
1713 | SCS.Second = ICK_Identity; |
1714 | SCS.Third = ICK_Qualification; |
1715 | SCS.QualificationIncludesObjCLifetime = false; |
1716 | SCS.setAllToTypes(FromType); |
1717 | return true; |
1718 | } |
1719 | } else if (FromType->isFunctionType() && argIsLValue) { |
1720 | |
1721 | SCS.First = ICK_Function_To_Pointer; |
1722 | |
1723 | if (auto *DRE = dyn_cast<DeclRefExpr>(From->IgnoreParenCasts())) |
1724 | if (auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl())) |
1725 | if (!S.checkAddressOfFunctionIsAvailable(FD)) |
1726 | return false; |
1727 | |
1728 | |
1729 | |
1730 | |
1731 | FromType = S.Context.getPointerType(FromType); |
1732 | } else { |
1733 | |
1734 | SCS.First = ICK_Identity; |
1735 | } |
1736 | SCS.setToType(0, FromType); |
1737 | |
1738 | |
1739 | |
1740 | |
1741 | |
1742 | |
1743 | |
1744 | bool IncompatibleObjC = false; |
1745 | ImplicitConversionKind SecondICK = ICK_Identity; |
1746 | if (S.Context.hasSameUnqualifiedType(FromType, ToType)) { |
1747 | |
1748 | |
1749 | SCS.Second = ICK_Identity; |
1750 | } else if (S.IsIntegralPromotion(From, FromType, ToType)) { |
1751 | |
1752 | SCS.Second = ICK_Integral_Promotion; |
1753 | FromType = ToType.getUnqualifiedType(); |
1754 | } else if (S.IsFloatingPointPromotion(FromType, ToType)) { |
1755 | |
1756 | SCS.Second = ICK_Floating_Promotion; |
1757 | FromType = ToType.getUnqualifiedType(); |
1758 | } else if (S.IsComplexPromotion(FromType, ToType)) { |
1759 | |
1760 | SCS.Second = ICK_Complex_Promotion; |
1761 | FromType = ToType.getUnqualifiedType(); |
1762 | } else if (ToType->isBooleanType() && |
1763 | (FromType->isArithmeticType() || |
1764 | FromType->isAnyPointerType() || |
1765 | FromType->isBlockPointerType() || |
1766 | FromType->isMemberPointerType() || |
1767 | FromType->isNullPtrType())) { |
1768 | |
1769 | SCS.Second = ICK_Boolean_Conversion; |
1770 | FromType = S.Context.BoolTy; |
1771 | } else if (FromType->isIntegralOrUnscopedEnumerationType() && |
1772 | ToType->isIntegralType(S.Context)) { |
1773 | |
1774 | SCS.Second = ICK_Integral_Conversion; |
1775 | FromType = ToType.getUnqualifiedType(); |
1776 | } else if (FromType->isAnyComplexType() && ToType->isAnyComplexType()) { |
1777 | |
1778 | SCS.Second = ICK_Complex_Conversion; |
1779 | FromType = ToType.getUnqualifiedType(); |
1780 | } else if ((FromType->isAnyComplexType() && ToType->isArithmeticType()) || |
1781 | (ToType->isAnyComplexType() && FromType->isArithmeticType())) { |
1782 | |
1783 | SCS.Second = ICK_Complex_Real; |
1784 | FromType = ToType.getUnqualifiedType(); |
1785 | } else if (FromType->isRealFloatingType() && ToType->isRealFloatingType()) { |
1786 | |
1787 | |
1788 | |
1789 | if (&S.Context.getFloatTypeSemantics(FromType) != |
1790 | &S.Context.getFloatTypeSemantics(ToType)) { |
1791 | bool Float128AndLongDouble = ((FromType == S.Context.Float128Ty && |
1792 | ToType == S.Context.LongDoubleTy) || |
1793 | (FromType == S.Context.LongDoubleTy && |
1794 | ToType == S.Context.Float128Ty)); |
1795 | if (Float128AndLongDouble && |
1796 | (&S.Context.getFloatTypeSemantics(S.Context.LongDoubleTy) == |
1797 | &llvm::APFloat::PPCDoubleDouble())) |
1798 | return false; |
1799 | } |
1800 | |
1801 | SCS.Second = ICK_Floating_Conversion; |
1802 | FromType = ToType.getUnqualifiedType(); |
1803 | } else if ((FromType->isRealFloatingType() && |
1804 | ToType->isIntegralType(S.Context)) || |
1805 | (FromType->isIntegralOrUnscopedEnumerationType() && |
1806 | ToType->isRealFloatingType())) { |
1807 | |
1808 | SCS.Second = ICK_Floating_Integral; |
1809 | FromType = ToType.getUnqualifiedType(); |
1810 | } else if (S.IsBlockPointerConversion(FromType, ToType, FromType)) { |
1811 | SCS.Second = ICK_Block_Pointer_Conversion; |
1812 | } else if (AllowObjCWritebackConversion && |
1813 | S.isObjCWritebackConversion(FromType, ToType, FromType)) { |
1814 | SCS.Second = ICK_Writeback_Conversion; |
1815 | } else if (S.IsPointerConversion(From, FromType, ToType, InOverloadResolution, |
1816 | FromType, IncompatibleObjC)) { |
1817 | |
1818 | SCS.Second = ICK_Pointer_Conversion; |
1819 | SCS.IncompatibleObjC = IncompatibleObjC; |
1820 | FromType = FromType.getUnqualifiedType(); |
1821 | } else if (S.IsMemberPointerConversion(From, FromType, ToType, |
1822 | InOverloadResolution, FromType)) { |
1823 | |
1824 | SCS.Second = ICK_Pointer_Member; |
1825 | } else if (IsVectorConversion(S, FromType, ToType, SecondICK)) { |
1826 | SCS.Second = SecondICK; |
1827 | FromType = ToType.getUnqualifiedType(); |
1828 | } else if (!S.getLangOpts().CPlusPlus && |
1829 | S.Context.typesAreCompatible(ToType, FromType)) { |
1830 | |
1831 | SCS.Second = ICK_Compatible_Conversion; |
1832 | FromType = ToType.getUnqualifiedType(); |
1833 | } else if (IsTransparentUnionStandardConversion(S, From, ToType, |
1834 | InOverloadResolution, |
1835 | SCS, CStyle)) { |
1836 | SCS.Second = ICK_TransparentUnionConversion; |
1837 | FromType = ToType; |
1838 | } else if (tryAtomicConversion(S, From, ToType, InOverloadResolution, SCS, |
1839 | CStyle)) { |
1840 | |
1841 | |
1842 | return true; |
1843 | } else if (ToType->isEventT() && |
1844 | From->isIntegerConstantExpr(S.getASTContext()) && |
1845 | From->EvaluateKnownConstInt(S.getASTContext()) == 0) { |
1846 | SCS.Second = ICK_Zero_Event_Conversion; |
1847 | FromType = ToType; |
1848 | } else if (ToType->isQueueT() && |
1849 | From->isIntegerConstantExpr(S.getASTContext()) && |
1850 | (From->EvaluateKnownConstInt(S.getASTContext()) == 0)) { |
1851 | SCS.Second = ICK_Zero_Queue_Conversion; |
1852 | FromType = ToType; |
1853 | } else { |
1854 | |
1855 | SCS.Second = ICK_Identity; |
1856 | } |
1857 | SCS.setToType(1, FromType); |
1858 | |
1859 | |
1860 | |
1861 | bool ObjCLifetimeConversion; |
1862 | if (S.IsFunctionConversion(FromType, ToType, FromType)) { |
1863 | |
1864 | |
1865 | SCS.Third = ICK_Function_Conversion; |
1866 | } else if (S.IsQualificationConversion(FromType, ToType, CStyle, |
1867 | ObjCLifetimeConversion)) { |
1868 | SCS.Third = ICK_Qualification; |
1869 | SCS.QualificationIncludesObjCLifetime = ObjCLifetimeConversion; |
1870 | FromType = ToType; |
1871 | } else { |
1872 | |
1873 | SCS.Third = ICK_Identity; |
1874 | } |
1875 | |
1876 | |
1877 | |
1878 | |
1879 | |
1880 | QualType CanonFrom = S.Context.getCanonicalType(FromType); |
1881 | QualType CanonTo = S.Context.getCanonicalType(ToType); |
1882 | if (CanonFrom.getLocalUnqualifiedType() |
1883 | == CanonTo.getLocalUnqualifiedType() && |
1884 | CanonFrom.getLocalQualifiers() != CanonTo.getLocalQualifiers()) { |
1885 | FromType = ToType; |
1886 | CanonFrom = CanonTo; |
1887 | } |
1888 | |
1889 | SCS.setToType(2, FromType); |
1890 | |
1891 | if (CanonFrom == CanonTo) |
1892 | return true; |
1893 | |
1894 | |
1895 | |
1896 | if (S.getLangOpts().CPlusPlus || !InOverloadResolution) |
1897 | return false; |
1898 | |
1899 | ExprResult ER = ExprResult{From}; |
1900 | Sema::AssignConvertType Conv = |
1901 | S.CheckSingleAssignmentConstraints(ToType, ER, |
1902 | , |
1903 | , |
1904 | ); |
1905 | ImplicitConversionKind SecondConv; |
1906 | switch (Conv) { |
1907 | case Sema::Compatible: |
1908 | SecondConv = ICK_C_Only_Conversion; |
1909 | break; |
1910 | |
1911 | |
1912 | |
1913 | case Sema::CompatiblePointerDiscardsQualifiers: |
1914 | case Sema::IncompatiblePointer: |
1915 | case Sema::IncompatiblePointerSign: |
1916 | SecondConv = ICK_Incompatible_Pointer_Conversion; |
1917 | break; |
1918 | default: |
1919 | return false; |
1920 | } |
1921 | |
1922 | |
1923 | |
1924 | |
1925 | SCS.Second = SecondConv; |
1926 | SCS.setToType(1, ToType); |
1927 | |
1928 | |
1929 | |
1930 | |
1931 | |
1932 | SCS.Third = ICK_Identity; |
1933 | SCS.setToType(2, ToType); |
1934 | return true; |
1935 | } |
1936 | |
1937 | static bool |
1938 | IsTransparentUnionStandardConversion(Sema &S, Expr* From, |
1939 | QualType &ToType, |
1940 | bool InOverloadResolution, |
1941 | StandardConversionSequence &SCS, |
1942 | bool CStyle) { |
1943 | |
1944 | const RecordType *UT = ToType->getAsUnionType(); |
1945 | if (!UT || !UT->getDecl()->hasAttr<TransparentUnionAttr>()) |
1946 | return false; |
1947 | |
1948 | RecordDecl *UD = UT->getDecl(); |
1949 | |
1950 | for (const auto *it : UD->fields()) { |
1951 | if (IsStandardConversion(S, From, it->getType(), InOverloadResolution, SCS, |
1952 | CStyle, )) { |
1953 | ToType = it->getType(); |
1954 | return true; |
1955 | } |
1956 | } |
1957 | return false; |
1958 | } |
1959 | |
1960 | |
1961 | |
1962 | |
1963 | |
1964 | bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) { |
1965 | const BuiltinType *To = ToType->getAs<BuiltinType>(); |
1966 | |
1967 | if (!To) { |
1968 | return false; |
1969 | } |
1970 | |
1971 | |
1972 | |
1973 | |
1974 | |
1975 | |
1976 | if (FromType->isPromotableIntegerType() && !FromType->isBooleanType() && |
1977 | !FromType->isEnumeralType()) { |
1978 | if ( |
1979 | (FromType->isSignedIntegerType() || |
1980 | |
1981 | |
1982 | Context.getTypeSize(FromType) < Context.getTypeSize(ToType))) { |
1983 | return To->getKind() == BuiltinType::Int; |
1984 | } |
1985 | |
1986 | return To->getKind() == BuiltinType::UInt; |
1987 | } |
1988 | |
1989 | |
1990 | |
1991 | |
1992 | |
1993 | |
1994 | |
1995 | |
1996 | |
1997 | |
1998 | |
1999 | |
2000 | |
2001 | |
2002 | |
2003 | |
2004 | |
2005 | |
2006 | |
2007 | if (const EnumType * = FromType->getAs<EnumType>()) { |
2008 | |
2009 | |
2010 | if (FromEnumType->getDecl()->isScoped()) |
2011 | return false; |
2012 | |
2013 | |
2014 | |
2015 | |
2016 | |
2017 | if (FromEnumType->getDecl()->isFixed()) { |
2018 | QualType Underlying = FromEnumType->getDecl()->getIntegerType(); |
2019 | return Context.hasSameUnqualifiedType(Underlying, ToType) || |
2020 | IsIntegralPromotion(nullptr, Underlying, ToType); |
2021 | } |
2022 | |
2023 | |
2024 | if (ToType->isIntegerType() && |
2025 | isCompleteType(From->getBeginLoc(), FromType)) |
2026 | return Context.hasSameUnqualifiedType( |
2027 | ToType, FromEnumType->getDecl()->getPromotionType()); |
2028 | |
2029 | |
2030 | |
2031 | |
2032 | |
2033 | |
2034 | if (getLangOpts().CPlusPlus) |
2035 | return false; |
2036 | } |
2037 | |
2038 | |
2039 | |
2040 | |
2041 | |
2042 | |
2043 | |
2044 | |
2045 | |
2046 | |
2047 | if (FromType->isAnyCharacterType() && !FromType->isCharType() && |
2048 | ToType->isIntegerType()) { |
2049 | |
2050 | |
2051 | bool FromIsSigned = FromType->isSignedIntegerType(); |
2052 | uint64_t FromSize = Context.getTypeSize(FromType); |
2053 | |
2054 | |
2055 | |
2056 | QualType PromoteTypes[6] = { |
2057 | Context.IntTy, Context.UnsignedIntTy, |
2058 | Context.LongTy, Context.UnsignedLongTy , |
2059 | Context.LongLongTy, Context.UnsignedLongLongTy |
2060 | }; |
2061 | for (int Idx = 0; Idx < 6; ++Idx) { |
2062 | uint64_t ToSize = Context.getTypeSize(PromoteTypes[Idx]); |
2063 | if (FromSize < ToSize || |
2064 | (FromSize == ToSize && |
2065 | FromIsSigned == PromoteTypes[Idx]->isSignedIntegerType())) { |
2066 | |
2067 | |
2068 | |
2069 | return Context.hasSameUnqualifiedType(ToType, PromoteTypes[Idx]); |
2070 | } |
2071 | } |
2072 | } |
2073 | |
2074 | |
2075 | |
2076 | |
2077 | |
2078 | |
2079 | |
2080 | |
2081 | |
2082 | |
2083 | |
2084 | |
2085 | |
2086 | |
2087 | |
2088 | if (From) { |
2089 | if (FieldDecl *MemberDecl = From->getSourceBitField()) { |
2090 | llvm::APSInt BitWidth; |
2091 | if (FromType->isIntegralType(Context) && |
2092 | MemberDecl->getBitWidth()->isIntegerConstantExpr(BitWidth, Context)) { |
2093 | llvm::APSInt ToSize(BitWidth.getBitWidth(), BitWidth.isUnsigned()); |
2094 | ToSize = Context.getTypeSize(ToType); |
2095 | |
2096 | |
2097 | if (BitWidth < ToSize || |
2098 | (FromType->isSignedIntegerType() && BitWidth <= ToSize)) { |
2099 | return To->getKind() == BuiltinType::Int; |
2100 | } |
2101 | |
2102 | |
2103 | |
2104 | if (FromType->isUnsignedIntegerType() && BitWidth <= ToSize) { |
2105 | return To->getKind() == BuiltinType::UInt; |
2106 | } |
2107 | |
2108 | return false; |
2109 | } |
2110 | } |
2111 | } |
2112 | |
2113 | |
2114 | |
2115 | if (FromType->isBooleanType() && To->getKind() == BuiltinType::Int) { |
2116 | return true; |
2117 | } |
2118 | |
2119 | return false; |
2120 | } |
2121 | |
2122 | |
2123 | |
2124 | |
2125 | bool Sema::IsFloatingPointPromotion(QualType FromType, QualType ToType) { |
2126 | if (const BuiltinType *FromBuiltin = FromType->getAs<BuiltinType>()) |
2127 | if (const BuiltinType *ToBuiltin = ToType->getAs<BuiltinType>()) { |
2128 | |
2129 | |
2130 | if (FromBuiltin->getKind() == BuiltinType::Float && |
2131 | ToBuiltin->getKind() == BuiltinType::Double) |
2132 | return true; |
2133 | |
2134 | |
2135 | |
2136 | |
2137 | if (!getLangOpts().CPlusPlus && |
2138 | (FromBuiltin->getKind() == BuiltinType::Float || |
2139 | FromBuiltin->getKind() == BuiltinType::Double) && |
2140 | (ToBuiltin->getKind() == BuiltinType::LongDouble || |
2141 | ToBuiltin->getKind() == BuiltinType::Float128)) |
2142 | return true; |
2143 | |
2144 | |
2145 | if (!getLangOpts().NativeHalfType && |
2146 | FromBuiltin->getKind() == BuiltinType::Half && |
2147 | ToBuiltin->getKind() == BuiltinType::Float) |
2148 | return true; |
2149 | } |
2150 | |
2151 | return false; |
2152 | } |
2153 | |
2154 | |
2155 | |
2156 | |
2157 | |
2158 | |
2159 | bool Sema::IsComplexPromotion(QualType FromType, QualType ToType) { |
2160 | const ComplexType *FromComplex = FromType->getAs<ComplexType>(); |
2161 | if (!FromComplex) |
2162 | return false; |
2163 | |
2164 | const ComplexType *ToComplex = ToType->getAs<ComplexType>(); |
2165 | if (!ToComplex) |
2166 | return false; |
2167 | |
2168 | return IsFloatingPointPromotion(FromComplex->getElementType(), |
2169 | ToComplex->getElementType()) || |
2170 | IsIntegralPromotion(nullptr, FromComplex->getElementType(), |
2171 | ToComplex->getElementType()); |
2172 | } |
2173 | |
2174 | |
2175 | |
2176 | |
2177 | |
2178 | |
2179 | |
2180 | static QualType |
2181 | BuildSimilarlyQualifiedPointerType(const Type *FromPtr, |
2182 | QualType ToPointee, QualType ToType, |
2183 | ASTContext &Context, |
2184 | bool StripObjCLifetime = false) { |
2185 | (0) . __assert_fail ("(FromPtr->getTypeClass() == Type..Pointer || FromPtr->getTypeClass() == Type..ObjCObjectPointer) && \"Invalid similarly-qualified pointer type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 2187, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((FromPtr->getTypeClass() == Type::Pointer || |
2186 | (0) . __assert_fail ("(FromPtr->getTypeClass() == Type..Pointer || FromPtr->getTypeClass() == Type..ObjCObjectPointer) && \"Invalid similarly-qualified pointer type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 2187, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> FromPtr->getTypeClass() == Type::ObjCObjectPointer) && |
2187 | (0) . __assert_fail ("(FromPtr->getTypeClass() == Type..Pointer || FromPtr->getTypeClass() == Type..ObjCObjectPointer) && \"Invalid similarly-qualified pointer type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 2187, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Invalid similarly-qualified pointer type"); |
2188 | |
2189 | |
2190 | if (ToType->isObjCIdType() || ToType->isObjCQualifiedIdType()) |
2191 | return ToType.getUnqualifiedType(); |
2192 | |
2193 | QualType CanonFromPointee |
2194 | = Context.getCanonicalType(FromPtr->getPointeeType()); |
2195 | QualType CanonToPointee = Context.getCanonicalType(ToPointee); |
2196 | Qualifiers Quals = CanonFromPointee.getQualifiers(); |
2197 | |
2198 | if (StripObjCLifetime) |
2199 | Quals.removeObjCLifetime(); |
2200 | |
2201 | |
2202 | if (CanonToPointee.getLocalQualifiers() == Quals) { |
2203 | |
2204 | if (!ToType.isNull()) |
2205 | return ToType.getUnqualifiedType(); |
2206 | |
2207 | |
2208 | |
2209 | if (isa<ObjCObjectPointerType>(ToType)) |
2210 | return Context.getObjCObjectPointerType(ToPointee); |
2211 | return Context.getPointerType(ToPointee); |
2212 | } |
2213 | |
2214 | |
2215 | QualType QualifiedCanonToPointee |
2216 | = Context.getQualifiedType(CanonToPointee.getLocalUnqualifiedType(), Quals); |
2217 | |
2218 | if (isa<ObjCObjectPointerType>(ToType)) |
2219 | return Context.getObjCObjectPointerType(QualifiedCanonToPointee); |
2220 | return Context.getPointerType(QualifiedCanonToPointee); |
2221 | } |
2222 | |
2223 | static bool isNullPointerConstantForConversion(Expr *Expr, |
2224 | bool InOverloadResolution, |
2225 | ASTContext &Context) { |
2226 | |
2227 | |
2228 | if (Expr->isValueDependent() && !Expr->isTypeDependent() && |
2229 | Expr->getType()->isIntegerType() && !Expr->getType()->isEnumeralType()) |
2230 | return !InOverloadResolution; |
2231 | |
2232 | return Expr->isNullPointerConstant(Context, |
2233 | InOverloadResolution? Expr::NPC_ValueDependentIsNotNull |
2234 | : Expr::NPC_ValueDependentIsNull); |
2235 | } |
2236 | |
2237 | |
2238 | |
2239 | |
2240 | |
2241 | |
2242 | |
2243 | |
2244 | |
2245 | |
2246 | |
2247 | |
2248 | |
2249 | |
2250 | |
2251 | |
2252 | |
2253 | bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType, |
2254 | bool InOverloadResolution, |
2255 | QualType& ConvertedType, |
2256 | bool &IncompatibleObjC) { |
2257 | IncompatibleObjC = false; |
2258 | if (isObjCPointerConversion(FromType, ToType, ConvertedType, |
2259 | IncompatibleObjC)) |
2260 | return true; |
2261 | |
2262 | |
2263 | if (ToType->isObjCObjectPointerType() && |
2264 | isNullPointerConstantForConversion(From, InOverloadResolution, Context)) { |
2265 | ConvertedType = ToType; |
2266 | return true; |
2267 | } |
2268 | |
2269 | |
2270 | if (FromType->isBlockPointerType() && ToType->isPointerType() && |
2271 | ToType->getAs<PointerType>()->getPointeeType()->isVoidType()) { |
2272 | ConvertedType = ToType; |
2273 | return true; |
2274 | } |
2275 | |
2276 | |
2277 | if (ToType->isBlockPointerType() && |
2278 | isNullPointerConstantForConversion(From, InOverloadResolution, Context)) { |
2279 | ConvertedType = ToType; |
2280 | return true; |
2281 | } |
2282 | |
2283 | |
2284 | |
2285 | if (ToType->isNullPtrType() && |
2286 | isNullPointerConstantForConversion(From, InOverloadResolution, Context)) { |
2287 | ConvertedType = ToType; |
2288 | return true; |
2289 | } |
2290 | |
2291 | const PointerType* ToTypePtr = ToType->getAs<PointerType>(); |
2292 | if (!ToTypePtr) |
2293 | return false; |
2294 | |
2295 | |
2296 | if (isNullPointerConstantForConversion(From, InOverloadResolution, Context)) { |
2297 | ConvertedType = ToType; |
2298 | return true; |
2299 | } |
2300 | |
2301 | |
2302 | |
2303 | QualType ToPointeeType = ToTypePtr->getPointeeType(); |
2304 | if (FromType->isObjCObjectPointerType() && ToPointeeType->isVoidType() && |
2305 | !getLangOpts().ObjCAutoRefCount) { |
2306 | ConvertedType = BuildSimilarlyQualifiedPointerType( |
2307 | FromType->getAs<ObjCObjectPointerType>(), |
2308 | ToPointeeType, |
2309 | ToType, Context); |
2310 | return true; |
2311 | } |
2312 | const PointerType *FromTypePtr = FromType->getAs<PointerType>(); |
2313 | if (!FromTypePtr) |
2314 | return false; |
2315 | |
2316 | QualType FromPointeeType = FromTypePtr->getPointeeType(); |
2317 | |
2318 | |
2319 | |
2320 | if (Context.hasSameUnqualifiedType(FromPointeeType, ToPointeeType)) |
2321 | return false; |
2322 | |
2323 | |
2324 | |
2325 | |
2326 | if (FromPointeeType->isIncompleteOrObjectType() && |
2327 | ToPointeeType->isVoidType()) { |
2328 | ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr, |
2329 | ToPointeeType, |
2330 | ToType, Context, |
2331 | ); |
2332 | return true; |
2333 | } |
2334 | |
2335 | |
2336 | if (getLangOpts().MSVCCompat && FromPointeeType->isFunctionType() && |
2337 | ToPointeeType->isVoidType()) { |
2338 | ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr, |
2339 | ToPointeeType, |
2340 | ToType, Context); |
2341 | return true; |
2342 | } |
2343 | |
2344 | |
2345 | |
2346 | if (!getLangOpts().CPlusPlus && |
2347 | Context.typesAreCompatible(FromPointeeType, ToPointeeType)) { |
2348 | ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr, |
2349 | ToPointeeType, |
2350 | ToType, Context); |
2351 | return true; |
2352 | } |
2353 | |
2354 | |
2355 | |
2356 | |
2357 | |
2358 | |
2359 | |
2360 | |
2361 | |
2362 | |
2363 | |
2364 | |
2365 | |
2366 | |
2367 | if (getLangOpts().CPlusPlus && FromPointeeType->isRecordType() && |
2368 | ToPointeeType->isRecordType() && |
2369 | !Context.hasSameUnqualifiedType(FromPointeeType, ToPointeeType) && |
2370 | IsDerivedFrom(From->getBeginLoc(), FromPointeeType, ToPointeeType)) { |
2371 | ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr, |
2372 | ToPointeeType, |
2373 | ToType, Context); |
2374 | return true; |
2375 | } |
2376 | |
2377 | if (FromPointeeType->isVectorType() && ToPointeeType->isVectorType() && |
2378 | Context.areCompatibleVectorTypes(FromPointeeType, ToPointeeType)) { |
2379 | ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr, |
2380 | ToPointeeType, |
2381 | ToType, Context); |
2382 | return true; |
2383 | } |
2384 | |
2385 | return false; |
2386 | } |
2387 | |
2388 | |
2389 | static QualType AdoptQualifiers(ASTContext &Context, QualType T, Qualifiers Qs){ |
2390 | Qualifiers TQs = T.getQualifiers(); |
2391 | |
2392 | |
2393 | if (TQs == Qs) |
2394 | return T; |
2395 | |
2396 | if (Qs.compatiblyIncludes(TQs)) |
2397 | return Context.getQualifiedType(T, Qs); |
2398 | |
2399 | return Context.getQualifiedType(T.getUnqualifiedType(), Qs); |
2400 | } |
2401 | |
2402 | |
2403 | |
2404 | |
2405 | bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType, |
2406 | QualType& ConvertedType, |
2407 | bool &IncompatibleObjC) { |
2408 | if (!getLangOpts().ObjC) |
2409 | return false; |
2410 | |
2411 | |
2412 | Qualifiers FromQualifiers = FromType.getQualifiers(); |
2413 | |
2414 | |
2415 | const ObjCObjectPointerType* ToObjCPtr = |
2416 | ToType->getAs<ObjCObjectPointerType>(); |
2417 | const ObjCObjectPointerType *FromObjCPtr = |
2418 | FromType->getAs<ObjCObjectPointerType>(); |
2419 | |
2420 | if (ToObjCPtr && FromObjCPtr) { |
2421 | |
2422 | |
2423 | if (Context.hasSameUnqualifiedType(ToObjCPtr->getPointeeType(), |
2424 | FromObjCPtr->getPointeeType())) |
2425 | return false; |
2426 | |
2427 | |
2428 | if (Context.canAssignObjCInterfaces(ToObjCPtr, FromObjCPtr)) { |
2429 | const ObjCInterfaceType* LHS = ToObjCPtr->getInterfaceType(); |
2430 | const ObjCInterfaceType* RHS = FromObjCPtr->getInterfaceType(); |
2431 | if (getLangOpts().CPlusPlus && LHS && RHS && |
2432 | !ToObjCPtr->getPointeeType().isAtLeastAsQualifiedAs( |
2433 | FromObjCPtr->getPointeeType())) |
2434 | return false; |
2435 | ConvertedType = BuildSimilarlyQualifiedPointerType(FromObjCPtr, |
2436 | ToObjCPtr->getPointeeType(), |
2437 | ToType, Context); |
2438 | ConvertedType = AdoptQualifiers(Context, ConvertedType, FromQualifiers); |
2439 | return true; |
2440 | } |
2441 | |
2442 | if (Context.canAssignObjCInterfaces(FromObjCPtr, ToObjCPtr)) { |
2443 | |
2444 | |
2445 | |
2446 | IncompatibleObjC = true; |
2447 | ConvertedType = BuildSimilarlyQualifiedPointerType(FromObjCPtr, |
2448 | ToObjCPtr->getPointeeType(), |
2449 | ToType, Context); |
2450 | ConvertedType = AdoptQualifiers(Context, ConvertedType, FromQualifiers); |
2451 | return true; |
2452 | } |
2453 | } |
2454 | |
2455 | QualType ToPointeeType; |
2456 | if (const PointerType *ToCPtr = ToType->getAs<PointerType>()) |
2457 | ToPointeeType = ToCPtr->getPointeeType(); |
2458 | else if (const BlockPointerType *ToBlockPtr = |
2459 | ToType->getAs<BlockPointerType>()) { |
2460 | |
2461 | |
2462 | if (FromObjCPtr && FromObjCPtr->isObjCBuiltinType()) { |
2463 | ConvertedType = AdoptQualifiers(Context, ToType, FromQualifiers); |
2464 | return true; |
2465 | } |
2466 | ToPointeeType = ToBlockPtr->getPointeeType(); |
2467 | } |
2468 | else if (FromType->getAs<BlockPointerType>() && |
2469 | ToObjCPtr && ToObjCPtr->isObjCBuiltinType()) { |
2470 | |
2471 | |
2472 | ConvertedType = AdoptQualifiers(Context, ToType, FromQualifiers); |
2473 | return true; |
2474 | } |
2475 | else |
2476 | return false; |
2477 | |
2478 | QualType FromPointeeType; |
2479 | if (const PointerType *FromCPtr = FromType->getAs<PointerType>()) |
2480 | FromPointeeType = FromCPtr->getPointeeType(); |
2481 | else if (const BlockPointerType *FromBlockPtr = |
2482 | FromType->getAs<BlockPointerType>()) |
2483 | FromPointeeType = FromBlockPtr->getPointeeType(); |
2484 | else |
2485 | return false; |
2486 | |
2487 | |
2488 | |
2489 | if (FromPointeeType->isPointerType() && ToPointeeType->isPointerType() && |
2490 | isObjCPointerConversion(FromPointeeType, ToPointeeType, ConvertedType, |
2491 | IncompatibleObjC)) { |
2492 | |
2493 | IncompatibleObjC = true; |
2494 | ConvertedType = Context.getPointerType(ConvertedType); |
2495 | ConvertedType = AdoptQualifiers(Context, ConvertedType, FromQualifiers); |
2496 | return true; |
2497 | } |
2498 | |
2499 | |
2500 | if (FromPointeeType->getAs<ObjCObjectPointerType>() && |
2501 | ToPointeeType->getAs<ObjCObjectPointerType>() && |
2502 | isObjCPointerConversion(FromPointeeType, ToPointeeType, ConvertedType, |
2503 | IncompatibleObjC)) { |
2504 | |
2505 | ConvertedType = Context.getPointerType(ConvertedType); |
2506 | ConvertedType = AdoptQualifiers(Context, ConvertedType, FromQualifiers); |
2507 | return true; |
2508 | } |
2509 | |
2510 | |
2511 | |
2512 | |
2513 | |
2514 | const FunctionProtoType *FromFunctionType |
2515 | = FromPointeeType->getAs<FunctionProtoType>(); |
2516 | const FunctionProtoType *ToFunctionType |
2517 | = ToPointeeType->getAs<FunctionProtoType>(); |
2518 | if (FromFunctionType && ToFunctionType) { |
2519 | |
2520 | |
2521 | if (Context.getCanonicalType(FromPointeeType) |
2522 | == Context.getCanonicalType(ToPointeeType)) |
2523 | return false; |
2524 | |
2525 | |
2526 | |
2527 | if (FromFunctionType->getNumParams() != ToFunctionType->getNumParams() || |
2528 | FromFunctionType->isVariadic() != ToFunctionType->isVariadic() || |
2529 | FromFunctionType->getMethodQuals() != ToFunctionType->getMethodQuals()) |
2530 | return false; |
2531 | |
2532 | bool HasObjCConversion = false; |
2533 | if (Context.getCanonicalType(FromFunctionType->getReturnType()) == |
2534 | Context.getCanonicalType(ToFunctionType->getReturnType())) { |
2535 | |
2536 | } else if (isObjCPointerConversion(FromFunctionType->getReturnType(), |
2537 | ToFunctionType->getReturnType(), |
2538 | ConvertedType, IncompatibleObjC)) { |
2539 | |
2540 | HasObjCConversion = true; |
2541 | } else { |
2542 | |
2543 | return false; |
2544 | } |
2545 | |
2546 | |
2547 | for (unsigned ArgIdx = 0, NumArgs = FromFunctionType->getNumParams(); |
2548 | ArgIdx != NumArgs; ++ArgIdx) { |
2549 | QualType FromArgType = FromFunctionType->getParamType(ArgIdx); |
2550 | QualType ToArgType = ToFunctionType->getParamType(ArgIdx); |
2551 | if (Context.getCanonicalType(FromArgType) |
2552 | == Context.getCanonicalType(ToArgType)) { |
2553 | |
2554 | } else if (isObjCPointerConversion(FromArgType, ToArgType, |
2555 | ConvertedType, IncompatibleObjC)) { |
2556 | |
2557 | HasObjCConversion = true; |
2558 | } else { |
2559 | |
2560 | return false; |
2561 | } |
2562 | } |
2563 | |
2564 | if (HasObjCConversion) { |
2565 | |
2566 | |
2567 | ConvertedType = AdoptQualifiers(Context, ToType, FromQualifiers); |
2568 | IncompatibleObjC = true; |
2569 | return true; |
2570 | } |
2571 | } |
2572 | |
2573 | return false; |
2574 | } |
2575 | |
2576 | |
2577 | |
2578 | |
2579 | |
2580 | |
2581 | |
2582 | |
2583 | |
2584 | |
2585 | bool Sema::isObjCWritebackConversion(QualType FromType, QualType ToType, |
2586 | QualType &ConvertedType) { |
2587 | if (!getLangOpts().ObjCAutoRefCount || |
2588 | Context.hasSameUnqualifiedType(FromType, ToType)) |
2589 | return false; |
2590 | |
2591 | |
2592 | QualType ToPointee; |
2593 | if (const PointerType *ToPointer = ToType->getAs<PointerType>()) |
2594 | ToPointee = ToPointer->getPointeeType(); |
2595 | else |
2596 | return false; |
2597 | |
2598 | Qualifiers ToQuals = ToPointee.getQualifiers(); |
2599 | if (!ToPointee->isObjCLifetimeType() || |
2600 | ToQuals.getObjCLifetime() != Qualifiers::OCL_Autoreleasing || |
2601 | !ToQuals.withoutObjCLifetime().empty()) |
2602 | return false; |
2603 | |
2604 | |
2605 | QualType FromPointee; |
2606 | if (const PointerType *FromPointer = FromType->getAs<PointerType>()) |
2607 | FromPointee = FromPointer->getPointeeType(); |
2608 | else |
2609 | return false; |
2610 | |
2611 | Qualifiers FromQuals = FromPointee.getQualifiers(); |
2612 | if (!FromPointee->isObjCLifetimeType() || |
2613 | (FromQuals.getObjCLifetime() != Qualifiers::OCL_Strong && |
2614 | FromQuals.getObjCLifetime() != Qualifiers::OCL_Weak)) |
2615 | return false; |
2616 | |
2617 | |
2618 | FromQuals.setObjCLifetime(Qualifiers::OCL_Autoreleasing); |
2619 | if (!ToQuals.compatiblyIncludes(FromQuals)) |
2620 | return false; |
2621 | |
2622 | |
2623 | |
2624 | |
2625 | FromPointee = FromPointee.getUnqualifiedType(); |
2626 | |
2627 | |
2628 | ToPointee = ToPointee.getUnqualifiedType(); |
2629 | bool IncompatibleObjC; |
2630 | if (Context.typesAreCompatible(FromPointee, ToPointee)) |
2631 | FromPointee = ToPointee; |
2632 | else if (!isObjCPointerConversion(FromPointee, ToPointee, FromPointee, |
2633 | IncompatibleObjC)) |
2634 | return false; |
2635 | |
2636 | |
2637 | |
2638 | FromPointee = Context.getQualifiedType(FromPointee, FromQuals); |
2639 | ConvertedType = Context.getPointerType(FromPointee); |
2640 | return true; |
2641 | } |
2642 | |
2643 | bool Sema::IsBlockPointerConversion(QualType FromType, QualType ToType, |
2644 | QualType& ConvertedType) { |
2645 | QualType ToPointeeType; |
2646 | if (const BlockPointerType *ToBlockPtr = |
2647 | ToType->getAs<BlockPointerType>()) |
2648 | ToPointeeType = ToBlockPtr->getPointeeType(); |
2649 | else |
2650 | return false; |
2651 | |
2652 | QualType FromPointeeType; |
2653 | if (const BlockPointerType *FromBlockPtr = |
2654 | FromType->getAs<BlockPointerType>()) |
2655 | FromPointeeType = FromBlockPtr->getPointeeType(); |
2656 | else |
2657 | return false; |
2658 | |
2659 | |
2660 | |
2661 | |
2662 | const FunctionProtoType *FromFunctionType |
2663 | = FromPointeeType->getAs<FunctionProtoType>(); |
2664 | const FunctionProtoType *ToFunctionType |
2665 | = ToPointeeType->getAs<FunctionProtoType>(); |
2666 | |
2667 | if (!FromFunctionType || !ToFunctionType) |
2668 | return false; |
2669 | |
2670 | if (Context.hasSameType(FromPointeeType, ToPointeeType)) |
2671 | return true; |
2672 | |
2673 | |
2674 | |
2675 | if (FromFunctionType->getNumParams() != ToFunctionType->getNumParams() || |
2676 | FromFunctionType->isVariadic() != ToFunctionType->isVariadic()) |
2677 | return false; |
2678 | |
2679 | FunctionType::ExtInfo FromEInfo = FromFunctionType->getExtInfo(); |
2680 | FunctionType::ExtInfo ToEInfo = ToFunctionType->getExtInfo(); |
2681 | if (FromEInfo != ToEInfo) |
2682 | return false; |
2683 | |
2684 | bool IncompatibleObjC = false; |
2685 | if (Context.hasSameType(FromFunctionType->getReturnType(), |
2686 | ToFunctionType->getReturnType())) { |
2687 | |
2688 | } else { |
2689 | QualType RHS = FromFunctionType->getReturnType(); |
2690 | QualType LHS = ToFunctionType->getReturnType(); |
2691 | if ((!getLangOpts().CPlusPlus || !RHS->isRecordType()) && |
2692 | !RHS.hasQualifiers() && LHS.hasQualifiers()) |
2693 | LHS = LHS.getUnqualifiedType(); |
2694 | |
2695 | if (Context.hasSameType(RHS,LHS)) { |
2696 | |
2697 | } else if (isObjCPointerConversion(RHS, LHS, |
2698 | ConvertedType, IncompatibleObjC)) { |
2699 | if (IncompatibleObjC) |
2700 | return false; |
2701 | |
2702 | } |
2703 | else |
2704 | return false; |
2705 | } |
2706 | |
2707 | |
2708 | for (unsigned ArgIdx = 0, NumArgs = FromFunctionType->getNumParams(); |
2709 | ArgIdx != NumArgs; ++ArgIdx) { |
2710 | IncompatibleObjC = false; |
2711 | QualType FromArgType = FromFunctionType->getParamType(ArgIdx); |
2712 | QualType ToArgType = ToFunctionType->getParamType(ArgIdx); |
2713 | if (Context.hasSameType(FromArgType, ToArgType)) { |
2714 | |
2715 | } else if (isObjCPointerConversion(ToArgType, FromArgType, |
2716 | ConvertedType, IncompatibleObjC)) { |
2717 | if (IncompatibleObjC) |
2718 | return false; |
2719 | |
2720 | } else |
2721 | |
2722 | return false; |
2723 | } |
2724 | |
2725 | SmallVector<FunctionProtoType::ExtParameterInfo, 4> NewParamInfos; |
2726 | bool CanUseToFPT, CanUseFromFPT; |
2727 | if (!Context.mergeExtParameterInfo(ToFunctionType, FromFunctionType, |
2728 | CanUseToFPT, CanUseFromFPT, |
2729 | NewParamInfos)) |
2730 | return false; |
2731 | |
2732 | ConvertedType = ToType; |
2733 | return true; |
2734 | } |
2735 | |
2736 | enum { |
2737 | ft_default, |
2738 | ft_different_class, |
2739 | ft_parameter_arity, |
2740 | ft_parameter_mismatch, |
2741 | ft_return_type, |
2742 | ft_qualifer_mismatch, |
2743 | ft_noexcept |
2744 | }; |
2745 | |
2746 | |
2747 | |
2748 | static const FunctionProtoType *tryGetFunctionProtoType(QualType FromType) { |
2749 | if (auto *FPT = FromType->getAs<FunctionProtoType>()) |
2750 | return FPT; |
2751 | |
2752 | if (auto *MPT = FromType->getAs<MemberPointerType>()) |
2753 | return MPT->getPointeeType()->getAs<FunctionProtoType>(); |
2754 | |
2755 | return nullptr; |
2756 | } |
2757 | |
2758 | |
2759 | |
2760 | |
2761 | void Sema::HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, |
2762 | QualType FromType, QualType ToType) { |
2763 | |
2764 | if (FromType.isNull() || ToType.isNull()) { |
2765 | PDiag << ft_default; |
2766 | return; |
2767 | } |
2768 | |
2769 | |
2770 | if (FromType->isMemberPointerType() && ToType->isMemberPointerType()) { |
2771 | const MemberPointerType *FromMember = FromType->getAs<MemberPointerType>(), |
2772 | *ToMember = ToType->getAs<MemberPointerType>(); |
2773 | if (!Context.hasSameType(FromMember->getClass(), ToMember->getClass())) { |
2774 | PDiag << ft_different_class << QualType(ToMember->getClass(), 0) |
2775 | << QualType(FromMember->getClass(), 0); |
2776 | return; |
2777 | } |
2778 | FromType = FromMember->getPointeeType(); |
2779 | ToType = ToMember->getPointeeType(); |
2780 | } |
2781 | |
2782 | if (FromType->isPointerType()) |
2783 | FromType = FromType->getPointeeType(); |
2784 | if (ToType->isPointerType()) |
2785 | ToType = ToType->getPointeeType(); |
2786 | |
2787 | |
2788 | FromType = FromType.getNonReferenceType(); |
2789 | ToType = ToType.getNonReferenceType(); |
2790 | |
2791 | |
2792 | if (FromType->isInstantiationDependentType() && |
2793 | !FromType->getAs<TemplateSpecializationType>()) { |
2794 | PDiag << ft_default; |
2795 | return; |
2796 | } |
2797 | |
2798 | |
2799 | if (Context.hasSameType(FromType, ToType)) { |
2800 | PDiag << ft_default; |
2801 | return; |
2802 | } |
2803 | |
2804 | const FunctionProtoType *FromFunction = tryGetFunctionProtoType(FromType), |
2805 | *ToFunction = tryGetFunctionProtoType(ToType); |
2806 | |
2807 | |
2808 | if (!FromFunction || !ToFunction) { |
2809 | PDiag << ft_default; |
2810 | return; |
2811 | } |
2812 | |
2813 | if (FromFunction->getNumParams() != ToFunction->getNumParams()) { |
2814 | PDiag << ft_parameter_arity << ToFunction->getNumParams() |
2815 | << FromFunction->getNumParams(); |
2816 | return; |
2817 | } |
2818 | |
2819 | |
2820 | unsigned ArgPos; |
2821 | if (!FunctionParamTypesAreEqual(FromFunction, ToFunction, &ArgPos)) { |
2822 | PDiag << ft_parameter_mismatch << ArgPos + 1 |
2823 | << ToFunction->getParamType(ArgPos) |
2824 | << FromFunction->getParamType(ArgPos); |
2825 | return; |
2826 | } |
2827 | |
2828 | |
2829 | if (!Context.hasSameType(FromFunction->getReturnType(), |
2830 | ToFunction->getReturnType())) { |
2831 | PDiag << ft_return_type << ToFunction->getReturnType() |
2832 | << FromFunction->getReturnType(); |
2833 | return; |
2834 | } |
2835 | |
2836 | if (FromFunction->getMethodQuals() != ToFunction->getMethodQuals()) { |
2837 | PDiag << ft_qualifer_mismatch << ToFunction->getMethodQuals() |
2838 | << FromFunction->getMethodQuals(); |
2839 | return; |
2840 | } |
2841 | |
2842 | |
2843 | |
2844 | if (cast<FunctionProtoType>(FromFunction->getCanonicalTypeUnqualified()) |
2845 | ->isNothrow() != |
2846 | cast<FunctionProtoType>(ToFunction->getCanonicalTypeUnqualified()) |
2847 | ->isNothrow()) { |
2848 | PDiag << ft_noexcept; |
2849 | return; |
2850 | } |
2851 | |
2852 | |
2853 | PDiag << ft_default; |
2854 | } |
2855 | |
2856 | |
2857 | |
2858 | |
2859 | |
2860 | bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType, |
2861 | const FunctionProtoType *NewType, |
2862 | unsigned *ArgPos) { |
2863 | for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(), |
2864 | N = NewType->param_type_begin(), |
2865 | E = OldType->param_type_end(); |
2866 | O && (O != E); ++O, ++N) { |
2867 | if (!Context.hasSameType(O->getUnqualifiedType(), |
2868 | N->getUnqualifiedType())) { |
2869 | if (ArgPos) |
2870 | *ArgPos = O - OldType->param_type_begin(); |
2871 | return false; |
2872 | } |
2873 | } |
2874 | return true; |
2875 | } |
2876 | |
2877 | |
2878 | |
2879 | |
2880 | |
2881 | |
2882 | |
2883 | bool Sema::CheckPointerConversion(Expr *From, QualType ToType, |
2884 | CastKind &Kind, |
2885 | CXXCastPath& BasePath, |
2886 | bool IgnoreBaseAccess, |
2887 | bool Diagnose) { |
2888 | QualType FromType = From->getType(); |
2889 | bool IsCStyleOrFunctionalCast = IgnoreBaseAccess; |
2890 | |
2891 | Kind = CK_BitCast; |
2892 | |
2893 | if (Diagnose && !IsCStyleOrFunctionalCast && !FromType->isAnyPointerType() && |
2894 | From->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull) == |
2895 | Expr::NPCK_ZeroExpression) { |
2896 | if (Context.hasSameUnqualifiedType(From->getType(), Context.BoolTy)) |
2897 | DiagRuntimeBehavior(From->getExprLoc(), From, |
2898 | PDiag(diag::warn_impcast_bool_to_null_pointer) |
2899 | << ToType << From->getSourceRange()); |
2900 | else if (!isUnevaluatedContext()) |
2901 | Diag(From->getExprLoc(), diag::warn_non_literal_null_pointer) |
2902 | << ToType << From->getSourceRange(); |
2903 | } |
2904 | if (const PointerType *ToPtrType = ToType->getAs<PointerType>()) { |
2905 | if (const PointerType *FromPtrType = FromType->getAs<PointerType>()) { |
2906 | QualType FromPointeeType = FromPtrType->getPointeeType(), |
2907 | ToPointeeType = ToPtrType->getPointeeType(); |
2908 | |
2909 | if (FromPointeeType->isRecordType() && ToPointeeType->isRecordType() && |
2910 | !Context.hasSameUnqualifiedType(FromPointeeType, ToPointeeType)) { |
2911 | |
2912 | |
2913 | unsigned InaccessibleID = 0; |
2914 | unsigned AmbigiousID = 0; |
2915 | if (Diagnose) { |
2916 | InaccessibleID = diag::err_upcast_to_inaccessible_base; |
2917 | AmbigiousID = diag::err_ambiguous_derived_to_base_conv; |
2918 | } |
2919 | if (CheckDerivedToBaseConversion( |
2920 | FromPointeeType, ToPointeeType, InaccessibleID, AmbigiousID, |
2921 | From->getExprLoc(), From->getSourceRange(), DeclarationName(), |
2922 | &BasePath, IgnoreBaseAccess)) |
2923 | return true; |
2924 | |
2925 | |
2926 | Kind = CK_DerivedToBase; |
2927 | } |
2928 | |
2929 | if (Diagnose && !IsCStyleOrFunctionalCast && |
2930 | FromPointeeType->isFunctionType() && ToPointeeType->isVoidType()) { |
2931 | (0) . __assert_fail ("getLangOpts().MSVCCompat && \"this should only be possible with MSVCCompat!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 2932, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(getLangOpts().MSVCCompat && |
2932 | (0) . __assert_fail ("getLangOpts().MSVCCompat && \"this should only be possible with MSVCCompat!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 2932, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "this should only be possible with MSVCCompat!"); |
2933 | Diag(From->getExprLoc(), diag::ext_ms_impcast_fn_obj) |
2934 | << From->getSourceRange(); |
2935 | } |
2936 | } |
2937 | } else if (const ObjCObjectPointerType *ToPtrType = |
2938 | ToType->getAs<ObjCObjectPointerType>()) { |
2939 | if (const ObjCObjectPointerType *FromPtrType = |
2940 | FromType->getAs<ObjCObjectPointerType>()) { |
2941 | |
2942 | |
2943 | |
2944 | if (FromPtrType->isObjCBuiltinType() || ToPtrType->isObjCBuiltinType()) |
2945 | return false; |
2946 | } else if (FromType->isBlockPointerType()) { |
2947 | Kind = CK_BlockPointerToObjCPointerCast; |
2948 | } else { |
2949 | Kind = CK_CPointerToObjCPointerCast; |
2950 | } |
2951 | } else if (ToType->isBlockPointerType()) { |
2952 | if (!FromType->isBlockPointerType()) |
2953 | Kind = CK_AnyPointerToBlockPointerCast; |
2954 | } |
2955 | |
2956 | |
2957 | |
2958 | if (From->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull)) |
2959 | Kind = CK_NullToPointer; |
2960 | |
2961 | return false; |
2962 | } |
2963 | |
2964 | |
2965 | |
2966 | |
2967 | |
2968 | |
2969 | bool Sema::IsMemberPointerConversion(Expr *From, QualType FromType, |
2970 | QualType ToType, |
2971 | bool InOverloadResolution, |
2972 | QualType &ConvertedType) { |
2973 | const MemberPointerType *ToTypePtr = ToType->getAs<MemberPointerType>(); |
2974 | if (!ToTypePtr) |
2975 | return false; |
2976 | |
2977 | |
2978 | if (From->isNullPointerConstant(Context, |
2979 | InOverloadResolution? Expr::NPC_ValueDependentIsNotNull |
2980 | : Expr::NPC_ValueDependentIsNull)) { |
2981 | ConvertedType = ToType; |
2982 | return true; |
2983 | } |
2984 | |
2985 | |
2986 | const MemberPointerType *FromTypePtr = FromType->getAs<MemberPointerType>(); |
2987 | if (!FromTypePtr) |
2988 | return false; |
2989 | |
2990 | |
2991 | |
2992 | QualType FromClass(FromTypePtr->getClass(), 0); |
2993 | QualType ToClass(ToTypePtr->getClass(), 0); |
2994 | |
2995 | if (!Context.hasSameUnqualifiedType(FromClass, ToClass) && |
2996 | IsDerivedFrom(From->getBeginLoc(), ToClass, FromClass)) { |
2997 | ConvertedType = Context.getMemberPointerType(FromTypePtr->getPointeeType(), |
2998 | ToClass.getTypePtr()); |
2999 | return true; |
3000 | } |
3001 | |
3002 | return false; |
3003 | } |
3004 | |
3005 | |
3006 | |
3007 | |
3008 | |
3009 | |
3010 | |
3011 | bool Sema::CheckMemberPointerConversion(Expr *From, QualType ToType, |
3012 | CastKind &Kind, |
3013 | CXXCastPath &BasePath, |
3014 | bool IgnoreBaseAccess) { |
3015 | QualType FromType = From->getType(); |
3016 | const MemberPointerType *FromPtrType = FromType->getAs<MemberPointerType>(); |
3017 | if (!FromPtrType) { |
3018 | |
3019 | (0) . __assert_fail ("From->isNullPointerConstant(Context, Expr..NPC_ValueDependentIsNull) && \"Expr must be null pointer constant!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 3021, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(From->isNullPointerConstant(Context, |
3020 | (0) . __assert_fail ("From->isNullPointerConstant(Context, Expr..NPC_ValueDependentIsNull) && \"Expr must be null pointer constant!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 3021, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> Expr::NPC_ValueDependentIsNull) && |
3021 | (0) . __assert_fail ("From->isNullPointerConstant(Context, Expr..NPC_ValueDependentIsNull) && \"Expr must be null pointer constant!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 3021, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Expr must be null pointer constant!"); |
3022 | Kind = CK_NullToMemberPointer; |
3023 | return false; |
3024 | } |
3025 | |
3026 | const MemberPointerType *ToPtrType = ToType->getAs<MemberPointerType>(); |
3027 | (0) . __assert_fail ("ToPtrType && \"No member pointer cast has a target type \" \"that is not a member pointer.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 3028, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ToPtrType && "No member pointer cast has a target type " |
3028 | (0) . __assert_fail ("ToPtrType && \"No member pointer cast has a target type \" \"that is not a member pointer.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 3028, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "that is not a member pointer."); |
3029 | |
3030 | QualType FromClass = QualType(FromPtrType->getClass(), 0); |
3031 | QualType ToClass = QualType(ToPtrType->getClass(), 0); |
3032 | |
3033 | |
3034 | (0) . __assert_fail ("FromClass->isRecordType() && \"Pointer into non-class.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 3034, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(FromClass->isRecordType() && "Pointer into non-class."); |
3035 | (0) . __assert_fail ("ToClass->isRecordType() && \"Pointer into non-class.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 3035, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ToClass->isRecordType() && "Pointer into non-class."); |
3036 | |
3037 | CXXBasePaths Paths(, , |
3038 | ); |
3039 | bool DerivationOkay = |
3040 | IsDerivedFrom(From->getBeginLoc(), ToClass, FromClass, Paths); |
3041 | (0) . __assert_fail ("DerivationOkay && \"Should not have been called if derivation isn't OK.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 3042, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DerivationOkay && |
3042 | (0) . __assert_fail ("DerivationOkay && \"Should not have been called if derivation isn't OK.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 3042, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Should not have been called if derivation isn't OK."); |
3043 | (void)DerivationOkay; |
3044 | |
3045 | if (Paths.isAmbiguous(Context.getCanonicalType(FromClass). |
3046 | getUnqualifiedType())) { |
3047 | std::string PathDisplayStr = getAmbiguousPathsDisplayString(Paths); |
3048 | Diag(From->getExprLoc(), diag::err_ambiguous_memptr_conv) |
3049 | << 0 << FromClass << ToClass << PathDisplayStr << From->getSourceRange(); |
3050 | return true; |
3051 | } |
3052 | |
3053 | if (const RecordType *VBase = Paths.getDetectedVirtual()) { |
3054 | Diag(From->getExprLoc(), diag::err_memptr_conv_via_virtual) |
3055 | << FromClass << ToClass << QualType(VBase, 0) |
3056 | << From->getSourceRange(); |
3057 | return true; |
3058 | } |
3059 | |
3060 | if (!IgnoreBaseAccess) |
3061 | CheckBaseClassAccess(From->getExprLoc(), FromClass, ToClass, |
3062 | Paths.front(), |
3063 | diag::err_downcast_from_inaccessible_base); |
3064 | |
3065 | |
3066 | BuildBasePathArray(Paths, BasePath); |
3067 | Kind = CK_BaseToDerivedMemberPointer; |
3068 | return false; |
3069 | } |
3070 | |
3071 | |
3072 | |
3073 | static bool isNonTrivialObjCLifetimeConversion(Qualifiers FromQuals, |
3074 | Qualifiers ToQuals) { |
3075 | |
3076 | if (ToQuals.hasConst() && |
3077 | ToQuals.getObjCLifetime() == Qualifiers::OCL_ExplicitNone) |
3078 | return false; |
3079 | |
3080 | return true; |
3081 | } |
3082 | |
3083 | |
3084 | |
3085 | |
3086 | |
3087 | |
3088 | |
3089 | |
3090 | bool |
3091 | Sema::IsQualificationConversion(QualType FromType, QualType ToType, |
3092 | bool CStyle, bool &ObjCLifetimeConversion) { |
3093 | FromType = Context.getCanonicalType(FromType); |
3094 | ToType = Context.getCanonicalType(ToType); |
3095 | ObjCLifetimeConversion = false; |
3096 | |
3097 | |
3098 | |
3099 | if (FromType.getUnqualifiedType() == ToType.getUnqualifiedType()) |
3100 | return false; |
3101 | |
3102 | |
3103 | |
3104 | |
3105 | bool PreviousToQualsIncludeConst = true; |
3106 | bool UnwrappedAnyPointer = false; |
3107 | while (Context.UnwrapSimilarTypes(FromType, ToType)) { |
3108 | |
3109 | |
3110 | |
3111 | |
3112 | |
3113 | |
3114 | UnwrappedAnyPointer = true; |
3115 | |
3116 | Qualifiers FromQuals = FromType.getQualifiers(); |
3117 | Qualifiers ToQuals = ToType.getQualifiers(); |
3118 | |
3119 | |
3120 | if (ToType.getUnqualifiedType()->isVoidType()) |
3121 | FromQuals.removeUnaligned(); |
3122 | |
3123 | |
3124 | |
3125 | if (FromQuals.getObjCLifetime() != ToQuals.getObjCLifetime() && |
3126 | UnwrappedAnyPointer) { |
3127 | if (ToQuals.compatiblyIncludesObjCLifetime(FromQuals)) { |
3128 | if (isNonTrivialObjCLifetimeConversion(FromQuals, ToQuals)) |
3129 | ObjCLifetimeConversion = true; |
3130 | FromQuals.removeObjCLifetime(); |
3131 | ToQuals.removeObjCLifetime(); |
3132 | } else { |
3133 | |
3134 | |
3135 | return false; |
3136 | } |
3137 | } |
3138 | |
3139 | |
3140 | if (FromQuals.getObjCGCAttr() != ToQuals.getObjCGCAttr() && |
3141 | (!FromQuals.hasObjCGCAttr() || !ToQuals.hasObjCGCAttr())) { |
3142 | FromQuals.removeObjCGCAttr(); |
3143 | ToQuals.removeObjCGCAttr(); |
3144 | } |
3145 | |
3146 | |
3147 | |
3148 | if (!CStyle && !ToQuals.compatiblyIncludes(FromQuals)) |
3149 | return false; |
3150 | |
3151 | |
3152 | |
3153 | if (!CStyle && FromQuals.getCVRQualifiers() != ToQuals.getCVRQualifiers() |
3154 | && !PreviousToQualsIncludeConst) |
3155 | return false; |
3156 | |
3157 | |
3158 | |
3159 | PreviousToQualsIncludeConst |
3160 | = PreviousToQualsIncludeConst && ToQuals.hasConst(); |
3161 | } |
3162 | |
3163 | |
3164 | |
3165 | Qualifiers FromQuals = FromType.getQualifiers(); |
3166 | Qualifiers ToQuals = ToType.getQualifiers(); |
3167 | if (!ToQuals.isAddressSpaceSupersetOf(FromQuals) && |
3168 | !FromQuals.isAddressSpaceSupersetOf(ToQuals)) { |
3169 | return false; |
3170 | } |
3171 | |
3172 | |
3173 | |
3174 | |
3175 | |
3176 | |
3177 | return UnwrappedAnyPointer && Context.hasSameUnqualifiedType(FromType,ToType); |
3178 | } |
3179 | |
3180 | |
3181 | |
3182 | |
3183 | |
3184 | |
3185 | static bool tryAtomicConversion(Sema &S, Expr *From, QualType ToType, |
3186 | bool InOverloadResolution, |
3187 | StandardConversionSequence &SCS, |
3188 | bool CStyle) { |
3189 | const AtomicType *ToAtomic = ToType->getAs<AtomicType>(); |
3190 | if (!ToAtomic) |
3191 | return false; |
3192 | |
3193 | StandardConversionSequence InnerSCS; |
3194 | if (!IsStandardConversion(S, From, ToAtomic->getValueType(), |
3195 | InOverloadResolution, InnerSCS, |
3196 | CStyle, )) |
3197 | return false; |
3198 | |
3199 | SCS.Second = InnerSCS.Second; |
3200 | SCS.setToType(1, InnerSCS.getToType(1)); |
3201 | SCS.Third = InnerSCS.Third; |
3202 | SCS.QualificationIncludesObjCLifetime |
3203 | = InnerSCS.QualificationIncludesObjCLifetime; |
3204 | SCS.setToType(2, InnerSCS.getToType(2)); |
3205 | return true; |
3206 | } |
3207 | |
3208 | static bool isFirstArgumentCompatibleWithType(ASTContext &Context, |
3209 | CXXConstructorDecl *Constructor, |
3210 | QualType Type) { |
3211 | const FunctionProtoType *CtorType = |
3212 | Constructor->getType()->getAs<FunctionProtoType>(); |
3213 | if (CtorType->getNumParams() > 0) { |
3214 | QualType FirstArg = CtorType->getParamType(0); |
3215 | if (Context.hasSameUnqualifiedType(Type, FirstArg.getNonReferenceType())) |
3216 | return true; |
3217 | } |
3218 | return false; |
3219 | } |
3220 | |
3221 | static OverloadingResult |
3222 | IsInitializerListConstructorConversion(Sema &S, Expr *From, QualType ToType, |
3223 | CXXRecordDecl *To, |
3224 | UserDefinedConversionSequence &User, |
3225 | OverloadCandidateSet &CandidateSet, |
3226 | bool AllowExplicit) { |
3227 | CandidateSet.clear(OverloadCandidateSet::CSK_InitByUserDefinedConversion); |
3228 | for (auto *D : S.LookupConstructors(To)) { |
3229 | auto Info = getConstructorInfo(D); |
3230 | if (!Info) |
3231 | continue; |
3232 | |
3233 | bool Usable = !Info.Constructor->isInvalidDecl() && |
3234 | S.isInitListConstructor(Info.Constructor) && |
3235 | (AllowExplicit || !Info.Constructor->isExplicit()); |
3236 | if (Usable) { |
3237 | |
3238 | |
3239 | bool SuppressUserConversions = isFirstArgumentCompatibleWithType( |
3240 | S.Context, Info.Constructor, ToType); |
3241 | if (Info.ConstructorTmpl) |
3242 | S.AddTemplateOverloadCandidate(Info.ConstructorTmpl, Info.FoundDecl, |
3243 | nullptr, From, |
3244 | CandidateSet, SuppressUserConversions); |
3245 | else |
3246 | S.AddOverloadCandidate(Info.Constructor, Info.FoundDecl, From, |
3247 | CandidateSet, SuppressUserConversions); |
3248 | } |
3249 | } |
3250 | |
3251 | bool HadMultipleCandidates = (CandidateSet.size() > 1); |
3252 | |
3253 | OverloadCandidateSet::iterator Best; |
3254 | switch (auto Result = |
3255 | CandidateSet.BestViableFunction(S, From->getBeginLoc(), Best)) { |
3256 | case OR_Deleted: |
3257 | case OR_Success: { |
3258 | |
3259 | CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(Best->Function); |
3260 | QualType ThisType = Constructor->getThisType(); |
3261 | |
3262 | User.Before.setAsIdentityConversion(); |
3263 | User.HadMultipleCandidates = HadMultipleCandidates; |
3264 | User.ConversionFunction = Constructor; |
3265 | User.FoundConversionFunction = Best->FoundDecl; |
3266 | User.After.setAsIdentityConversion(); |
3267 | User.After.setFromType(ThisType->getAs<PointerType>()->getPointeeType()); |
3268 | User.After.setAllToTypes(ToType); |
3269 | return Result; |
3270 | } |
3271 | |
3272 | case OR_No_Viable_Function: |
3273 | return OR_No_Viable_Function; |
3274 | case OR_Ambiguous: |
3275 | return OR_Ambiguous; |
3276 | } |
3277 | |
3278 | llvm_unreachable("Invalid OverloadResult!"); |
3279 | } |
3280 | |
3281 | |
3282 | |
3283 | |
3284 | |
3285 | |
3286 | |
3287 | |
3288 | |
3289 | |
3290 | |
3291 | |
3292 | |
3293 | |
3294 | |
3295 | static OverloadingResult |
3296 | IsUserDefinedConversion(Sema &S, Expr *From, QualType ToType, |
3297 | UserDefinedConversionSequence &User, |
3298 | OverloadCandidateSet &CandidateSet, |
3299 | bool AllowExplicit, |
3300 | bool AllowObjCConversionOnExplicit) { |
3301 | assert(AllowExplicit || !AllowObjCConversionOnExplicit); |
3302 | CandidateSet.clear(OverloadCandidateSet::CSK_InitByUserDefinedConversion); |
3303 | |
3304 | |
3305 | bool ConstructorsOnly = false; |
3306 | |
3307 | |
3308 | |
3309 | if (const RecordType *ToRecordType = ToType->getAs<RecordType>()) { |
3310 | |
3311 | |
3312 | |
3313 | |
3314 | |
3315 | |
3316 | |
3317 | |
3318 | if (S.Context.hasSameUnqualifiedType(ToType, From->getType()) || |
3319 | (From->getType()->getAs<RecordType>() && |
3320 | S.IsDerivedFrom(From->getBeginLoc(), From->getType(), ToType))) |
3321 | ConstructorsOnly = true; |
3322 | |
3323 | if (!S.isCompleteType(From->getExprLoc(), ToType)) { |
3324 | |
3325 | } else if (CXXRecordDecl *ToRecordDecl |
3326 | = dyn_cast<CXXRecordDecl>(ToRecordType->getDecl())) { |
3327 | |
3328 | Expr **Args = &From; |
3329 | unsigned NumArgs = 1; |
3330 | bool ListInitializing = false; |
3331 | if (InitListExpr *InitList = dyn_cast<InitListExpr>(From)) { |
3332 | |
3333 | OverloadingResult Result = IsInitializerListConstructorConversion( |
3334 | S, From, ToType, ToRecordDecl, User, CandidateSet, AllowExplicit); |
3335 | if (Result != OR_No_Viable_Function) |
3336 | return Result; |
3337 | |
3338 | CandidateSet.clear( |
3339 | OverloadCandidateSet::CSK_InitByUserDefinedConversion); |
3340 | |
3341 | |
3342 | |
3343 | Args = InitList->getInits(); |
3344 | NumArgs = InitList->getNumInits(); |
3345 | ListInitializing = true; |
3346 | } |
3347 | |
3348 | for (auto *D : S.LookupConstructors(ToRecordDecl)) { |
3349 | auto Info = getConstructorInfo(D); |
3350 | if (!Info) |
3351 | continue; |
3352 | |
3353 | bool Usable = !Info.Constructor->isInvalidDecl(); |
3354 | if (ListInitializing) |
3355 | Usable = Usable && (AllowExplicit || !Info.Constructor->isExplicit()); |
3356 | else |
3357 | Usable = Usable && |
3358 | Info.Constructor->isConvertingConstructor(AllowExplicit); |
3359 | if (Usable) { |
3360 | bool SuppressUserConversions = !ConstructorsOnly; |
3361 | if (SuppressUserConversions && ListInitializing) { |
3362 | SuppressUserConversions = false; |
3363 | if (NumArgs == 1) { |
3364 | |
3365 | |
3366 | SuppressUserConversions = isFirstArgumentCompatibleWithType( |
3367 | S.Context, Info.Constructor, ToType); |
3368 | } |
3369 | } |
3370 | if (Info.ConstructorTmpl) |
3371 | S.AddTemplateOverloadCandidate( |
3372 | Info.ConstructorTmpl, Info.FoundDecl, |
3373 | nullptr, llvm::makeArrayRef(Args, NumArgs), |
3374 | CandidateSet, SuppressUserConversions); |
3375 | else |
3376 | |
3377 | |
3378 | S.AddOverloadCandidate(Info.Constructor, Info.FoundDecl, |
3379 | llvm::makeArrayRef(Args, NumArgs), |
3380 | CandidateSet, SuppressUserConversions); |
3381 | } |
3382 | } |
3383 | } |
3384 | } |
3385 | |
3386 | |
3387 | if (ConstructorsOnly || isa<InitListExpr>(From)) { |
3388 | } else if (!S.isCompleteType(From->getBeginLoc(), From->getType())) { |
3389 | |
3390 | } else if (const RecordType *FromRecordType = |
3391 | From->getType()->getAs<RecordType>()) { |
3392 | if (CXXRecordDecl *FromRecordDecl |
3393 | = dyn_cast<CXXRecordDecl>(FromRecordType->getDecl())) { |
3394 | |
3395 | const auto &Conversions = FromRecordDecl->getVisibleConversionFunctions(); |
3396 | for (auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) { |
3397 | DeclAccessPair FoundDecl = I.getPair(); |
3398 | NamedDecl *D = FoundDecl.getDecl(); |
3399 | CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(D->getDeclContext()); |
3400 | if (isa<UsingShadowDecl>(D)) |
3401 | D = cast<UsingShadowDecl>(D)->getTargetDecl(); |
3402 | |
3403 | CXXConversionDecl *Conv; |
3404 | FunctionTemplateDecl *ConvTemplate; |
3405 | if ((ConvTemplate = dyn_cast<FunctionTemplateDecl>(D))) |
3406 | Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl()); |
3407 | else |
3408 | Conv = cast<CXXConversionDecl>(D); |
3409 | |
3410 | if (AllowExplicit || !Conv->isExplicit()) { |
3411 | if (ConvTemplate) |
3412 | S.AddTemplateConversionCandidate(ConvTemplate, FoundDecl, |
3413 | ActingContext, From, ToType, |
3414 | CandidateSet, |
3415 | AllowObjCConversionOnExplicit); |
3416 | else |
3417 | S.AddConversionCandidate(Conv, FoundDecl, ActingContext, |
3418 | From, ToType, CandidateSet, |
3419 | AllowObjCConversionOnExplicit); |
3420 | } |
3421 | } |
3422 | } |
3423 | } |
3424 | |
3425 | bool HadMultipleCandidates = (CandidateSet.size() > 1); |
3426 | |
3427 | OverloadCandidateSet::iterator Best; |
3428 | switch (auto Result = |
3429 | CandidateSet.BestViableFunction(S, From->getBeginLoc(), Best)) { |
3430 | case OR_Success: |
3431 | case OR_Deleted: |
3432 | |
3433 | if (CXXConstructorDecl *Constructor |
3434 | = dyn_cast<CXXConstructorDecl>(Best->Function)) { |
3435 | |
3436 | |
3437 | |
3438 | |
3439 | |
3440 | |
3441 | QualType ThisType = Constructor->getThisType(); |
3442 | if (isa<InitListExpr>(From)) { |
3443 | |
3444 | User.Before.setAsIdentityConversion(); |
3445 | } else { |
3446 | if (Best->Conversions[0].isEllipsis()) |
3447 | User.EllipsisConversion = true; |
3448 | else { |
3449 | User.Before = Best->Conversions[0].Standard; |
3450 | User.EllipsisConversion = false; |
3451 | } |
3452 | } |
3453 | User.HadMultipleCandidates = HadMultipleCandidates; |
3454 | User.ConversionFunction = Constructor; |
3455 | User.FoundConversionFunction = Best->FoundDecl; |
3456 | User.After.setAsIdentityConversion(); |
3457 | User.After.setFromType(ThisType->getAs<PointerType>()->getPointeeType()); |
3458 | User.After.setAllToTypes(ToType); |
3459 | return Result; |
3460 | } |
3461 | if (CXXConversionDecl *Conversion |
3462 | = dyn_cast<CXXConversionDecl>(Best->Function)) { |
3463 | |
3464 | |
3465 | |
3466 | |
3467 | |
3468 | |
3469 | User.Before = Best->Conversions[0].Standard; |
3470 | User.HadMultipleCandidates = HadMultipleCandidates; |
3471 | User.ConversionFunction = Conversion; |
3472 | User.FoundConversionFunction = Best->FoundDecl; |
3473 | User.EllipsisConversion = false; |
3474 | |
3475 | |
3476 | |
3477 | |
3478 | |
3479 | |
3480 | |
3481 | |
3482 | |
3483 | |
3484 | User.After = Best->FinalConversion; |
3485 | return Result; |
3486 | } |
3487 | llvm_unreachable("Not a constructor or conversion function?"); |
3488 | |
3489 | case OR_No_Viable_Function: |
3490 | return OR_No_Viable_Function; |
3491 | |
3492 | case OR_Ambiguous: |
3493 | return OR_Ambiguous; |
3494 | } |
3495 | |
3496 | llvm_unreachable("Invalid OverloadResult!"); |
3497 | } |
3498 | |
3499 | bool |
3500 | Sema::DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType) { |
3501 | ImplicitConversionSequence ICS; |
3502 | OverloadCandidateSet CandidateSet(From->getExprLoc(), |
3503 | OverloadCandidateSet::CSK_Normal); |
3504 | OverloadingResult OvResult = |
3505 | IsUserDefinedConversion(*this, From, ToType, ICS.UserDefined, |
3506 | CandidateSet, false, false); |
3507 | if (OvResult == OR_Ambiguous) |
3508 | Diag(From->getBeginLoc(), diag::err_typecheck_ambiguous_condition) |
3509 | << From->getType() << ToType << From->getSourceRange(); |
3510 | else if (OvResult == OR_No_Viable_Function && !CandidateSet.empty()) { |
3511 | if (!RequireCompleteType(From->getBeginLoc(), ToType, |
3512 | diag::err_typecheck_nonviable_condition_incomplete, |
3513 | From->getType(), From->getSourceRange())) |
3514 | Diag(From->getBeginLoc(), diag::err_typecheck_nonviable_condition) |
3515 | << false << From->getType() << From->getSourceRange() << ToType; |
3516 | } else |
3517 | return false; |
3518 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, From); |
3519 | return true; |
3520 | } |
3521 | |
3522 | |
3523 | |
3524 | |
3525 | static ImplicitConversionSequence::CompareKind |
3526 | compareConversionFunctions(Sema &S, FunctionDecl *Function1, |
3527 | FunctionDecl *Function2) { |
3528 | if (!S.getLangOpts().ObjC || !S.getLangOpts().CPlusPlus11) |
3529 | return ImplicitConversionSequence::Indistinguishable; |
3530 | |
3531 | |
3532 | |
3533 | |
3534 | |
3535 | |
3536 | |
3537 | CXXConversionDecl *Conv1 = dyn_cast_or_null<CXXConversionDecl>(Function1); |
3538 | if (!Conv1) |
3539 | return ImplicitConversionSequence::Indistinguishable; |
3540 | |
3541 | CXXConversionDecl *Conv2 = dyn_cast<CXXConversionDecl>(Function2); |
3542 | if (!Conv2) |
3543 | return ImplicitConversionSequence::Indistinguishable; |
3544 | |
3545 | if (Conv1->getParent()->isLambda() && Conv2->getParent()->isLambda()) { |
3546 | bool Block1 = Conv1->getConversionType()->isBlockPointerType(); |
3547 | bool Block2 = Conv2->getConversionType()->isBlockPointerType(); |
3548 | if (Block1 != Block2) |
3549 | return Block1 ? ImplicitConversionSequence::Worse |
3550 | : ImplicitConversionSequence::Better; |
3551 | } |
3552 | |
3553 | return ImplicitConversionSequence::Indistinguishable; |
3554 | } |
3555 | |
3556 | static bool hasDeprecatedStringLiteralToCharPtrConversion( |
3557 | const ImplicitConversionSequence &ICS) { |
3558 | return (ICS.isStandard() && ICS.Standard.DeprecatedStringLiteralToCharPtr) || |
3559 | (ICS.isUserDefined() && |
3560 | ICS.UserDefined.Before.DeprecatedStringLiteralToCharPtr); |
3561 | } |
3562 | |
3563 | |
3564 | |
3565 | |
3566 | static ImplicitConversionSequence::CompareKind |
3567 | CompareImplicitConversionSequences(Sema &S, SourceLocation Loc, |
3568 | const ImplicitConversionSequence& ICS1, |
3569 | const ImplicitConversionSequence& ICS2) |
3570 | { |
3571 | |
3572 | |
3573 | |
3574 | |
3575 | |
3576 | |
3577 | |
3578 | |
3579 | |
3580 | |
3581 | |
3582 | |
3583 | |
3584 | |
3585 | |
3586 | |
3587 | |
3588 | |
3589 | |
3590 | |
3591 | |
3592 | |
3593 | |
3594 | |
3595 | |
3596 | |
3597 | |
3598 | |
3599 | |
3600 | |
3601 | |
3602 | |
3603 | |
3604 | if (S.getLangOpts().CPlusPlus11 && !S.getLangOpts().WritableStrings && |
3605 | hasDeprecatedStringLiteralToCharPtrConversion(ICS1) != |
3606 | hasDeprecatedStringLiteralToCharPtrConversion(ICS2)) |
3607 | return hasDeprecatedStringLiteralToCharPtrConversion(ICS1) |
3608 | ? ImplicitConversionSequence::Worse |
3609 | : ImplicitConversionSequence::Better; |
3610 | |
3611 | if (ICS1.getKindRank() < ICS2.getKindRank()) |
3612 | return ImplicitConversionSequence::Better; |
3613 | if (ICS2.getKindRank() < ICS1.getKindRank()) |
3614 | return ImplicitConversionSequence::Worse; |
3615 | |
3616 | |
3617 | |
3618 | if (ICS1.getKind() != ICS2.getKind()) |
3619 | return ImplicitConversionSequence::Indistinguishable; |
3620 | |
3621 | ImplicitConversionSequence::CompareKind Result = |
3622 | ImplicitConversionSequence::Indistinguishable; |
3623 | |
3624 | |
3625 | |
3626 | |
3627 | |
3628 | |
3629 | |
3630 | |
3631 | |
3632 | |
3633 | |
3634 | |
3635 | if (!ICS1.isBad()) { |
3636 | if (ICS1.isStdInitializerListElement() && |
3637 | !ICS2.isStdInitializerListElement()) |
3638 | return ImplicitConversionSequence::Better; |
3639 | if (!ICS1.isStdInitializerListElement() && |
3640 | ICS2.isStdInitializerListElement()) |
3641 | return ImplicitConversionSequence::Worse; |
3642 | } |
3643 | |
3644 | if (ICS1.isStandard()) |
3645 | |
3646 | |
3647 | Result = CompareStandardConversionSequences(S, Loc, |
3648 | ICS1.Standard, ICS2.Standard); |
3649 | else if (ICS1.isUserDefined()) { |
3650 | |
3651 | |
3652 | |
3653 | |
3654 | |
3655 | |
3656 | if (ICS1.UserDefined.ConversionFunction == |
3657 | ICS2.UserDefined.ConversionFunction) |
3658 | Result = CompareStandardConversionSequences(S, Loc, |
3659 | ICS1.UserDefined.After, |
3660 | ICS2.UserDefined.After); |
3661 | else |
3662 | Result = compareConversionFunctions(S, |
3663 | ICS1.UserDefined.ConversionFunction, |
3664 | ICS2.UserDefined.ConversionFunction); |
3665 | } |
3666 | |
3667 | return Result; |
3668 | } |
3669 | |
3670 | |
3671 | |
3672 | static ImplicitConversionSequence::CompareKind |
3673 | compareStandardConversionSubsets(ASTContext &Context, |
3674 | const StandardConversionSequence& SCS1, |
3675 | const StandardConversionSequence& SCS2) { |
3676 | ImplicitConversionSequence::CompareKind Result |
3677 | = ImplicitConversionSequence::Indistinguishable; |
3678 | |
3679 | |
3680 | |
3681 | if (SCS1.isIdentityConversion() && !SCS2.isIdentityConversion()) |
3682 | return ImplicitConversionSequence::Better; |
3683 | else if (!SCS1.isIdentityConversion() && SCS2.isIdentityConversion()) |
3684 | return ImplicitConversionSequence::Worse; |
3685 | |
3686 | if (SCS1.Second != SCS2.Second) { |
3687 | if (SCS1.Second == ICK_Identity) |
3688 | Result = ImplicitConversionSequence::Better; |
3689 | else if (SCS2.Second == ICK_Identity) |
3690 | Result = ImplicitConversionSequence::Worse; |
3691 | else |
3692 | return ImplicitConversionSequence::Indistinguishable; |
3693 | } else if (!Context.hasSimilarType(SCS1.getToType(1), SCS2.getToType(1))) |
3694 | return ImplicitConversionSequence::Indistinguishable; |
3695 | |
3696 | if (SCS1.Third == SCS2.Third) { |
3697 | return Context.hasSameType(SCS1.getToType(2), SCS2.getToType(2))? Result |
3698 | : ImplicitConversionSequence::Indistinguishable; |
3699 | } |
3700 | |
3701 | if (SCS1.Third == ICK_Identity) |
3702 | return Result == ImplicitConversionSequence::Worse |
3703 | ? ImplicitConversionSequence::Indistinguishable |
3704 | : ImplicitConversionSequence::Better; |
3705 | |
3706 | if (SCS2.Third == ICK_Identity) |
3707 | return Result == ImplicitConversionSequence::Better |
3708 | ? ImplicitConversionSequence::Indistinguishable |
3709 | : ImplicitConversionSequence::Worse; |
3710 | |
3711 | return ImplicitConversionSequence::Indistinguishable; |
3712 | } |
3713 | |
3714 | |
3715 | |
3716 | static bool |
3717 | isBetterReferenceBindingKind(const StandardConversionSequence &SCS1, |
3718 | const StandardConversionSequence &SCS2) { |
3719 | |
3720 | |
3721 | |
3722 | |
3723 | |
3724 | |
3725 | |
3726 | |
3727 | |
3728 | |
3729 | |
3730 | |
3731 | |
3732 | if (SCS1.BindsImplicitObjectArgumentWithoutRefQualifier || |
3733 | SCS2.BindsImplicitObjectArgumentWithoutRefQualifier) |
3734 | return false; |
3735 | |
3736 | return (!SCS1.IsLvalueReference && SCS1.BindsToRvalue && |
3737 | SCS2.IsLvalueReference) || |
3738 | (SCS1.IsLvalueReference && SCS1.BindsToFunctionLvalue && |
3739 | !SCS2.IsLvalueReference && SCS2.BindsToFunctionLvalue); |
3740 | } |
3741 | |
3742 | |
3743 | |
3744 | |
3745 | static ImplicitConversionSequence::CompareKind |
3746 | CompareStandardConversionSequences(Sema &S, SourceLocation Loc, |
3747 | const StandardConversionSequence& SCS1, |
3748 | const StandardConversionSequence& SCS2) |
3749 | { |
3750 | |
3751 | |
3752 | |
3753 | |
3754 | |
3755 | |
3756 | |
3757 | |
3758 | if (ImplicitConversionSequence::CompareKind CK |
3759 | = compareStandardConversionSubsets(S.Context, SCS1, SCS2)) |
3760 | return CK; |
3761 | |
3762 | |
3763 | |
3764 | ImplicitConversionRank Rank1 = SCS1.getRank(); |
3765 | ImplicitConversionRank Rank2 = SCS2.getRank(); |
3766 | if (Rank1 < Rank2) |
3767 | return ImplicitConversionSequence::Better; |
3768 | else if (Rank2 < Rank1) |
3769 | return ImplicitConversionSequence::Worse; |
3770 | |
3771 | |
3772 | |
3773 | |
3774 | |
3775 | |
3776 | |
3777 | |
3778 | if (SCS1.isPointerConversionToBool() != SCS2.isPointerConversionToBool()) |
3779 | return SCS2.isPointerConversionToBool() |
3780 | ? ImplicitConversionSequence::Better |
3781 | : ImplicitConversionSequence::Worse; |
3782 | |
3783 | |
3784 | |
3785 | |
3786 | |
3787 | |
3788 | |
3789 | bool SCS1ConvertsToVoid |
3790 | = SCS1.isPointerConversionToVoidPointer(S.Context); |
3791 | bool SCS2ConvertsToVoid |
3792 | = SCS2.isPointerConversionToVoidPointer(S.Context); |
3793 | if (SCS1ConvertsToVoid != SCS2ConvertsToVoid) { |
3794 | |
3795 | |
3796 | return SCS2ConvertsToVoid ? ImplicitConversionSequence::Better |
3797 | : ImplicitConversionSequence::Worse; |
3798 | } else if (!SCS1ConvertsToVoid && !SCS2ConvertsToVoid) { |
3799 | |
3800 | |
3801 | if (ImplicitConversionSequence::CompareKind DerivedCK |
3802 | = CompareDerivedToBaseConversions(S, Loc, SCS1, SCS2)) |
3803 | return DerivedCK; |
3804 | } else if (SCS1ConvertsToVoid && SCS2ConvertsToVoid && |
3805 | !S.Context.hasSameType(SCS1.getFromType(), SCS2.getFromType())) { |
3806 | |
3807 | |
3808 | |
3809 | QualType FromType1 = SCS1.getFromType(); |
3810 | QualType FromType2 = SCS2.getFromType(); |
3811 | |
3812 | |
3813 | |
3814 | if (SCS1.First == ICK_Array_To_Pointer) |
3815 | FromType1 = S.Context.getArrayDecayedType(FromType1); |
3816 | if (SCS2.First == ICK_Array_To_Pointer) |
3817 | FromType2 = S.Context.getArrayDecayedType(FromType2); |
3818 | |
3819 | QualType FromPointee1 = FromType1->getPointeeType().getUnqualifiedType(); |
3820 | QualType FromPointee2 = FromType2->getPointeeType().getUnqualifiedType(); |
3821 | |
3822 | if (S.IsDerivedFrom(Loc, FromPointee2, FromPointee1)) |
3823 | return ImplicitConversionSequence::Better; |
3824 | else if (S.IsDerivedFrom(Loc, FromPointee1, FromPointee2)) |
3825 | return ImplicitConversionSequence::Worse; |
3826 | |
3827 | |
3828 | |
3829 | const ObjCObjectPointerType* FromObjCPtr1 |
3830 | = FromType1->getAs<ObjCObjectPointerType>(); |
3831 | const ObjCObjectPointerType* FromObjCPtr2 |
3832 | = FromType2->getAs<ObjCObjectPointerType>(); |
3833 | if (FromObjCPtr1 && FromObjCPtr2) { |
3834 | bool AssignLeft = S.Context.canAssignObjCInterfaces(FromObjCPtr1, |
3835 | FromObjCPtr2); |
3836 | bool AssignRight = S.Context.canAssignObjCInterfaces(FromObjCPtr2, |
3837 | FromObjCPtr1); |
3838 | if (AssignLeft != AssignRight) { |
3839 | return AssignLeft? ImplicitConversionSequence::Better |
3840 | : ImplicitConversionSequence::Worse; |
3841 | } |
3842 | } |
3843 | } |
3844 | |
3845 | |
3846 | |
3847 | if (ImplicitConversionSequence::CompareKind QualCK |
3848 | = CompareQualificationConversions(S, SCS1, SCS2)) |
3849 | return QualCK; |
3850 | |
3851 | if (SCS1.ReferenceBinding && SCS2.ReferenceBinding) { |
3852 | |
3853 | if (isBetterReferenceBindingKind(SCS1, SCS2)) |
3854 | return ImplicitConversionSequence::Better; |
3855 | else if (isBetterReferenceBindingKind(SCS2, SCS1)) |
3856 | return ImplicitConversionSequence::Worse; |
3857 | |
3858 | |
3859 | |
3860 | |
3861 | |
3862 | |
3863 | |
3864 | QualType T1 = SCS1.getToType(2); |
3865 | QualType T2 = SCS2.getToType(2); |
3866 | T1 = S.Context.getCanonicalType(T1); |
3867 | T2 = S.Context.getCanonicalType(T2); |
3868 | Qualifiers T1Quals, T2Quals; |
3869 | QualType UnqualT1 = S.Context.getUnqualifiedArrayType(T1, T1Quals); |
3870 | QualType UnqualT2 = S.Context.getUnqualifiedArrayType(T2, T2Quals); |
3871 | if (UnqualT1 == UnqualT2) { |
3872 | |
3873 | |
3874 | if (SCS1.ObjCLifetimeConversionBinding != |
3875 | SCS2.ObjCLifetimeConversionBinding) { |
3876 | return SCS1.ObjCLifetimeConversionBinding |
3877 | ? ImplicitConversionSequence::Worse |
3878 | : ImplicitConversionSequence::Better; |
3879 | } |
3880 | |
3881 | |
3882 | |
3883 | if (isa<ArrayType>(T1) && T1Quals) |
3884 | T1 = S.Context.getQualifiedType(UnqualT1, T1Quals); |
3885 | if (isa<ArrayType>(T2) && T2Quals) |
3886 | T2 = S.Context.getQualifiedType(UnqualT2, T2Quals); |
3887 | if (T2.isMoreQualifiedThan(T1)) |
3888 | return ImplicitConversionSequence::Better; |
3889 | else if (T1.isMoreQualifiedThan(T2)) |
3890 | return ImplicitConversionSequence::Worse; |
3891 | } |
3892 | } |
3893 | |
3894 | |
3895 | |
3896 | |
3897 | |
3898 | |
3899 | |
3900 | |
3901 | |
3902 | |
3903 | |
3904 | |
3905 | |
3906 | if (S.getLangOpts().MSVCCompat && SCS1.Second == ICK_Integral_Conversion && |
3907 | SCS2.Second == ICK_Floating_Integral && |
3908 | S.Context.getTypeSize(SCS1.getFromType()) == |
3909 | S.Context.getTypeSize(SCS1.getToType(2))) |
3910 | return ImplicitConversionSequence::Better; |
3911 | |
3912 | |
3913 | |
3914 | |
3915 | |
3916 | |
3917 | |
3918 | |
3919 | |
3920 | |
3921 | |
3922 | |
3923 | |
3924 | if (SCS1.Second == ICK_Vector_Conversion && |
3925 | SCS2.Second == ICK_Vector_Conversion) { |
3926 | bool SCS1IsCompatibleVectorConversion = S.Context.areCompatibleVectorTypes( |
3927 | SCS1.getFromType(), SCS1.getToType(2)); |
3928 | bool SCS2IsCompatibleVectorConversion = S.Context.areCompatibleVectorTypes( |
3929 | SCS2.getFromType(), SCS2.getToType(2)); |
3930 | |
3931 | if (SCS1IsCompatibleVectorConversion != SCS2IsCompatibleVectorConversion) |
3932 | return SCS1IsCompatibleVectorConversion |
3933 | ? ImplicitConversionSequence::Better |
3934 | : ImplicitConversionSequence::Worse; |
3935 | } |
3936 | |
3937 | return ImplicitConversionSequence::Indistinguishable; |
3938 | } |
3939 | |
3940 | |
3941 | |
3942 | |
3943 | static ImplicitConversionSequence::CompareKind |
3944 | CompareQualificationConversions(Sema &S, |
3945 | const StandardConversionSequence& SCS1, |
3946 | const StandardConversionSequence& SCS2) { |
3947 | |
3948 | |
3949 | |
3950 | |
3951 | |
3952 | |
3953 | if (SCS1.First != SCS2.First || SCS1.Second != SCS2.Second || |
3954 | SCS1.Third != SCS2.Third || SCS1.Third != ICK_Qualification) |
3955 | return ImplicitConversionSequence::Indistinguishable; |
3956 | |
3957 | |
3958 | |
3959 | QualType T1 = SCS1.getToType(2); |
3960 | QualType T2 = SCS2.getToType(2); |
3961 | T1 = S.Context.getCanonicalType(T1); |
3962 | T2 = S.Context.getCanonicalType(T2); |
3963 | Qualifiers T1Quals, T2Quals; |
3964 | QualType UnqualT1 = S.Context.getUnqualifiedArrayType(T1, T1Quals); |
3965 | QualType UnqualT2 = S.Context.getUnqualifiedArrayType(T2, T2Quals); |
3966 | |
3967 | |
3968 | |
3969 | if (UnqualT1 == UnqualT2) |
3970 | return ImplicitConversionSequence::Indistinguishable; |
3971 | |
3972 | |
3973 | |
3974 | if (isa<ArrayType>(T1) && T1Quals) |
3975 | T1 = S.Context.getQualifiedType(UnqualT1, T1Quals); |
3976 | if (isa<ArrayType>(T2) && T2Quals) |
3977 | T2 = S.Context.getQualifiedType(UnqualT2, T2Quals); |
3978 | |
3979 | ImplicitConversionSequence::CompareKind Result |
3980 | = ImplicitConversionSequence::Indistinguishable; |
3981 | |
3982 | |
3983 | |
3984 | |
3985 | if (SCS1.QualificationIncludesObjCLifetime != |
3986 | SCS2.QualificationIncludesObjCLifetime) { |
3987 | Result = SCS1.QualificationIncludesObjCLifetime |
3988 | ? ImplicitConversionSequence::Worse |
3989 | : ImplicitConversionSequence::Better; |
3990 | } |
3991 | |
3992 | while (S.Context.UnwrapSimilarTypes(T1, T2)) { |
3993 | |
3994 | |
3995 | |
3996 | |
3997 | |
3998 | |
3999 | |
4000 | |
4001 | if (T1.getQualifiers().withoutObjCLifetime() == |
4002 | T2.getQualifiers().withoutObjCLifetime()) |
4003 | |
4004 | |
4005 | |
4006 | |
4007 | ; |
4008 | else if (T2.isMoreQualifiedThan(T1)) { |
4009 | |
4010 | if (Result == ImplicitConversionSequence::Worse) |
4011 | |
4012 | |
4013 | return ImplicitConversionSequence::Indistinguishable; |
4014 | |
4015 | Result = ImplicitConversionSequence::Better; |
4016 | } else if (T1.isMoreQualifiedThan(T2)) { |
4017 | |
4018 | if (Result == ImplicitConversionSequence::Better) |
4019 | |
4020 | |
4021 | return ImplicitConversionSequence::Indistinguishable; |
4022 | |
4023 | Result = ImplicitConversionSequence::Worse; |
4024 | } else { |
4025 | |
4026 | return ImplicitConversionSequence::Indistinguishable; |
4027 | } |
4028 | |
4029 | |
4030 | if (S.Context.hasSameUnqualifiedType(T1, T2)) |
4031 | break; |
4032 | } |
4033 | |
4034 | |
4035 | |
4036 | switch (Result) { |
4037 | case ImplicitConversionSequence::Better: |
4038 | if (SCS1.DeprecatedStringLiteralToCharPtr) |
4039 | Result = ImplicitConversionSequence::Indistinguishable; |
4040 | break; |
4041 | |
4042 | case ImplicitConversionSequence::Indistinguishable: |
4043 | break; |
4044 | |
4045 | case ImplicitConversionSequence::Worse: |
4046 | if (SCS2.DeprecatedStringLiteralToCharPtr) |
4047 | Result = ImplicitConversionSequence::Indistinguishable; |
4048 | break; |
4049 | } |
4050 | |
4051 | return Result; |
4052 | } |
4053 | |
4054 | |
4055 | |
4056 | |
4057 | |
4058 | |
4059 | static ImplicitConversionSequence::CompareKind |
4060 | CompareDerivedToBaseConversions(Sema &S, SourceLocation Loc, |
4061 | const StandardConversionSequence& SCS1, |
4062 | const StandardConversionSequence& SCS2) { |
4063 | QualType FromType1 = SCS1.getFromType(); |
4064 | QualType ToType1 = SCS1.getToType(1); |
4065 | QualType FromType2 = SCS2.getFromType(); |
4066 | QualType ToType2 = SCS2.getToType(1); |
4067 | |
4068 | |
4069 | |
4070 | if (SCS1.First == ICK_Array_To_Pointer) |
4071 | FromType1 = S.Context.getArrayDecayedType(FromType1); |
4072 | if (SCS2.First == ICK_Array_To_Pointer) |
4073 | FromType2 = S.Context.getArrayDecayedType(FromType2); |
4074 | |
4075 | |
4076 | FromType1 = S.Context.getCanonicalType(FromType1); |
4077 | ToType1 = S.Context.getCanonicalType(ToType1); |
4078 | FromType2 = S.Context.getCanonicalType(FromType2); |
4079 | ToType2 = S.Context.getCanonicalType(ToType2); |
4080 | |
4081 | |
4082 | |
4083 | |
4084 | |
4085 | |
4086 | |
4087 | if (SCS1.Second == ICK_Pointer_Conversion && |
4088 | SCS2.Second == ICK_Pointer_Conversion && |
4089 | |
4090 | FromType1->isPointerType() && FromType2->isPointerType() && |
4091 | ToType1->isPointerType() && ToType2->isPointerType()) { |
4092 | QualType FromPointee1 |
4093 | = FromType1->getAs<PointerType>()->getPointeeType().getUnqualifiedType(); |
4094 | QualType ToPointee1 |
4095 | = ToType1->getAs<PointerType>()->getPointeeType().getUnqualifiedType(); |
4096 | QualType FromPointee2 |
4097 | = FromType2->getAs<PointerType>()->getPointeeType().getUnqualifiedType(); |
4098 | QualType ToPointee2 |
4099 | = ToType2->getAs<PointerType>()->getPointeeType().getUnqualifiedType(); |
4100 | |
4101 | |
4102 | if (FromPointee1 == FromPointee2 && ToPointee1 != ToPointee2) { |
4103 | if (S.IsDerivedFrom(Loc, ToPointee1, ToPointee2)) |
4104 | return ImplicitConversionSequence::Better; |
4105 | else if (S.IsDerivedFrom(Loc, ToPointee2, ToPointee1)) |
4106 | return ImplicitConversionSequence::Worse; |
4107 | } |
4108 | |
4109 | |
4110 | if (FromPointee1 != FromPointee2 && ToPointee1 == ToPointee2) { |
4111 | if (S.IsDerivedFrom(Loc, FromPointee2, FromPointee1)) |
4112 | return ImplicitConversionSequence::Better; |
4113 | else if (S.IsDerivedFrom(Loc, FromPointee1, FromPointee2)) |
4114 | return ImplicitConversionSequence::Worse; |
4115 | } |
4116 | } else if (SCS1.Second == ICK_Pointer_Conversion && |
4117 | SCS2.Second == ICK_Pointer_Conversion) { |
4118 | const ObjCObjectPointerType *FromPtr1 |
4119 | = FromType1->getAs<ObjCObjectPointerType>(); |
4120 | const ObjCObjectPointerType *FromPtr2 |
4121 | = FromType2->getAs<ObjCObjectPointerType>(); |
4122 | const ObjCObjectPointerType *ToPtr1 |
4123 | = ToType1->getAs<ObjCObjectPointerType>(); |
4124 | const ObjCObjectPointerType *ToPtr2 |
4125 | = ToType2->getAs<ObjCObjectPointerType>(); |
4126 | |
4127 | if (FromPtr1 && FromPtr2 && ToPtr1 && ToPtr2) { |
4128 | |
4129 | |
4130 | |
4131 | |
4132 | bool FromAssignLeft |
4133 | = S.Context.canAssignObjCInterfaces(FromPtr1, FromPtr2); |
4134 | bool FromAssignRight |
4135 | = S.Context.canAssignObjCInterfaces(FromPtr2, FromPtr1); |
4136 | bool ToAssignLeft |
4137 | = S.Context.canAssignObjCInterfaces(ToPtr1, ToPtr2); |
4138 | bool ToAssignRight |
4139 | = S.Context.canAssignObjCInterfaces(ToPtr2, ToPtr1); |
4140 | |
4141 | |
4142 | |
4143 | if (ToPtr1->isObjCIdType() && |
4144 | (ToPtr2->isObjCQualifiedIdType() || ToPtr2->getInterfaceDecl())) |
4145 | return ImplicitConversionSequence::Worse; |
4146 | if (ToPtr2->isObjCIdType() && |
4147 | (ToPtr1->isObjCQualifiedIdType() || ToPtr1->getInterfaceDecl())) |
4148 | return ImplicitConversionSequence::Better; |
4149 | |
4150 | |
4151 | |
4152 | if (ToPtr1->isObjCQualifiedIdType() && ToPtr2->getInterfaceDecl()) |
4153 | return ImplicitConversionSequence::Worse; |
4154 | if (ToPtr2->isObjCQualifiedIdType() && ToPtr1->getInterfaceDecl()) |
4155 | return ImplicitConversionSequence::Better; |
4156 | |
4157 | |
4158 | |
4159 | if (ToPtr1->isObjCClassType() && |
4160 | (ToPtr2->isObjCQualifiedClassType() || ToPtr2->getInterfaceDecl())) |
4161 | return ImplicitConversionSequence::Worse; |
4162 | if (ToPtr2->isObjCClassType() && |
4163 | (ToPtr1->isObjCQualifiedClassType() || ToPtr1->getInterfaceDecl())) |
4164 | return ImplicitConversionSequence::Better; |
4165 | |
4166 | |
4167 | |
4168 | if (ToPtr1->isObjCQualifiedClassType() && ToPtr2->getInterfaceDecl()) |
4169 | return ImplicitConversionSequence::Worse; |
4170 | if (ToPtr2->isObjCQualifiedClassType() && ToPtr1->getInterfaceDecl()) |
4171 | return ImplicitConversionSequence::Better; |
4172 | |
4173 | |
4174 | if (S.Context.hasSameType(FromType1, FromType2) && |
4175 | !FromPtr1->isObjCIdType() && !FromPtr1->isObjCClassType() && |
4176 | (ToAssignLeft != ToAssignRight)) { |
4177 | if (FromPtr1->isSpecialized()) { |
4178 | |
4179 | |
4180 | bool IsFirstSame = |
4181 | FromPtr1->getInterfaceDecl() == ToPtr1->getInterfaceDecl(); |
4182 | bool IsSecondSame = |
4183 | FromPtr1->getInterfaceDecl() == ToPtr2->getInterfaceDecl(); |
4184 | if (IsFirstSame) { |
4185 | if (!IsSecondSame) |
4186 | return ImplicitConversionSequence::Better; |
4187 | } else if (IsSecondSame) |
4188 | return ImplicitConversionSequence::Worse; |
4189 | } |
4190 | return ToAssignLeft? ImplicitConversionSequence::Worse |
4191 | : ImplicitConversionSequence::Better; |
4192 | } |
4193 | |
4194 | |
4195 | if (S.Context.hasSameUnqualifiedType(ToType1, ToType2) && |
4196 | (FromAssignLeft != FromAssignRight)) |
4197 | return FromAssignLeft? ImplicitConversionSequence::Better |
4198 | : ImplicitConversionSequence::Worse; |
4199 | } |
4200 | } |
4201 | |
4202 | |
4203 | if (SCS1.Second == ICK_Pointer_Member && SCS2.Second == ICK_Pointer_Member && |
4204 | FromType1->isMemberPointerType() && FromType2->isMemberPointerType() && |
4205 | ToType1->isMemberPointerType() && ToType2->isMemberPointerType()) { |
4206 | const MemberPointerType * FromMemPointer1 = |
4207 | FromType1->getAs<MemberPointerType>(); |
4208 | const MemberPointerType * ToMemPointer1 = |
4209 | ToType1->getAs<MemberPointerType>(); |
4210 | const MemberPointerType * FromMemPointer2 = |
4211 | FromType2->getAs<MemberPointerType>(); |
4212 | const MemberPointerType * ToMemPointer2 = |
4213 | ToType2->getAs<MemberPointerType>(); |
4214 | const Type *FromPointeeType1 = FromMemPointer1->getClass(); |
4215 | const Type *ToPointeeType1 = ToMemPointer1->getClass(); |
4216 | const Type *FromPointeeType2 = FromMemPointer2->getClass(); |
4217 | const Type *ToPointeeType2 = ToMemPointer2->getClass(); |
4218 | QualType FromPointee1 = QualType(FromPointeeType1, 0).getUnqualifiedType(); |
4219 | QualType ToPointee1 = QualType(ToPointeeType1, 0).getUnqualifiedType(); |
4220 | QualType FromPointee2 = QualType(FromPointeeType2, 0).getUnqualifiedType(); |
4221 | QualType ToPointee2 = QualType(ToPointeeType2, 0).getUnqualifiedType(); |
4222 | |
4223 | if (FromPointee1 == FromPointee2 && ToPointee1 != ToPointee2) { |
4224 | if (S.IsDerivedFrom(Loc, ToPointee1, ToPointee2)) |
4225 | return ImplicitConversionSequence::Worse; |
4226 | else if (S.IsDerivedFrom(Loc, ToPointee2, ToPointee1)) |
4227 | return ImplicitConversionSequence::Better; |
4228 | } |
4229 | |
4230 | if (ToPointee1 == ToPointee2 && FromPointee1 != FromPointee2) { |
4231 | if (S.IsDerivedFrom(Loc, FromPointee1, FromPointee2)) |
4232 | return ImplicitConversionSequence::Better; |
4233 | else if (S.IsDerivedFrom(Loc, FromPointee2, FromPointee1)) |
4234 | return ImplicitConversionSequence::Worse; |
4235 | } |
4236 | } |
4237 | |
4238 | if (SCS1.Second == ICK_Derived_To_Base) { |
4239 | |
4240 | |
4241 | |
4242 | |
4243 | if (S.Context.hasSameUnqualifiedType(FromType1, FromType2) && |
4244 | !S.Context.hasSameUnqualifiedType(ToType1, ToType2)) { |
4245 | if (S.IsDerivedFrom(Loc, ToType1, ToType2)) |
4246 | return ImplicitConversionSequence::Better; |
4247 | else if (S.IsDerivedFrom(Loc, ToType2, ToType1)) |
4248 | return ImplicitConversionSequence::Worse; |
4249 | } |
4250 | |
4251 | |
4252 | |
4253 | |
4254 | |
4255 | if (!S.Context.hasSameUnqualifiedType(FromType1, FromType2) && |
4256 | S.Context.hasSameUnqualifiedType(ToType1, ToType2)) { |
4257 | if (S.IsDerivedFrom(Loc, FromType2, FromType1)) |
4258 | return ImplicitConversionSequence::Better; |
4259 | else if (S.IsDerivedFrom(Loc, FromType1, FromType2)) |
4260 | return ImplicitConversionSequence::Worse; |
4261 | } |
4262 | } |
4263 | |
4264 | return ImplicitConversionSequence::Indistinguishable; |
4265 | } |
4266 | |
4267 | |
4268 | |
4269 | static bool isTypeValid(QualType T) { |
4270 | if (CXXRecordDecl *Record = T->getAsCXXRecordDecl()) |
4271 | return !Record->isInvalidDecl(); |
4272 | |
4273 | return true; |
4274 | } |
4275 | |
4276 | |
4277 | |
4278 | |
4279 | |
4280 | |
4281 | |
4282 | |
4283 | Sema::ReferenceCompareResult |
4284 | Sema::CompareReferenceRelationship(SourceLocation Loc, |
4285 | QualType OrigT1, QualType OrigT2, |
4286 | bool &DerivedToBase, |
4287 | bool &ObjCConversion, |
4288 | bool &ObjCLifetimeConversion) { |
4289 | (0) . __assert_fail ("!OrigT1->isReferenceType() && \"T1 must be the pointee type of the reference type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 4290, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!OrigT1->isReferenceType() && |
4290 | (0) . __assert_fail ("!OrigT1->isReferenceType() && \"T1 must be the pointee type of the reference type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 4290, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "T1 must be the pointee type of the reference type"); |
4291 | (0) . __assert_fail ("!OrigT2->isReferenceType() && \"T2 cannot be a reference type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 4291, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!OrigT2->isReferenceType() && "T2 cannot be a reference type"); |
4292 | |
4293 | QualType T1 = Context.getCanonicalType(OrigT1); |
4294 | QualType T2 = Context.getCanonicalType(OrigT2); |
4295 | Qualifiers T1Quals, T2Quals; |
4296 | QualType UnqualT1 = Context.getUnqualifiedArrayType(T1, T1Quals); |
4297 | QualType UnqualT2 = Context.getUnqualifiedArrayType(T2, T2Quals); |
4298 | |
4299 | |
4300 | |
4301 | |
4302 | |
4303 | DerivedToBase = false; |
4304 | ObjCConversion = false; |
4305 | ObjCLifetimeConversion = false; |
4306 | QualType ConvertedT2; |
4307 | if (UnqualT1 == UnqualT2) { |
4308 | |
4309 | } else if (isCompleteType(Loc, OrigT2) && |
4310 | isTypeValid(UnqualT1) && isTypeValid(UnqualT2) && |
4311 | IsDerivedFrom(Loc, UnqualT2, UnqualT1)) |
4312 | DerivedToBase = true; |
4313 | else if (UnqualT1->isObjCObjectOrInterfaceType() && |
4314 | UnqualT2->isObjCObjectOrInterfaceType() && |
4315 | Context.canBindObjCObjectType(UnqualT1, UnqualT2)) |
4316 | ObjCConversion = true; |
4317 | else if (UnqualT2->isFunctionType() && |
4318 | IsFunctionConversion(UnqualT2, UnqualT1, ConvertedT2)) |
4319 | |
4320 | |
4321 | |
4322 | |
4323 | |
4324 | |
4325 | return Ref_Compatible; |
4326 | else |
4327 | return Ref_Incompatible; |
4328 | |
4329 | |
4330 | |
4331 | |
4332 | |
4333 | |
4334 | if (isa<ArrayType>(T1) && T1Quals) |
4335 | T1 = Context.getQualifiedType(UnqualT1, T1Quals); |
4336 | if (isa<ArrayType>(T2) && T2Quals) |
4337 | T2 = Context.getQualifiedType(UnqualT2, T2Quals); |
4338 | |
4339 | |
4340 | |
4341 | |
4342 | |
4343 | |
4344 | |
4345 | |
4346 | |
4347 | |
4348 | |
4349 | |
4350 | |
4351 | if (T1Quals.getObjCLifetime() != T2Quals.getObjCLifetime() && |
4352 | T1Quals.compatiblyIncludesObjCLifetime(T2Quals)) { |
4353 | if (isNonTrivialObjCLifetimeConversion(T2Quals, T1Quals)) |
4354 | ObjCLifetimeConversion = true; |
4355 | |
4356 | T1Quals.removeObjCLifetime(); |
4357 | T2Quals.removeObjCLifetime(); |
4358 | } |
4359 | |
4360 | |
4361 | T1Quals.removeUnaligned(); |
4362 | T2Quals.removeUnaligned(); |
4363 | |
4364 | if (T1Quals.compatiblyIncludes(T2Quals)) |
4365 | return Ref_Compatible; |
4366 | else |
4367 | return Ref_Related; |
4368 | } |
4369 | |
4370 | |
4371 | |
4372 | static bool |
4373 | FindConversionForRefInit(Sema &S, ImplicitConversionSequence &ICS, |
4374 | QualType DeclType, SourceLocation DeclLoc, |
4375 | Expr *Init, QualType T2, bool AllowRvalues, |
4376 | bool AllowExplicit) { |
4377 | (0) . __assert_fail ("T2->isRecordType() && \"Can only find conversions of record types.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 4377, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(T2->isRecordType() && "Can only find conversions of record types."); |
4378 | CXXRecordDecl *T2RecordDecl |
4379 | = dyn_cast<CXXRecordDecl>(T2->getAs<RecordType>()->getDecl()); |
4380 | |
4381 | OverloadCandidateSet CandidateSet( |
4382 | DeclLoc, OverloadCandidateSet::CSK_InitByUserDefinedConversion); |
4383 | const auto &Conversions = T2RecordDecl->getVisibleConversionFunctions(); |
4384 | for (auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) { |
4385 | NamedDecl *D = *I; |
4386 | CXXRecordDecl *ActingDC = cast<CXXRecordDecl>(D->getDeclContext()); |
4387 | if (isa<UsingShadowDecl>(D)) |
4388 | D = cast<UsingShadowDecl>(D)->getTargetDecl(); |
4389 | |
4390 | FunctionTemplateDecl *ConvTemplate |
4391 | = dyn_cast<FunctionTemplateDecl>(D); |
4392 | CXXConversionDecl *Conv; |
4393 | if (ConvTemplate) |
4394 | Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl()); |
4395 | else |
4396 | Conv = cast<CXXConversionDecl>(D); |
4397 | |
4398 | |
4399 | |
4400 | if (!AllowExplicit && Conv->isExplicit()) |
4401 | continue; |
4402 | |
4403 | if (AllowRvalues) { |
4404 | bool DerivedToBase = false; |
4405 | bool ObjCConversion = false; |
4406 | bool ObjCLifetimeConversion = false; |
4407 | |
4408 | |
4409 | |
4410 | if (!ConvTemplate && DeclType->isRValueReferenceType()) { |
4411 | const ReferenceType *RefType |
4412 | = Conv->getConversionType()->getAs<LValueReferenceType>(); |
4413 | if (RefType && !RefType->getPointeeType()->isFunctionType()) |
4414 | continue; |
4415 | } |
4416 | |
4417 | if (!ConvTemplate && |
4418 | S.CompareReferenceRelationship( |
4419 | DeclLoc, |
4420 | Conv->getConversionType().getNonReferenceType() |
4421 | .getUnqualifiedType(), |
4422 | DeclType.getNonReferenceType().getUnqualifiedType(), |
4423 | DerivedToBase, ObjCConversion, ObjCLifetimeConversion) == |
4424 | Sema::Ref_Incompatible) |
4425 | continue; |
4426 | } else { |
4427 | |
4428 | |
4429 | |
4430 | |
4431 | const ReferenceType *RefType = |
4432 | Conv->getConversionType()->getAs<ReferenceType>(); |
4433 | if (!RefType || |
4434 | (!RefType->isLValueReferenceType() && |
4435 | !RefType->getPointeeType()->isFunctionType())) |
4436 | continue; |
4437 | } |
4438 | |
4439 | if (ConvTemplate) |
4440 | S.AddTemplateConversionCandidate(ConvTemplate, I.getPair(), ActingDC, |
4441 | Init, DeclType, CandidateSet, |
4442 | ); |
4443 | else |
4444 | S.AddConversionCandidate(Conv, I.getPair(), ActingDC, Init, |
4445 | DeclType, CandidateSet, |
4446 | ); |
4447 | } |
4448 | |
4449 | bool HadMultipleCandidates = (CandidateSet.size() > 1); |
4450 | |
4451 | OverloadCandidateSet::iterator Best; |
4452 | switch (CandidateSet.BestViableFunction(S, DeclLoc, Best)) { |
4453 | case OR_Success: |
4454 | |
4455 | |
4456 | |
4457 | |
4458 | |
4459 | |
4460 | |
4461 | |
4462 | |
4463 | |
4464 | if (!Best->FinalConversion.DirectBinding) |
4465 | return false; |
4466 | |
4467 | ICS.setUserDefined(); |
4468 | ICS.UserDefined.Before = Best->Conversions[0].Standard; |
4469 | ICS.UserDefined.After = Best->FinalConversion; |
4470 | ICS.UserDefined.HadMultipleCandidates = HadMultipleCandidates; |
4471 | ICS.UserDefined.ConversionFunction = Best->Function; |
4472 | ICS.UserDefined.FoundConversionFunction = Best->FoundDecl; |
4473 | ICS.UserDefined.EllipsisConversion = false; |
4474 | (0) . __assert_fail ("ICS.UserDefined.After.ReferenceBinding && ICS.UserDefined.After.DirectBinding && \"Expected a direct reference binding!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 4476, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ICS.UserDefined.After.ReferenceBinding && |
4475 | (0) . __assert_fail ("ICS.UserDefined.After.ReferenceBinding && ICS.UserDefined.After.DirectBinding && \"Expected a direct reference binding!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 4476, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> ICS.UserDefined.After.DirectBinding && |
4476 | (0) . __assert_fail ("ICS.UserDefined.After.ReferenceBinding && ICS.UserDefined.After.DirectBinding && \"Expected a direct reference binding!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 4476, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Expected a direct reference binding!"); |
4477 | return true; |
4478 | |
4479 | case OR_Ambiguous: |
4480 | ICS.setAmbiguous(); |
4481 | for (OverloadCandidateSet::iterator Cand = CandidateSet.begin(); |
4482 | Cand != CandidateSet.end(); ++Cand) |
4483 | if (Cand->Viable) |
4484 | ICS.Ambiguous.addConversion(Cand->FoundDecl, Cand->Function); |
4485 | return true; |
4486 | |
4487 | case OR_No_Viable_Function: |
4488 | case OR_Deleted: |
4489 | |
4490 | |
4491 | return false; |
4492 | } |
4493 | |
4494 | llvm_unreachable("Invalid OverloadResult!"); |
4495 | } |
4496 | |
4497 | |
4498 | |
4499 | static ImplicitConversionSequence |
4500 | TryReferenceInit(Sema &S, Expr *Init, QualType DeclType, |
4501 | SourceLocation DeclLoc, |
4502 | bool SuppressUserConversions, |
4503 | bool AllowExplicit) { |
4504 | (0) . __assert_fail ("DeclType->isReferenceType() && \"Reference init needs a reference\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 4504, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DeclType->isReferenceType() && "Reference init needs a reference"); |
4505 | |
4506 | |
4507 | ImplicitConversionSequence ICS; |
4508 | ICS.setBad(BadConversionSequence::no_conversion, Init, DeclType); |
4509 | |
4510 | QualType T1 = DeclType->getAs<ReferenceType>()->getPointeeType(); |
4511 | QualType T2 = Init->getType(); |
4512 | |
4513 | |
4514 | |
4515 | |
4516 | if (S.Context.getCanonicalType(T2) == S.Context.OverloadTy) { |
4517 | DeclAccessPair Found; |
4518 | if (FunctionDecl *Fn = S.ResolveAddressOfOverloadedFunction(Init, DeclType, |
4519 | false, Found)) |
4520 | T2 = Fn->getType(); |
4521 | } |
4522 | |
4523 | |
4524 | bool isRValRef = DeclType->isRValueReferenceType(); |
4525 | bool DerivedToBase = false; |
4526 | bool ObjCConversion = false; |
4527 | bool ObjCLifetimeConversion = false; |
4528 | Expr::Classification InitCategory = Init->Classify(S.Context); |
4529 | Sema::ReferenceCompareResult RefRelationship |
4530 | = S.CompareReferenceRelationship(DeclLoc, T1, T2, DerivedToBase, |
4531 | ObjCConversion, ObjCLifetimeConversion); |
4532 | |
4533 | |
4534 | |
4535 | |
4536 | |
4537 | |
4538 | |
4539 | if (!isRValRef) { |
4540 | |
4541 | |
4542 | |
4543 | |
4544 | if (InitCategory.isLValue() && RefRelationship == Sema::Ref_Compatible) { |
4545 | |
4546 | |
4547 | |
4548 | |
4549 | |
4550 | |
4551 | |
4552 | ICS.setStandard(); |
4553 | ICS.Standard.First = ICK_Identity; |
4554 | ICS.Standard.Second = DerivedToBase? ICK_Derived_To_Base |
4555 | : ObjCConversion? ICK_Compatible_Conversion |
4556 | : ICK_Identity; |
4557 | ICS.Standard.Third = ICK_Identity; |
4558 | ICS.Standard.FromTypePtr = T2.getAsOpaquePtr(); |
4559 | ICS.Standard.setToType(0, T2); |
4560 | ICS.Standard.setToType(1, T1); |
4561 | ICS.Standard.setToType(2, T1); |
4562 | ICS.Standard.ReferenceBinding = true; |
4563 | ICS.Standard.DirectBinding = true; |
4564 | ICS.Standard.IsLvalueReference = !isRValRef; |
4565 | ICS.Standard.BindsToFunctionLvalue = T2->isFunctionType(); |
4566 | ICS.Standard.BindsToRvalue = false; |
4567 | ICS.Standard.BindsImplicitObjectArgumentWithoutRefQualifier = false; |
4568 | ICS.Standard.ObjCLifetimeConversionBinding = ObjCLifetimeConversion; |
4569 | ICS.Standard.CopyConstructor = nullptr; |
4570 | ICS.Standard.DeprecatedStringLiteralToCharPtr = false; |
4571 | |
4572 | |
4573 | |
4574 | |
4575 | |
4576 | return ICS; |
4577 | } |
4578 | |
4579 | |
4580 | |
4581 | |
4582 | |
4583 | |
4584 | |
4585 | |
4586 | if (!SuppressUserConversions && T2->isRecordType() && |
4587 | S.isCompleteType(DeclLoc, T2) && |
4588 | RefRelationship == Sema::Ref_Incompatible) { |
4589 | if (FindConversionForRefInit(S, ICS, DeclType, DeclLoc, |
4590 | Init, T2, , |
4591 | AllowExplicit)) |
4592 | return ICS; |
4593 | } |
4594 | } |
4595 | |
4596 | |
4597 | |
4598 | |
4599 | if (!isRValRef && (!T1.isConstQualified() || T1.isVolatileQualified())) |
4600 | return ICS; |
4601 | |
4602 | |
4603 | |
4604 | |
4605 | |
4606 | if (RefRelationship == Sema::Ref_Compatible && |
4607 | (InitCategory.isXValue() || |
4608 | (InitCategory.isPRValue() && (T2->isRecordType() || T2->isArrayType())) || |
4609 | (InitCategory.isLValue() && T2->isFunctionType()))) { |
4610 | ICS.setStandard(); |
4611 | ICS.Standard.First = ICK_Identity; |
4612 | ICS.Standard.Second = DerivedToBase? ICK_Derived_To_Base |
4613 | : ObjCConversion? ICK_Compatible_Conversion |
4614 | : ICK_Identity; |
4615 | ICS.Standard.Third = ICK_Identity; |
4616 | ICS.Standard.FromTypePtr = T2.getAsOpaquePtr(); |
4617 | ICS.Standard.setToType(0, T2); |
4618 | ICS.Standard.setToType(1, T1); |
4619 | ICS.Standard.setToType(2, T1); |
4620 | ICS.Standard.ReferenceBinding = true; |
4621 | |
4622 | |
4623 | |
4624 | |
4625 | |
4626 | ICS.Standard.DirectBinding = |
4627 | S.getLangOpts().CPlusPlus11 || |
4628 | !(InitCategory.isPRValue() || T2->isRecordType()); |
4629 | ICS.Standard.IsLvalueReference = !isRValRef; |
4630 | ICS.Standard.BindsToFunctionLvalue = T2->isFunctionType(); |
4631 | ICS.Standard.BindsToRvalue = InitCategory.isRValue(); |
4632 | ICS.Standard.BindsImplicitObjectArgumentWithoutRefQualifier = false; |
4633 | ICS.Standard.ObjCLifetimeConversionBinding = ObjCLifetimeConversion; |
4634 | ICS.Standard.CopyConstructor = nullptr; |
4635 | ICS.Standard.DeprecatedStringLiteralToCharPtr = false; |
4636 | return ICS; |
4637 | } |
4638 | |
4639 | |
4640 | |
4641 | |
4642 | |
4643 | |
4644 | |
4645 | |
4646 | |
4647 | |
4648 | |
4649 | if (!SuppressUserConversions && RefRelationship == Sema::Ref_Incompatible && |
4650 | T2->isRecordType() && S.isCompleteType(DeclLoc, T2) && |
4651 | FindConversionForRefInit(S, ICS, DeclType, DeclLoc, |
4652 | Init, T2, , |
4653 | AllowExplicit)) { |
4654 | |
4655 | |
4656 | |
4657 | |
4658 | if (ICS.isUserDefined() && isRValRef && |
4659 | ICS.UserDefined.After.First == ICK_Lvalue_To_Rvalue) |
4660 | ICS.setBad(BadConversionSequence::no_conversion, Init, DeclType); |
4661 | |
4662 | return ICS; |
4663 | } |
4664 | |
4665 | |
4666 | if (T1->isFunctionType()) |
4667 | return ICS; |
4668 | |
4669 | |
4670 | |
4671 | |
4672 | |
4673 | |
4674 | |
4675 | |
4676 | if (RefRelationship == Sema::Ref_Related) { |
4677 | |
4678 | |
4679 | |
4680 | |
4681 | |
4682 | |
4683 | |
4684 | Qualifiers T1Quals = T1.getQualifiers(); |
4685 | Qualifiers T2Quals = T2.getQualifiers(); |
4686 | T1Quals.removeObjCGCAttr(); |
4687 | T1Quals.removeObjCLifetime(); |
4688 | T2Quals.removeObjCGCAttr(); |
4689 | T2Quals.removeObjCLifetime(); |
4690 | |
4691 | T1Quals.removeUnaligned(); |
4692 | T2Quals.removeUnaligned(); |
4693 | if (!T1Quals.compatiblyIncludes(T2Quals)) |
4694 | return ICS; |
4695 | } |
4696 | |
4697 | |
4698 | |
4699 | |
4700 | |
4701 | |
4702 | if (SuppressUserConversions && RefRelationship == Sema::Ref_Incompatible && |
4703 | (T1->isRecordType() || T2->isRecordType())) |
4704 | return ICS; |
4705 | |
4706 | |
4707 | |
4708 | if (RefRelationship >= Sema::Ref_Related && |
4709 | isRValRef && Init->Classify(S.Context).isLValue()) |
4710 | return ICS; |
4711 | |
4712 | |
4713 | |
4714 | |
4715 | |
4716 | |
4717 | |
4718 | |
4719 | |
4720 | |
4721 | |
4722 | ICS = TryImplicitConversion(S, Init, T1, SuppressUserConversions, |
4723 | , |
4724 | , |
4725 | , |
4726 | , |
4727 | ); |
4728 | |
4729 | |
4730 | if (ICS.isStandard()) { |
4731 | ICS.Standard.ReferenceBinding = true; |
4732 | ICS.Standard.IsLvalueReference = !isRValRef; |
4733 | ICS.Standard.BindsToFunctionLvalue = false; |
4734 | ICS.Standard.BindsToRvalue = true; |
4735 | ICS.Standard.BindsImplicitObjectArgumentWithoutRefQualifier = false; |
4736 | ICS.Standard.ObjCLifetimeConversionBinding = false; |
4737 | } else if (ICS.isUserDefined()) { |
4738 | const ReferenceType *LValRefType = |
4739 | ICS.UserDefined.ConversionFunction->getReturnType() |
4740 | ->getAs<LValueReferenceType>(); |
4741 | |
4742 | |
4743 | |
4744 | |
4745 | |
4746 | |
4747 | |
4748 | if (DeclType->isRValueReferenceType() && LValRefType) { |
4749 | |
4750 | |
4751 | |
4752 | ICS.setBad(BadConversionSequence::lvalue_ref_to_rvalue, Init, DeclType); |
4753 | return ICS; |
4754 | } |
4755 | |
4756 | ICS.UserDefined.After.ReferenceBinding = true; |
4757 | ICS.UserDefined.After.IsLvalueReference = !isRValRef; |
4758 | ICS.UserDefined.After.BindsToFunctionLvalue = false; |
4759 | ICS.UserDefined.After.BindsToRvalue = !LValRefType; |
4760 | ICS.UserDefined.After.BindsImplicitObjectArgumentWithoutRefQualifier = false; |
4761 | ICS.UserDefined.After.ObjCLifetimeConversionBinding = false; |
4762 | } |
4763 | |
4764 | return ICS; |
4765 | } |
4766 | |
4767 | static ImplicitConversionSequence |
4768 | TryCopyInitialization(Sema &S, Expr *From, QualType ToType, |
4769 | bool SuppressUserConversions, |
4770 | bool InOverloadResolution, |
4771 | bool AllowObjCWritebackConversion, |
4772 | bool AllowExplicit = false); |
4773 | |
4774 | |
4775 | |
4776 | static ImplicitConversionSequence |
4777 | TryListConversion(Sema &S, InitListExpr *From, QualType ToType, |
4778 | bool SuppressUserConversions, |
4779 | bool InOverloadResolution, |
4780 | bool AllowObjCWritebackConversion) { |
4781 | |
4782 | |
4783 | |
4784 | |
4785 | ImplicitConversionSequence Result; |
4786 | Result.setBad(BadConversionSequence::no_conversion, From, ToType); |
4787 | |
4788 | |
4789 | |
4790 | if (!S.isCompleteType(From->getBeginLoc(), ToType)) |
4791 | return Result; |
4792 | |
4793 | |
4794 | |
4795 | |
4796 | |
4797 | |
4798 | |
4799 | |
4800 | |
4801 | |
4802 | |
4803 | if (From->getNumInits() == 1) { |
4804 | if (ToType->isRecordType()) { |
4805 | QualType InitType = From->getInit(0)->getType(); |
4806 | if (S.Context.hasSameUnqualifiedType(InitType, ToType) || |
4807 | S.IsDerivedFrom(From->getBeginLoc(), InitType, ToType)) |
4808 | return TryCopyInitialization(S, From->getInit(0), ToType, |
4809 | SuppressUserConversions, |
4810 | InOverloadResolution, |
4811 | AllowObjCWritebackConversion); |
4812 | } |
4813 | |
4814 | |
4815 | if (ToType->isArrayType()) { |
4816 | InitializedEntity Entity = |
4817 | InitializedEntity::InitializeParameter(S.Context, ToType, |
4818 | ); |
4819 | if (S.CanPerformCopyInitialization(Entity, From)) { |
4820 | Result.setStandard(); |
4821 | Result.Standard.setAsIdentityConversion(); |
4822 | Result.Standard.setFromType(ToType); |
4823 | Result.Standard.setAllToTypes(ToType); |
4824 | return Result; |
4825 | } |
4826 | } |
4827 | } |
4828 | |
4829 | |
4830 | |
4831 | |
4832 | |
4833 | |
4834 | |
4835 | |
4836 | |
4837 | |
4838 | |
4839 | |
4840 | |
4841 | |
4842 | |
4843 | |
4844 | bool toStdInitializerList = false; |
4845 | QualType X; |
4846 | if (ToType->isArrayType()) |
4847 | X = S.Context.getAsArrayType(ToType)->getElementType(); |
4848 | else |
4849 | toStdInitializerList = S.isStdInitializerList(ToType, &X); |
4850 | if (!X.isNull()) { |
4851 | for (unsigned i = 0, e = From->getNumInits(); i < e; ++i) { |
4852 | Expr *Init = From->getInit(i); |
4853 | ImplicitConversionSequence ICS = |
4854 | TryCopyInitialization(S, Init, X, SuppressUserConversions, |
4855 | InOverloadResolution, |
4856 | AllowObjCWritebackConversion); |
4857 | |
4858 | if (ICS.isBad()) { |
4859 | Result = ICS; |
4860 | break; |
4861 | } |
4862 | |
4863 | if (Result.isBad() || CompareImplicitConversionSequences( |
4864 | S, From->getBeginLoc(), ICS, Result) == |
4865 | ImplicitConversionSequence::Worse) |
4866 | Result = ICS; |
4867 | } |
4868 | |
4869 | |
4870 | |
4871 | if (From->getNumInits() == 0) { |
4872 | Result.setStandard(); |
4873 | Result.Standard.setAsIdentityConversion(); |
4874 | Result.Standard.setFromType(ToType); |
4875 | Result.Standard.setAllToTypes(ToType); |
4876 | } |
4877 | |
4878 | Result.setStdInitializerListElement(toStdInitializerList); |
4879 | return Result; |
4880 | } |
4881 | |
4882 | |
4883 | |
4884 | |
4885 | |
4886 | |
4887 | |
4888 | |
4889 | if (ToType->isRecordType() && !ToType->isAggregateType()) { |
4890 | |
4891 | return TryUserDefinedConversion(S, From, ToType, SuppressUserConversions, |
4892 | , |
4893 | InOverloadResolution, , |
4894 | AllowObjCWritebackConversion, |
4895 | ); |
4896 | } |
4897 | |
4898 | |
4899 | |
4900 | |
4901 | |
4902 | |
4903 | if (ToType->isAggregateType()) { |
4904 | |
4905 | |
4906 | |
4907 | |
4908 | |
4909 | |
4910 | InitializedEntity Entity = |
4911 | InitializedEntity::InitializeParameter(S.Context, ToType, |
4912 | ); |
4913 | if (S.CanPerformCopyInitialization(Entity, From)) { |
4914 | Result.setUserDefined(); |
4915 | Result.UserDefined.Before.setAsIdentityConversion(); |
4916 | |
4917 | Result.UserDefined.Before.setFromType(QualType()); |
4918 | Result.UserDefined.Before.setAllToTypes(QualType()); |
4919 | |
4920 | Result.UserDefined.After.setAsIdentityConversion(); |
4921 | Result.UserDefined.After.setFromType(ToType); |
4922 | Result.UserDefined.After.setAllToTypes(ToType); |
4923 | Result.UserDefined.ConversionFunction = nullptr; |
4924 | } |
4925 | return Result; |
4926 | } |
4927 | |
4928 | |
4929 | |
4930 | |
4931 | if (ToType->isReferenceType()) { |
4932 | |
4933 | |
4934 | |
4935 | |
4936 | QualType T1 = ToType->getAs<ReferenceType>()->getPointeeType(); |
4937 | |
4938 | |
4939 | |
4940 | if (From->getNumInits() == 1) { |
4941 | Expr *Init = From->getInit(0); |
4942 | |
4943 | QualType T2 = Init->getType(); |
4944 | |
4945 | |
4946 | |
4947 | |
4948 | if (S.Context.getCanonicalType(T2) == S.Context.OverloadTy) { |
4949 | DeclAccessPair Found; |
4950 | if (FunctionDecl *Fn = S.ResolveAddressOfOverloadedFunction( |
4951 | Init, ToType, false, Found)) |
4952 | T2 = Fn->getType(); |
4953 | } |
4954 | |
4955 | |
4956 | bool dummy1 = false; |
4957 | bool dummy2 = false; |
4958 | bool dummy3 = false; |
4959 | Sema::ReferenceCompareResult RefRelationship = |
4960 | S.CompareReferenceRelationship(From->getBeginLoc(), T1, T2, dummy1, |
4961 | dummy2, dummy3); |
4962 | |
4963 | if (RefRelationship >= Sema::Ref_Related) { |
4964 | return TryReferenceInit(S, Init, ToType, From->getBeginLoc(), |
4965 | SuppressUserConversions, |
4966 | ); |
4967 | } |
4968 | } |
4969 | |
4970 | |
4971 | |
4972 | Result = TryListConversion(S, From, T1, SuppressUserConversions, |
4973 | InOverloadResolution, |
4974 | AllowObjCWritebackConversion); |
4975 | if (Result.isFailure()) |
4976 | return Result; |
4977 | (0) . __assert_fail ("!Result.isEllipsis() && \"Sub-initialization cannot result in ellipsis conversion.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 4978, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Result.isEllipsis() && |
4978 | (0) . __assert_fail ("!Result.isEllipsis() && \"Sub-initialization cannot result in ellipsis conversion.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 4978, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Sub-initialization cannot result in ellipsis conversion."); |
4979 | |
4980 | |
4981 | if (ToType->isRValueReferenceType() || |
4982 | (T1.isConstQualified() && !T1.isVolatileQualified())) { |
4983 | StandardConversionSequence &SCS = Result.isStandard() ? Result.Standard : |
4984 | Result.UserDefined.After; |
4985 | SCS.ReferenceBinding = true; |
4986 | SCS.IsLvalueReference = ToType->isLValueReferenceType(); |
4987 | SCS.BindsToRvalue = true; |
4988 | SCS.BindsToFunctionLvalue = false; |
4989 | SCS.BindsImplicitObjectArgumentWithoutRefQualifier = false; |
4990 | SCS.ObjCLifetimeConversionBinding = false; |
4991 | } else |
4992 | Result.setBad(BadConversionSequence::lvalue_ref_to_rvalue, |
4993 | From, ToType); |
4994 | return Result; |
4995 | } |
4996 | |
4997 | |
4998 | |
4999 | |
5000 | if (!ToType->isRecordType()) { |
5001 | |
5002 | |
5003 | |
5004 | unsigned NumInits = From->getNumInits(); |
5005 | if (NumInits == 1 && !isa<InitListExpr>(From->getInit(0))) |
5006 | Result = TryCopyInitialization(S, From->getInit(0), ToType, |
5007 | SuppressUserConversions, |
5008 | InOverloadResolution, |
5009 | AllowObjCWritebackConversion); |
5010 | |
5011 | |
5012 | else if (NumInits == 0) { |
5013 | Result.setStandard(); |
5014 | Result.Standard.setAsIdentityConversion(); |
5015 | Result.Standard.setFromType(ToType); |
5016 | Result.Standard.setAllToTypes(ToType); |
5017 | } |
5018 | return Result; |
5019 | } |
5020 | |
5021 | |
5022 | |
5023 | |
5024 | return Result; |
5025 | } |
5026 | |
5027 | |
5028 | |
5029 | |
5030 | |
5031 | |
5032 | |
5033 | static ImplicitConversionSequence |
5034 | TryCopyInitialization(Sema &S, Expr *From, QualType ToType, |
5035 | bool SuppressUserConversions, |
5036 | bool InOverloadResolution, |
5037 | bool AllowObjCWritebackConversion, |
5038 | bool AllowExplicit) { |
5039 | if (InitListExpr *FromInitList = dyn_cast<InitListExpr>(From)) |
5040 | return TryListConversion(S, FromInitList, ToType, SuppressUserConversions, |
5041 | InOverloadResolution,AllowObjCWritebackConversion); |
5042 | |
5043 | if (ToType->isReferenceType()) |
5044 | return TryReferenceInit(S, From, ToType, |
5045 | From->getBeginLoc(), |
5046 | SuppressUserConversions, AllowExplicit); |
5047 | |
5048 | return TryImplicitConversion(S, From, ToType, |
5049 | SuppressUserConversions, |
5050 | , |
5051 | InOverloadResolution, |
5052 | , |
5053 | AllowObjCWritebackConversion, |
5054 | ); |
5055 | } |
5056 | |
5057 | static bool TryCopyInitialization(const CanQualType FromQTy, |
5058 | const CanQualType ToQTy, |
5059 | Sema &S, |
5060 | SourceLocation Loc, |
5061 | ExprValueKind FromVK) { |
5062 | OpaqueValueExpr TmpExpr(Loc, FromQTy, FromVK); |
5063 | ImplicitConversionSequence ICS = |
5064 | TryCopyInitialization(S, &TmpExpr, ToQTy, true, true, false); |
5065 | |
5066 | return !ICS.isBad(); |
5067 | } |
5068 | |
5069 | |
5070 | |
5071 | |
5072 | static ImplicitConversionSequence |
5073 | TryObjectArgumentInitialization(Sema &S, SourceLocation Loc, QualType FromType, |
5074 | Expr::Classification FromClassification, |
5075 | CXXMethodDecl *Method, |
5076 | CXXRecordDecl *ActingContext) { |
5077 | QualType ClassType = S.Context.getTypeDeclType(ActingContext); |
5078 | |
5079 | |
5080 | Qualifiers Quals; |
5081 | if (isa<CXXDestructorDecl>(Method)) { |
5082 | Quals.addConst(); |
5083 | Quals.addVolatile(); |
5084 | } else { |
5085 | Quals = Method->getMethodQualifiers(); |
5086 | } |
5087 | |
5088 | QualType ImplicitParamType = S.Context.getQualifiedType(ClassType, Quals); |
5089 | |
5090 | |
5091 | |
5092 | ImplicitConversionSequence ICS; |
5093 | |
5094 | |
5095 | if (const PointerType *PT = FromType->getAs<PointerType>()) { |
5096 | FromType = PT->getPointeeType(); |
5097 | |
5098 | |
5099 | |
5100 | assert(FromClassification.isLValue()); |
5101 | } |
5102 | |
5103 | isRecordType()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 5103, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(FromType->isRecordType()); |
5104 | |
5105 | |
5106 | |
5107 | |
5108 | |
5109 | |
5110 | |
5111 | |
5112 | |
5113 | |
5114 | |
5115 | |
5116 | |
5117 | |
5118 | |
5119 | |
5120 | |
5121 | |
5122 | |
5123 | |
5124 | QualType FromTypeCanon = S.Context.getCanonicalType(FromType); |
5125 | if (ImplicitParamType.getCVRQualifiers() |
5126 | != FromTypeCanon.getLocalCVRQualifiers() && |
5127 | !ImplicitParamType.isAtLeastAsQualifiedAs(FromTypeCanon)) { |
5128 | ICS.setBad(BadConversionSequence::bad_qualifiers, |
5129 | FromType, ImplicitParamType); |
5130 | return ICS; |
5131 | } |
5132 | |
5133 | if (FromTypeCanon.getQualifiers().hasAddressSpace()) { |
5134 | Qualifiers QualsImplicitParamType = ImplicitParamType.getQualifiers(); |
5135 | Qualifiers QualsFromType = FromTypeCanon.getQualifiers(); |
5136 | if (!QualsImplicitParamType.isAddressSpaceSupersetOf(QualsFromType)) { |
5137 | ICS.setBad(BadConversionSequence::bad_qualifiers, |
5138 | FromType, ImplicitParamType); |
5139 | return ICS; |
5140 | } |
5141 | } |
5142 | |
5143 | |
5144 | |
5145 | QualType ClassTypeCanon = S.Context.getCanonicalType(ClassType); |
5146 | ImplicitConversionKind SecondKind; |
5147 | if (ClassTypeCanon == FromTypeCanon.getLocalUnqualifiedType()) { |
5148 | SecondKind = ICK_Identity; |
5149 | } else if (S.IsDerivedFrom(Loc, FromType, ClassType)) |
5150 | SecondKind = ICK_Derived_To_Base; |
5151 | else { |
5152 | ICS.setBad(BadConversionSequence::unrelated_class, |
5153 | FromType, ImplicitParamType); |
5154 | return ICS; |
5155 | } |
5156 | |
5157 | |
5158 | switch (Method->getRefQualifier()) { |
5159 | case RQ_None: |
5160 | |
5161 | break; |
5162 | |
5163 | case RQ_LValue: |
5164 | if (!FromClassification.isLValue() && !Quals.hasOnlyConst()) { |
5165 | |
5166 | ICS.setBad(BadConversionSequence::lvalue_ref_to_rvalue, FromType, |
5167 | ImplicitParamType); |
5168 | return ICS; |
5169 | } |
5170 | break; |
5171 | |
5172 | case RQ_RValue: |
5173 | if (!FromClassification.isRValue()) { |
5174 | |
5175 | ICS.setBad(BadConversionSequence::rvalue_ref_to_lvalue, FromType, |
5176 | ImplicitParamType); |
5177 | return ICS; |
5178 | } |
5179 | break; |
5180 | } |
5181 | |
5182 | |
5183 | ICS.setStandard(); |
5184 | ICS.Standard.setAsIdentityConversion(); |
5185 | ICS.Standard.Second = SecondKind; |
5186 | ICS.Standard.setFromType(FromType); |
5187 | ICS.Standard.setAllToTypes(ImplicitParamType); |
5188 | ICS.Standard.ReferenceBinding = true; |
5189 | ICS.Standard.DirectBinding = true; |
5190 | ICS.Standard.IsLvalueReference = Method->getRefQualifier() != RQ_RValue; |
5191 | ICS.Standard.BindsToFunctionLvalue = false; |
5192 | ICS.Standard.BindsToRvalue = FromClassification.isRValue(); |
5193 | ICS.Standard.BindsImplicitObjectArgumentWithoutRefQualifier |
5194 | = (Method->getRefQualifier() == RQ_None); |
5195 | return ICS; |
5196 | } |
5197 | |
5198 | |
5199 | |
5200 | |
5201 | ExprResult |
5202 | Sema::PerformObjectArgumentInitialization(Expr *From, |
5203 | NestedNameSpecifier *Qualifier, |
5204 | NamedDecl *FoundDecl, |
5205 | CXXMethodDecl *Method) { |
5206 | QualType FromRecordType, DestType; |
5207 | QualType ImplicitParamRecordType = |
5208 | Method->getThisType()->getAs<PointerType>()->getPointeeType(); |
5209 | |
5210 | Expr::Classification FromClassification; |
5211 | if (const PointerType *PT = From->getType()->getAs<PointerType>()) { |
5212 | FromRecordType = PT->getPointeeType(); |
5213 | DestType = Method->getThisType(); |
5214 | FromClassification = Expr::Classification::makeSimpleLValue(); |
5215 | } else { |
5216 | FromRecordType = From->getType(); |
5217 | DestType = ImplicitParamRecordType; |
5218 | FromClassification = From->Classify(Context); |
5219 | |
5220 | |
5221 | if (From->isRValue()) { |
5222 | From = CreateMaterializeTemporaryExpr(FromRecordType, From, |
5223 | Method->getRefQualifier() != |
5224 | RefQualifierKind::RQ_RValue); |
5225 | } |
5226 | } |
5227 | |
5228 | |
5229 | |
5230 | ImplicitConversionSequence ICS = TryObjectArgumentInitialization( |
5231 | *this, From->getBeginLoc(), From->getType(), FromClassification, Method, |
5232 | Method->getParent()); |
5233 | if (ICS.isBad()) { |
5234 | switch (ICS.Bad.Kind) { |
5235 | case BadConversionSequence::bad_qualifiers: { |
5236 | Qualifiers FromQs = FromRecordType.getQualifiers(); |
5237 | Qualifiers ToQs = DestType.getQualifiers(); |
5238 | unsigned CVR = FromQs.getCVRQualifiers() & ~ToQs.getCVRQualifiers(); |
5239 | if (CVR) { |
5240 | Diag(From->getBeginLoc(), diag::err_member_function_call_bad_cvr) |
5241 | << Method->getDeclName() << FromRecordType << (CVR - 1) |
5242 | << From->getSourceRange(); |
5243 | Diag(Method->getLocation(), diag::note_previous_decl) |
5244 | << Method->getDeclName(); |
5245 | return ExprError(); |
5246 | } |
5247 | break; |
5248 | } |
5249 | |
5250 | case BadConversionSequence::lvalue_ref_to_rvalue: |
5251 | case BadConversionSequence::rvalue_ref_to_lvalue: { |
5252 | bool IsRValueQualified = |
5253 | Method->getRefQualifier() == RefQualifierKind::RQ_RValue; |
5254 | Diag(From->getBeginLoc(), diag::err_member_function_call_bad_ref) |
5255 | << Method->getDeclName() << FromClassification.isRValue() |
5256 | << IsRValueQualified; |
5257 | Diag(Method->getLocation(), diag::note_previous_decl) |
5258 | << Method->getDeclName(); |
5259 | return ExprError(); |
5260 | } |
5261 | |
5262 | case BadConversionSequence::no_conversion: |
5263 | case BadConversionSequence::unrelated_class: |
5264 | break; |
5265 | } |
5266 | |
5267 | return Diag(From->getBeginLoc(), diag::err_member_function_call_bad_type) |
5268 | << ImplicitParamRecordType << FromRecordType |
5269 | << From->getSourceRange(); |
5270 | } |
5271 | |
5272 | if (ICS.Standard.Second == ICK_Derived_To_Base) { |
5273 | ExprResult FromRes = |
5274 | PerformObjectMemberConversion(From, Qualifier, FoundDecl, Method); |
5275 | if (FromRes.isInvalid()) |
5276 | return ExprError(); |
5277 | From = FromRes.get(); |
5278 | } |
5279 | |
5280 | if (!Context.hasSameType(From->getType(), DestType)) { |
5281 | if (From->getType().getAddressSpace() != DestType.getAddressSpace()) |
5282 | From = ImpCastExprToType(From, DestType, CK_AddressSpaceConversion, |
5283 | From->getValueKind()).get(); |
5284 | else |
5285 | From = ImpCastExprToType(From, DestType, CK_NoOp, |
5286 | From->getValueKind()).get(); |
5287 | } |
5288 | return From; |
5289 | } |
5290 | |
5291 | |
5292 | |
5293 | static ImplicitConversionSequence |
5294 | TryContextuallyConvertToBool(Sema &S, Expr *From) { |
5295 | return TryImplicitConversion(S, From, S.Context.BoolTy, |
5296 | , |
5297 | , |
5298 | , |
5299 | , |
5300 | , |
5301 | ); |
5302 | } |
5303 | |
5304 | |
5305 | |
5306 | ExprResult Sema::PerformContextuallyConvertToBool(Expr *From) { |
5307 | if (checkPlaceholderForOverload(*this, From)) |
5308 | return ExprError(); |
5309 | |
5310 | ImplicitConversionSequence ICS = TryContextuallyConvertToBool(*this, From); |
5311 | if (!ICS.isBad()) |
5312 | return PerformImplicitConversion(From, Context.BoolTy, ICS, AA_Converting); |
5313 | |
5314 | if (!DiagnoseMultipleUserDefinedConversion(From, Context.BoolTy)) |
5315 | return Diag(From->getBeginLoc(), diag::err_typecheck_bool_condition) |
5316 | << From->getType() << From->getSourceRange(); |
5317 | return ExprError(); |
5318 | } |
5319 | |
5320 | |
5321 | |
5322 | |
5323 | static bool CheckConvertedConstantConversions(Sema &S, |
5324 | StandardConversionSequence &SCS) { |
5325 | |
5326 | |
5327 | |
5328 | switch (SCS.Second) { |
5329 | case ICK_Identity: |
5330 | case ICK_Function_Conversion: |
5331 | case ICK_Integral_Promotion: |
5332 | case ICK_Integral_Conversion: |
5333 | case ICK_Zero_Queue_Conversion: |
5334 | return true; |
5335 | |
5336 | case ICK_Boolean_Conversion: |
5337 | |
5338 | |
5339 | |
5340 | |
5341 | |
5342 | |
5343 | |
5344 | return SCS.getFromType()->isIntegralOrUnscopedEnumerationType() && |
5345 | SCS.getToType(2)->isBooleanType(); |
5346 | |
5347 | case ICK_Pointer_Conversion: |
5348 | case ICK_Pointer_Member: |
5349 | |
5350 | |
5351 | return SCS.getFromType()->isNullPtrType(); |
5352 | |
5353 | case ICK_Floating_Promotion: |
5354 | case ICK_Complex_Promotion: |
5355 | case ICK_Floating_Conversion: |
5356 | case ICK_Complex_Conversion: |
5357 | case ICK_Floating_Integral: |
5358 | case ICK_Compatible_Conversion: |
5359 | case ICK_Derived_To_Base: |
5360 | case ICK_Vector_Conversion: |
5361 | case ICK_Vector_Splat: |
5362 | case ICK_Complex_Real: |
5363 | case ICK_Block_Pointer_Conversion: |
5364 | case ICK_TransparentUnionConversion: |
5365 | case ICK_Writeback_Conversion: |
5366 | case ICK_Zero_Event_Conversion: |
5367 | case ICK_C_Only_Conversion: |
5368 | case ICK_Incompatible_Pointer_Conversion: |
5369 | return false; |
5370 | |
5371 | case ICK_Lvalue_To_Rvalue: |
5372 | case ICK_Array_To_Pointer: |
5373 | case ICK_Function_To_Pointer: |
5374 | llvm_unreachable("found a first conversion kind in Second"); |
5375 | |
5376 | case ICK_Qualification: |
5377 | llvm_unreachable("found a third conversion kind in Second"); |
5378 | |
5379 | case ICK_Num_Conversion_Kinds: |
5380 | break; |
5381 | } |
5382 | |
5383 | llvm_unreachable("unknown conversion kind"); |
5384 | } |
5385 | |
5386 | |
5387 | |
5388 | |
5389 | static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From, |
5390 | QualType T, APValue &Value, |
5391 | Sema::CCEKind CCE, |
5392 | bool RequireInt) { |
5393 | (0) . __assert_fail ("S.getLangOpts().CPlusPlus11 && \"converted constant expression outside C++11\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 5394, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(S.getLangOpts().CPlusPlus11 && |
5394 | (0) . __assert_fail ("S.getLangOpts().CPlusPlus11 && \"converted constant expression outside C++11\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 5394, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "converted constant expression outside C++11"); |
5395 | |
5396 | if (checkPlaceholderForOverload(S, From)) |
5397 | return ExprError(); |
5398 | |
5399 | |
5400 | |
5401 | |
5402 | |
5403 | |
5404 | |
5405 | |
5406 | |
5407 | |
5408 | ImplicitConversionSequence ICS = |
5409 | CCE == Sema::CCEK_ConstexprIf |
5410 | ? TryContextuallyConvertToBool(S, From) |
5411 | : TryCopyInitialization(S, From, T, |
5412 | , |
5413 | , |
5414 | , |
5415 | ); |
5416 | StandardConversionSequence *SCS = nullptr; |
5417 | switch (ICS.getKind()) { |
5418 | case ImplicitConversionSequence::StandardConversion: |
5419 | SCS = &ICS.Standard; |
5420 | break; |
5421 | case ImplicitConversionSequence::UserDefinedConversion: |
5422 | |
5423 | |
5424 | SCS = &ICS.UserDefined.After; |
5425 | break; |
5426 | case ImplicitConversionSequence::AmbiguousConversion: |
5427 | case ImplicitConversionSequence::BadConversion: |
5428 | if (!S.DiagnoseMultipleUserDefinedConversion(From, T)) |
5429 | return S.Diag(From->getBeginLoc(), |
5430 | diag::err_typecheck_converted_constant_expression) |
5431 | << From->getType() << From->getSourceRange() << T; |
5432 | return ExprError(); |
5433 | |
5434 | case ImplicitConversionSequence::EllipsisConversion: |
5435 | llvm_unreachable("ellipsis conversion in converted constant expression"); |
5436 | } |
5437 | |
5438 | |
5439 | if (!CheckConvertedConstantConversions(S, *SCS)) { |
5440 | return S.Diag(From->getBeginLoc(), |
5441 | diag::err_typecheck_converted_constant_expression_disallowed) |
5442 | << From->getType() << From->getSourceRange() << T; |
5443 | } |
5444 | |
5445 | if (SCS->ReferenceBinding && !SCS->DirectBinding) { |
5446 | return S.Diag(From->getBeginLoc(), |
5447 | diag::err_typecheck_converted_constant_expression_indirect) |
5448 | << From->getType() << From->getSourceRange() << T; |
5449 | } |
5450 | |
5451 | ExprResult Result = |
5452 | S.PerformImplicitConversion(From, T, ICS, Sema::AA_Converting); |
5453 | if (Result.isInvalid()) |
5454 | return Result; |
5455 | |
5456 | |
5457 | APValue PreNarrowingValue; |
5458 | QualType PreNarrowingType; |
5459 | switch (SCS->getNarrowingKind(S.Context, Result.get(), PreNarrowingValue, |
5460 | PreNarrowingType)) { |
5461 | case NK_Dependent_Narrowing: |
5462 | |
5463 | |
5464 | case NK_Variable_Narrowing: |
5465 | |
5466 | |
5467 | case NK_Not_Narrowing: |
5468 | break; |
5469 | |
5470 | case NK_Constant_Narrowing: |
5471 | S.Diag(From->getBeginLoc(), diag::ext_cce_narrowing) |
5472 | << CCE << 1 |
5473 | << PreNarrowingValue.getAsString(S.Context, PreNarrowingType) << T; |
5474 | break; |
5475 | |
5476 | case NK_Type_Narrowing: |
5477 | S.Diag(From->getBeginLoc(), diag::ext_cce_narrowing) |
5478 | << CCE << 0 << From->getType() << T; |
5479 | break; |
5480 | } |
5481 | |
5482 | if (Result.get()->isValueDependent()) { |
5483 | Value = APValue(); |
5484 | return Result; |
5485 | } |
5486 | |
5487 | |
5488 | SmallVector<PartialDiagnosticAt, 8> Notes; |
5489 | Expr::EvalResult Eval; |
5490 | Eval.Diag = &Notes; |
5491 | Expr::ConstExprUsage Usage = CCE == Sema::CCEK_TemplateArg |
5492 | ? Expr::EvaluateForMangling |
5493 | : Expr::EvaluateForCodeGen; |
5494 | |
5495 | if (!Result.get()->EvaluateAsConstantExpr(Eval, Usage, S.Context) || |
5496 | (RequireInt && !Eval.Val.isInt())) { |
5497 | |
5498 | |
5499 | Result = ExprError(); |
5500 | } else { |
5501 | Value = Eval.Val; |
5502 | |
5503 | if (Notes.empty()) { |
5504 | |
5505 | return ConstantExpr::Create(S.Context, Result.get()); |
5506 | } |
5507 | } |
5508 | |
5509 | |
5510 | if (Notes.size() == 1 && |
5511 | Notes[0].second.getDiagID() == diag::note_invalid_subexpr_in_const_expr) |
5512 | S.Diag(Notes[0].first, diag::err_expr_not_cce) << CCE; |
5513 | else { |
5514 | S.Diag(From->getBeginLoc(), diag::err_expr_not_cce) |
5515 | << CCE << From->getSourceRange(); |
5516 | for (unsigned I = 0; I < Notes.size(); ++I) |
5517 | S.Diag(Notes[I].first, Notes[I].second); |
5518 | } |
5519 | return ExprError(); |
5520 | } |
5521 | |
5522 | ExprResult Sema::CheckConvertedConstantExpression(Expr *From, QualType T, |
5523 | APValue &Value, CCEKind CCE) { |
5524 | return ::CheckConvertedConstantExpression(*this, From, T, Value, CCE, false); |
5525 | } |
5526 | |
5527 | ExprResult Sema::CheckConvertedConstantExpression(Expr *From, QualType T, |
5528 | llvm::APSInt &Value, |
5529 | CCEKind CCE) { |
5530 | (0) . __assert_fail ("T->isIntegralOrEnumerationType() && \"unexpected converted const type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 5530, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(T->isIntegralOrEnumerationType() && "unexpected converted const type"); |
5531 | |
5532 | APValue V; |
5533 | auto R = ::CheckConvertedConstantExpression(*this, From, T, V, CCE, true); |
5534 | if (!R.isInvalid() && !R.get()->isValueDependent()) |
5535 | Value = V.getInt(); |
5536 | return R; |
5537 | } |
5538 | |
5539 | |
5540 | |
5541 | |
5542 | |
5543 | static void dropPointerConversion(StandardConversionSequence &SCS) { |
5544 | if (SCS.Second == ICK_Pointer_Conversion) { |
5545 | SCS.Second = ICK_Identity; |
5546 | SCS.Third = ICK_Identity; |
5547 | SCS.ToTypePtrs[2] = SCS.ToTypePtrs[1] = SCS.ToTypePtrs[0]; |
5548 | } |
5549 | } |
5550 | |
5551 | |
5552 | |
5553 | static ImplicitConversionSequence |
5554 | TryContextuallyConvertToObjCPointer(Sema &S, Expr *From) { |
5555 | |
5556 | QualType Ty = S.Context.getObjCIdType(); |
5557 | ImplicitConversionSequence ICS |
5558 | = TryImplicitConversion(S, From, Ty, |
5559 | |
5560 | , |
5561 | , |
5562 | , |
5563 | , |
5564 | , |
5565 | ); |
5566 | |
5567 | |
5568 | switch (ICS.getKind()) { |
5569 | case ImplicitConversionSequence::BadConversion: |
5570 | case ImplicitConversionSequence::AmbiguousConversion: |
5571 | case ImplicitConversionSequence::EllipsisConversion: |
5572 | break; |
5573 | |
5574 | case ImplicitConversionSequence::UserDefinedConversion: |
5575 | dropPointerConversion(ICS.UserDefined.After); |
5576 | break; |
5577 | |
5578 | case ImplicitConversionSequence::StandardConversion: |
5579 | dropPointerConversion(ICS.Standard); |
5580 | break; |
5581 | } |
5582 | |
5583 | return ICS; |
5584 | } |
5585 | |
5586 | |
5587 | |
5588 | |
5589 | ExprResult Sema::PerformContextuallyConvertToObjCPointer(Expr *From) { |
5590 | if (checkPlaceholderForOverload(*this, From)) |
5591 | return ExprError(); |
5592 | |
5593 | QualType Ty = Context.getObjCIdType(); |
5594 | ImplicitConversionSequence ICS = |
5595 | TryContextuallyConvertToObjCPointer(*this, From); |
5596 | if (!ICS.isBad()) |
5597 | return PerformImplicitConversion(From, Ty, ICS, AA_Converting); |
5598 | return ExprResult(); |
5599 | } |
5600 | |
5601 | |
5602 | |
5603 | bool Sema::ICEConvertDiagnoser::match(QualType T) { |
5604 | return AllowScopedEnumerations ? T->isIntegralOrEnumerationType() |
5605 | : T->isIntegralOrUnscopedEnumerationType(); |
5606 | } |
5607 | |
5608 | static ExprResult |
5609 | diagnoseAmbiguousConversion(Sema &SemaRef, SourceLocation Loc, Expr *From, |
5610 | Sema::ContextualImplicitConverter &Converter, |
5611 | QualType T, UnresolvedSetImpl &ViableConversions) { |
5612 | |
5613 | if (Converter.Suppress) |
5614 | return ExprError(); |
5615 | |
5616 | Converter.diagnoseAmbiguous(SemaRef, Loc, T) << From->getSourceRange(); |
5617 | for (unsigned I = 0, N = ViableConversions.size(); I != N; ++I) { |
5618 | CXXConversionDecl *Conv = |
5619 | cast<CXXConversionDecl>(ViableConversions[I]->getUnderlyingDecl()); |
5620 | QualType ConvTy = Conv->getConversionType().getNonReferenceType(); |
5621 | Converter.noteAmbiguous(SemaRef, Conv, ConvTy); |
5622 | } |
5623 | return From; |
5624 | } |
5625 | |
5626 | static bool |
5627 | diagnoseNoViableConversion(Sema &SemaRef, SourceLocation Loc, Expr *&From, |
5628 | Sema::ContextualImplicitConverter &Converter, |
5629 | QualType T, bool HadMultipleCandidates, |
5630 | UnresolvedSetImpl &ExplicitConversions) { |
5631 | if (ExplicitConversions.size() == 1 && !Converter.Suppress) { |
5632 | DeclAccessPair Found = ExplicitConversions[0]; |
5633 | CXXConversionDecl *Conversion = |
5634 | cast<CXXConversionDecl>(Found->getUnderlyingDecl()); |
5635 | |
5636 | |
5637 | |
5638 | QualType ConvTy = Conversion->getConversionType().getNonReferenceType(); |
5639 | std::string TypeStr; |
5640 | ConvTy.getAsStringInternal(TypeStr, SemaRef.getPrintingPolicy()); |
5641 | |
5642 | Converter.diagnoseExplicitConv(SemaRef, Loc, T, ConvTy) |
5643 | << FixItHint::CreateInsertion(From->getBeginLoc(), |
5644 | "static_cast<" + TypeStr + ">(") |
5645 | << FixItHint::CreateInsertion( |
5646 | SemaRef.getLocForEndOfToken(From->getEndLoc()), ")"); |
5647 | Converter.noteExplicitConv(SemaRef, Conversion, ConvTy); |
5648 | |
5649 | |
5650 | |
5651 | if (SemaRef.isSFINAEContext()) |
5652 | return true; |
5653 | |
5654 | SemaRef.CheckMemberOperatorAccess(From->getExprLoc(), From, nullptr, Found); |
5655 | ExprResult Result = SemaRef.BuildCXXMemberCallExpr(From, Found, Conversion, |
5656 | HadMultipleCandidates); |
5657 | if (Result.isInvalid()) |
5658 | return true; |
5659 | |
5660 | From = ImplicitCastExpr::Create(SemaRef.Context, Result.get()->getType(), |
5661 | CK_UserDefinedConversion, Result.get(), |
5662 | nullptr, Result.get()->getValueKind()); |
5663 | } |
5664 | return false; |
5665 | } |
5666 | |
5667 | static bool recordConversion(Sema &SemaRef, SourceLocation Loc, Expr *&From, |
5668 | Sema::ContextualImplicitConverter &Converter, |
5669 | QualType T, bool HadMultipleCandidates, |
5670 | DeclAccessPair &Found) { |
5671 | CXXConversionDecl *Conversion = |
5672 | cast<CXXConversionDecl>(Found->getUnderlyingDecl()); |
5673 | SemaRef.CheckMemberOperatorAccess(From->getExprLoc(), From, nullptr, Found); |
5674 | |
5675 | QualType ToType = Conversion->getConversionType().getNonReferenceType(); |
5676 | if (!Converter.SuppressConversion) { |
5677 | if (SemaRef.isSFINAEContext()) |
5678 | return true; |
5679 | |
5680 | Converter.diagnoseConversion(SemaRef, Loc, T, ToType) |
5681 | << From->getSourceRange(); |
5682 | } |
5683 | |
5684 | ExprResult Result = SemaRef.BuildCXXMemberCallExpr(From, Found, Conversion, |
5685 | HadMultipleCandidates); |
5686 | if (Result.isInvalid()) |
5687 | return true; |
5688 | |
5689 | From = ImplicitCastExpr::Create(SemaRef.Context, Result.get()->getType(), |
5690 | CK_UserDefinedConversion, Result.get(), |
5691 | nullptr, Result.get()->getValueKind()); |
5692 | return false; |
5693 | } |
5694 | |
5695 | static ExprResult finishContextualImplicitConversion( |
5696 | Sema &SemaRef, SourceLocation Loc, Expr *From, |
5697 | Sema::ContextualImplicitConverter &Converter) { |
5698 | if (!Converter.match(From->getType()) && !Converter.Suppress) |
5699 | Converter.diagnoseNoMatch(SemaRef, Loc, From->getType()) |
5700 | << From->getSourceRange(); |
5701 | |
5702 | return SemaRef.DefaultLvalueConversion(From); |
5703 | } |
5704 | |
5705 | static void |
5706 | collectViableConversionCandidates(Sema &SemaRef, Expr *From, QualType ToType, |
5707 | UnresolvedSetImpl &ViableConversions, |
5708 | OverloadCandidateSet &CandidateSet) { |
5709 | for (unsigned I = 0, N = ViableConversions.size(); I != N; ++I) { |
5710 | DeclAccessPair FoundDecl = ViableConversions[I]; |
5711 | NamedDecl *D = FoundDecl.getDecl(); |
5712 | CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(D->getDeclContext()); |
5713 | if (isa<UsingShadowDecl>(D)) |
5714 | D = cast<UsingShadowDecl>(D)->getTargetDecl(); |
5715 | |
5716 | CXXConversionDecl *Conv; |
5717 | FunctionTemplateDecl *ConvTemplate; |
5718 | if ((ConvTemplate = dyn_cast<FunctionTemplateDecl>(D))) |
5719 | Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl()); |
5720 | else |
5721 | Conv = cast<CXXConversionDecl>(D); |
5722 | |
5723 | if (ConvTemplate) |
5724 | SemaRef.AddTemplateConversionCandidate( |
5725 | ConvTemplate, FoundDecl, ActingContext, From, ToType, CandidateSet, |
5726 | ); |
5727 | else |
5728 | SemaRef.AddConversionCandidate(Conv, FoundDecl, ActingContext, From, |
5729 | ToType, CandidateSet, |
5730 | ); |
5731 | } |
5732 | } |
5733 | |
5734 | |
5735 | |
5736 | |
5737 | |
5738 | |
5739 | |
5740 | |
5741 | |
5742 | |
5743 | |
5744 | |
5745 | |
5746 | |
5747 | |
5748 | |
5749 | |
5750 | |
5751 | |
5752 | ExprResult Sema::PerformContextualImplicitConversion( |
5753 | SourceLocation Loc, Expr *From, ContextualImplicitConverter &Converter) { |
5754 | |
5755 | if (From->isTypeDependent()) |
5756 | return From; |
5757 | |
5758 | |
5759 | if (From->hasPlaceholderType()) { |
5760 | ExprResult result = CheckPlaceholderExpr(From); |
5761 | if (result.isInvalid()) |
5762 | return result; |
5763 | From = result.get(); |
5764 | } |
5765 | |
5766 | |
5767 | QualType T = From->getType(); |
5768 | if (Converter.match(T)) |
5769 | return DefaultLvalueConversion(From); |
5770 | |
5771 | |
5772 | |
5773 | |
5774 | |
5775 | const RecordType *RecordTy = T->getAs<RecordType>(); |
5776 | if (!RecordTy || !getLangOpts().CPlusPlus) { |
5777 | if (!Converter.Suppress) |
5778 | Converter.diagnoseNoMatch(*this, Loc, T) << From->getSourceRange(); |
5779 | return From; |
5780 | } |
5781 | |
5782 | |
5783 | struct TypeDiagnoserPartialDiag : TypeDiagnoser { |
5784 | ContextualImplicitConverter &Converter; |
5785 | Expr *From; |
5786 | |
5787 | TypeDiagnoserPartialDiag(ContextualImplicitConverter &Converter, Expr *From) |
5788 | : Converter(Converter), From(From) {} |
5789 | |
5790 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
5791 | Converter.diagnoseIncomplete(S, Loc, T) << From->getSourceRange(); |
5792 | } |
5793 | } IncompleteDiagnoser(Converter, From); |
5794 | |
5795 | if (Converter.Suppress ? !isCompleteType(Loc, T) |
5796 | : RequireCompleteType(Loc, T, IncompleteDiagnoser)) |
5797 | return From; |
5798 | |
5799 | |
5800 | UnresolvedSet<4> |
5801 | ViableConversions; |
5802 | UnresolvedSet<4> ExplicitConversions; |
5803 | const auto &Conversions = |
5804 | cast<CXXRecordDecl>(RecordTy->getDecl())->getVisibleConversionFunctions(); |
5805 | |
5806 | bool HadMultipleCandidates = |
5807 | (std::distance(Conversions.begin(), Conversions.end()) > 1); |
5808 | |
5809 | |
5810 | QualType ToType; |
5811 | bool HasUniqueTargetType = true; |
5812 | |
5813 | |
5814 | for (auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) { |
5815 | NamedDecl *D = (*I)->getUnderlyingDecl(); |
5816 | CXXConversionDecl *Conversion; |
5817 | FunctionTemplateDecl *ConvTemplate = dyn_cast<FunctionTemplateDecl>(D); |
5818 | if (ConvTemplate) { |
5819 | if (getLangOpts().CPlusPlus14) |
5820 | Conversion = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl()); |
5821 | else |
5822 | continue; |
5823 | } else |
5824 | Conversion = cast<CXXConversionDecl>(D); |
5825 | |
5826 | (0) . __assert_fail ("(!ConvTemplate || getLangOpts().CPlusPlus14) && \"Conversion operator templates are considered potentially \" \"viable in C++1y\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 5828, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((!ConvTemplate || getLangOpts().CPlusPlus14) && |
5827 | (0) . __assert_fail ("(!ConvTemplate || getLangOpts().CPlusPlus14) && \"Conversion operator templates are considered potentially \" \"viable in C++1y\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 5828, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Conversion operator templates are considered potentially " |
5828 | (0) . __assert_fail ("(!ConvTemplate || getLangOpts().CPlusPlus14) && \"Conversion operator templates are considered potentially \" \"viable in C++1y\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 5828, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "viable in C++1y"); |
5829 | |
5830 | QualType CurToType = Conversion->getConversionType().getNonReferenceType(); |
5831 | if (Converter.match(CurToType) || ConvTemplate) { |
5832 | |
5833 | if (Conversion->isExplicit()) { |
5834 | |
5835 | |
5836 | if (!ConvTemplate) |
5837 | ExplicitConversions.addDecl(I.getDecl(), I.getAccess()); |
5838 | } else { |
5839 | if (!ConvTemplate && getLangOpts().CPlusPlus14) { |
5840 | if (ToType.isNull()) |
5841 | ToType = CurToType.getUnqualifiedType(); |
5842 | else if (HasUniqueTargetType && |
5843 | (CurToType.getUnqualifiedType() != ToType)) |
5844 | HasUniqueTargetType = false; |
5845 | } |
5846 | ViableConversions.addDecl(I.getDecl(), I.getAccess()); |
5847 | } |
5848 | } |
5849 | } |
5850 | |
5851 | if (getLangOpts().CPlusPlus14) { |
5852 | |
5853 | |
5854 | |
5855 | |
5856 | |
5857 | |
5858 | |
5859 | |
5860 | |
5861 | |
5862 | if (ToType.isNull()) { |
5863 | if (diagnoseNoViableConversion(*this, Loc, From, Converter, T, |
5864 | HadMultipleCandidates, |
5865 | ExplicitConversions)) |
5866 | return ExprError(); |
5867 | return finishContextualImplicitConversion(*this, Loc, From, Converter); |
5868 | } |
5869 | |
5870 | |
5871 | if (!HasUniqueTargetType) |
5872 | return diagnoseAmbiguousConversion(*this, Loc, From, Converter, T, |
5873 | ViableConversions); |
5874 | |
5875 | |
5876 | |
5877 | |
5878 | OverloadCandidateSet CandidateSet(Loc, OverloadCandidateSet::CSK_Normal); |
5879 | collectViableConversionCandidates(*this, From, ToType, ViableConversions, |
5880 | CandidateSet); |
5881 | |
5882 | |
5883 | OverloadCandidateSet::iterator Best; |
5884 | switch (CandidateSet.BestViableFunction(*this, Loc, Best)) { |
5885 | case OR_Success: { |
5886 | |
5887 | DeclAccessPair Found = |
5888 | DeclAccessPair::make(Best->Function, Best->FoundDecl.getAccess()); |
5889 | if (recordConversion(*this, Loc, From, Converter, T, |
5890 | HadMultipleCandidates, Found)) |
5891 | return ExprError(); |
5892 | break; |
5893 | } |
5894 | case OR_Ambiguous: |
5895 | return diagnoseAmbiguousConversion(*this, Loc, From, Converter, T, |
5896 | ViableConversions); |
5897 | case OR_No_Viable_Function: |
5898 | if (diagnoseNoViableConversion(*this, Loc, From, Converter, T, |
5899 | HadMultipleCandidates, |
5900 | ExplicitConversions)) |
5901 | return ExprError(); |
5902 | LLVM_FALLTHROUGH; |
5903 | case OR_Deleted: |
5904 | |
5905 | break; |
5906 | } |
5907 | } else { |
5908 | switch (ViableConversions.size()) { |
5909 | case 0: { |
5910 | if (diagnoseNoViableConversion(*this, Loc, From, Converter, T, |
5911 | HadMultipleCandidates, |
5912 | ExplicitConversions)) |
5913 | return ExprError(); |
5914 | |
5915 | |
5916 | break; |
5917 | } |
5918 | case 1: { |
5919 | |
5920 | DeclAccessPair Found = ViableConversions[0]; |
5921 | if (recordConversion(*this, Loc, From, Converter, T, |
5922 | HadMultipleCandidates, Found)) |
5923 | return ExprError(); |
5924 | break; |
5925 | } |
5926 | default: |
5927 | return diagnoseAmbiguousConversion(*this, Loc, From, Converter, T, |
5928 | ViableConversions); |
5929 | } |
5930 | } |
5931 | |
5932 | return finishContextualImplicitConversion(*this, Loc, From, Converter); |
5933 | } |
5934 | |
5935 | |
5936 | |
5937 | |
5938 | |
5939 | |
5940 | static bool IsAcceptableNonMemberOperatorCandidate(ASTContext &Context, |
5941 | FunctionDecl *Fn, |
5942 | ArrayRef<Expr *> Args) { |
5943 | QualType T1 = Args[0]->getType(); |
5944 | QualType T2 = Args.size() > 1 ? Args[1]->getType() : QualType(); |
5945 | |
5946 | if (T1->isDependentType() || (!T2.isNull() && T2->isDependentType())) |
5947 | return true; |
5948 | |
5949 | if (T1->isRecordType() || (!T2.isNull() && T2->isRecordType())) |
5950 | return true; |
5951 | |
5952 | const FunctionProtoType *Proto = Fn->getType()->getAs<FunctionProtoType>(); |
5953 | if (Proto->getNumParams() < 1) |
5954 | return false; |
5955 | |
5956 | if (T1->isEnumeralType()) { |
5957 | QualType ArgType = Proto->getParamType(0).getNonReferenceType(); |
5958 | if (Context.hasSameUnqualifiedType(T1, ArgType)) |
5959 | return true; |
5960 | } |
5961 | |
5962 | if (Proto->getNumParams() < 2) |
5963 | return false; |
5964 | |
5965 | if (!T2.isNull() && T2->isEnumeralType()) { |
5966 | QualType ArgType = Proto->getParamType(1).getNonReferenceType(); |
5967 | if (Context.hasSameUnqualifiedType(T2, ArgType)) |
5968 | return true; |
5969 | } |
5970 | |
5971 | return false; |
5972 | } |
5973 | |
5974 | |
5975 | |
5976 | |
5977 | |
5978 | |
5979 | |
5980 | |
5981 | |
5982 | void Sema::AddOverloadCandidate(FunctionDecl *Function, |
5983 | DeclAccessPair FoundDecl, ArrayRef<Expr *> Args, |
5984 | OverloadCandidateSet &CandidateSet, |
5985 | bool SuppressUserConversions, |
5986 | bool PartialOverloading, bool AllowExplicit, |
5987 | ADLCallKind IsADLCandidate, |
5988 | ConversionSequenceList EarlyConversions) { |
5989 | const FunctionProtoType *Proto |
5990 | = dyn_cast<FunctionProtoType>(Function->getType()->getAs<FunctionType>()); |
5991 | (0) . __assert_fail ("Proto && \"Functions without a prototype cannot be overloaded\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 5991, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Proto && "Functions without a prototype cannot be overloaded"); |
5992 | (0) . __assert_fail ("!Function->getDescribedFunctionTemplate() && \"Use AddTemplateOverloadCandidate for function templates\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 5993, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Function->getDescribedFunctionTemplate() && |
5993 | (0) . __assert_fail ("!Function->getDescribedFunctionTemplate() && \"Use AddTemplateOverloadCandidate for function templates\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 5993, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Use AddTemplateOverloadCandidate for function templates"); |
5994 | |
5995 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Function)) { |
5996 | if (!isa<CXXConstructorDecl>(Method)) { |
5997 | |
5998 | |
5999 | |
6000 | |
6001 | |
6002 | |
6003 | |
6004 | AddMethodCandidate(Method, FoundDecl, Method->getParent(), QualType(), |
6005 | Expr::Classification::makeSimpleLValue(), Args, |
6006 | CandidateSet, SuppressUserConversions, |
6007 | PartialOverloading, EarlyConversions); |
6008 | return; |
6009 | } |
6010 | |
6011 | |
6012 | } |
6013 | |
6014 | if (!CandidateSet.isNewCandidate(Function)) |
6015 | return; |
6016 | |
6017 | |
6018 | |
6019 | |
6020 | |
6021 | |
6022 | |
6023 | |
6024 | if (CandidateSet.getKind() == OverloadCandidateSet::CSK_Operator && |
6025 | !IsAcceptableNonMemberOperatorCandidate(Context, Function, Args)) |
6026 | return; |
6027 | |
6028 | |
6029 | |
6030 | |
6031 | CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(Function); |
6032 | if (Constructor && Constructor->isDefaulted() && Constructor->isDeleted() && |
6033 | Constructor->isMoveConstructor()) |
6034 | return; |
6035 | |
6036 | |
6037 | EnterExpressionEvaluationContext Unevaluated( |
6038 | *this, Sema::ExpressionEvaluationContext::Unevaluated); |
6039 | |
6040 | |
6041 | OverloadCandidate &Candidate = |
6042 | CandidateSet.addCandidate(Args.size(), EarlyConversions); |
6043 | Candidate.FoundDecl = FoundDecl; |
6044 | Candidate.Function = Function; |
6045 | Candidate.Viable = true; |
6046 | Candidate.IsSurrogate = false; |
6047 | Candidate.IsADLCandidate = IsADLCandidate; |
6048 | Candidate.IgnoreObjectArgument = false; |
6049 | Candidate.ExplicitCallArguments = Args.size(); |
6050 | |
6051 | if (Function->isMultiVersion() && Function->hasAttr<TargetAttr>() && |
6052 | !Function->getAttr<TargetAttr>()->isDefaultVersion()) { |
6053 | Candidate.Viable = false; |
6054 | Candidate.FailureKind = ovl_non_default_multiversion_function; |
6055 | return; |
6056 | } |
6057 | |
6058 | if (Constructor) { |
6059 | |
6060 | |
6061 | |
6062 | QualType ClassType = Context.getTypeDeclType(Constructor->getParent()); |
6063 | if (Args.size() == 1 && Constructor->isSpecializationCopyingObject() && |
6064 | (Context.hasSameUnqualifiedType(ClassType, Args[0]->getType()) || |
6065 | IsDerivedFrom(Args[0]->getBeginLoc(), Args[0]->getType(), |
6066 | ClassType))) { |
6067 | Candidate.Viable = false; |
6068 | Candidate.FailureKind = ovl_fail_illegal_constructor; |
6069 | return; |
6070 | } |
6071 | |
6072 | |
6073 | |
6074 | |
6075 | |
6076 | |
6077 | |
6078 | |
6079 | auto *Shadow = dyn_cast<ConstructorUsingShadowDecl>(FoundDecl.getDecl()); |
6080 | if (Shadow && Args.size() == 1 && Constructor->getNumParams() >= 1 && |
6081 | Constructor->getParamDecl(0)->getType()->isReferenceType()) { |
6082 | QualType P = Constructor->getParamDecl(0)->getType()->getPointeeType(); |
6083 | QualType C = Context.getRecordType(Constructor->getParent()); |
6084 | QualType D = Context.getRecordType(Shadow->getParent()); |
6085 | SourceLocation Loc = Args.front()->getExprLoc(); |
6086 | if ((Context.hasSameUnqualifiedType(P, C) || IsDerivedFrom(Loc, P, C)) && |
6087 | (Context.hasSameUnqualifiedType(D, P) || IsDerivedFrom(Loc, D, P))) { |
6088 | Candidate.Viable = false; |
6089 | Candidate.FailureKind = ovl_fail_inhctor_slice; |
6090 | return; |
6091 | } |
6092 | } |
6093 | } |
6094 | |
6095 | unsigned NumParams = Proto->getNumParams(); |
6096 | |
6097 | |
6098 | |
6099 | |
6100 | if (TooManyArguments(NumParams, Args.size(), PartialOverloading) && |
6101 | !Proto->isVariadic()) { |
6102 | Candidate.Viable = false; |
6103 | Candidate.FailureKind = ovl_fail_too_many_arguments; |
6104 | return; |
6105 | } |
6106 | |
6107 | |
6108 | |
6109 | |
6110 | |
6111 | |
6112 | unsigned MinRequiredArgs = Function->getMinRequiredArguments(); |
6113 | if (Args.size() < MinRequiredArgs && !PartialOverloading) { |
6114 | |
6115 | Candidate.Viable = false; |
6116 | Candidate.FailureKind = ovl_fail_too_few_arguments; |
6117 | return; |
6118 | } |
6119 | |
6120 | |
6121 | if (getLangOpts().CUDA) |
6122 | if (const FunctionDecl *Caller = dyn_cast<FunctionDecl>(CurContext)) |
6123 | |
6124 | |
6125 | |
6126 | |
6127 | if (!Caller->isImplicit() && !IsAllowedCUDACall(Caller, Function)) { |
6128 | Candidate.Viable = false; |
6129 | Candidate.FailureKind = ovl_fail_bad_target; |
6130 | return; |
6131 | } |
6132 | |
6133 | |
6134 | |
6135 | for (unsigned ArgIdx = 0; ArgIdx < Args.size(); ++ArgIdx) { |
6136 | if (Candidate.Conversions[ArgIdx].isInitialized()) { |
6137 | |
6138 | |
6139 | } else if (ArgIdx < NumParams) { |
6140 | |
6141 | |
6142 | |
6143 | |
6144 | QualType ParamType = Proto->getParamType(ArgIdx); |
6145 | Candidate.Conversions[ArgIdx] |
6146 | = TryCopyInitialization(*this, Args[ArgIdx], ParamType, |
6147 | SuppressUserConversions, |
6148 | , |
6149 | |
6150 | getLangOpts().ObjCAutoRefCount, |
6151 | AllowExplicit); |
6152 | if (Candidate.Conversions[ArgIdx].isBad()) { |
6153 | Candidate.Viable = false; |
6154 | Candidate.FailureKind = ovl_fail_bad_conversion; |
6155 | return; |
6156 | } |
6157 | } else { |
6158 | |
6159 | |
6160 | |
6161 | Candidate.Conversions[ArgIdx].setEllipsis(); |
6162 | } |
6163 | } |
6164 | |
6165 | if (EnableIfAttr *FailedAttr = CheckEnableIf(Function, Args)) { |
6166 | Candidate.Viable = false; |
6167 | Candidate.FailureKind = ovl_fail_enable_if; |
6168 | Candidate.DeductionFailure.Data = FailedAttr; |
6169 | return; |
6170 | } |
6171 | |
6172 | if (LangOpts.OpenCL && isOpenCLDisabledDecl(Function)) { |
6173 | Candidate.Viable = false; |
6174 | Candidate.FailureKind = ovl_fail_ext_disabled; |
6175 | return; |
6176 | } |
6177 | } |
6178 | |
6179 | ObjCMethodDecl * |
6180 | Sema::SelectBestMethod(Selector Sel, MultiExprArg Args, bool IsInstance, |
6181 | SmallVectorImpl<ObjCMethodDecl *> &Methods) { |
6182 | if (Methods.size() <= 1) |
6183 | return nullptr; |
6184 | |
6185 | for (unsigned b = 0, e = Methods.size(); b < e; b++) { |
6186 | bool Match = true; |
6187 | ObjCMethodDecl *Method = Methods[b]; |
6188 | unsigned NumNamedArgs = Sel.getNumArgs(); |
6189 | |
6190 | |
6191 | if (Method->param_size() > NumNamedArgs) |
6192 | NumNamedArgs = Method->param_size(); |
6193 | if (Args.size() < NumNamedArgs) |
6194 | continue; |
6195 | |
6196 | for (unsigned i = 0; i < NumNamedArgs; i++) { |
6197 | |
6198 | if (Args[i]->isTypeDependent()) { |
6199 | Match = false; |
6200 | break; |
6201 | } |
6202 | |
6203 | ParmVarDecl *param = Method->parameters()[i]; |
6204 | Expr *argExpr = Args[i]; |
6205 | (0) . __assert_fail ("argExpr && \"SelectBestMethod(). missing expression\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6205, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(argExpr && "SelectBestMethod(): missing expression"); |
6206 | |
6207 | |
6208 | |
6209 | if (argExpr->hasPlaceholderType(BuiltinType::ARCUnbridgedCast) && |
6210 | !param->hasAttr<CFConsumedAttr>()) |
6211 | argExpr = stripARCUnbridgedCast(argExpr); |
6212 | |
6213 | |
6214 | if (param->getType() == Context.UnknownAnyTy) { |
6215 | Match = false; |
6216 | break; |
6217 | } |
6218 | |
6219 | ImplicitConversionSequence ConversionState |
6220 | = TryCopyInitialization(*this, argExpr, param->getType(), |
6221 | , |
6222 | , |
6223 | |
6224 | getLangOpts().ObjCAutoRefCount, |
6225 | ); |
6226 | |
6227 | |
6228 | if (ConversionState.isBad() || |
6229 | (ConversionState.isStandard() && |
6230 | ConversionState.Standard.Second == |
6231 | ICK_Incompatible_Pointer_Conversion)) { |
6232 | Match = false; |
6233 | break; |
6234 | } |
6235 | } |
6236 | |
6237 | if (Match && Method->isVariadic()) { |
6238 | for (unsigned i = NumNamedArgs, e = Args.size(); i < e; ++i) { |
6239 | if (Args[i]->isTypeDependent()) { |
6240 | Match = false; |
6241 | break; |
6242 | } |
6243 | ExprResult Arg = DefaultVariadicArgumentPromotion(Args[i], VariadicMethod, |
6244 | nullptr); |
6245 | if (Arg.isInvalid()) { |
6246 | Match = false; |
6247 | break; |
6248 | } |
6249 | } |
6250 | } else { |
6251 | |
6252 | if (Args.size() != NumNamedArgs) |
6253 | Match = false; |
6254 | else if (Match && NumNamedArgs == 0 && Methods.size() > 1) { |
6255 | |
6256 | |
6257 | for (unsigned b = 0, e = Methods.size(); b < e; b++) { |
6258 | QualType ReturnT = Methods[b]->getReturnType(); |
6259 | if (ReturnT->isObjCIdType()) |
6260 | return Methods[b]; |
6261 | } |
6262 | } |
6263 | } |
6264 | |
6265 | if (Match) |
6266 | return Method; |
6267 | } |
6268 | return nullptr; |
6269 | } |
6270 | |
6271 | static bool |
6272 | convertArgsForAvailabilityChecks(Sema &S, FunctionDecl *Function, Expr *ThisArg, |
6273 | ArrayRef<Expr *> Args, Sema::SFINAETrap &Trap, |
6274 | bool MissingImplicitThis, Expr *&ConvertedThis, |
6275 | SmallVectorImpl<Expr *> &ConvertedArgs) { |
6276 | if (ThisArg) { |
6277 | CXXMethodDecl *Method = cast<CXXMethodDecl>(Function); |
6278 | (0) . __assert_fail ("!isa(Method) && \"Shouldn't have `this` for ctors!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6279, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!isa<CXXConstructorDecl>(Method) && |
6279 | (0) . __assert_fail ("!isa(Method) && \"Shouldn't have `this` for ctors!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6279, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Shouldn't have `this` for ctors!"); |
6280 | (0) . __assert_fail ("!Method->isStatic() && \"Shouldn't have `this` for static methods!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6280, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Method->isStatic() && "Shouldn't have `this` for static methods!"); |
6281 | ExprResult R = S.PerformObjectArgumentInitialization( |
6282 | ThisArg, , Method, Method); |
6283 | if (R.isInvalid()) |
6284 | return false; |
6285 | ConvertedThis = R.get(); |
6286 | } else { |
6287 | if (auto *MD = dyn_cast<CXXMethodDecl>(Function)) { |
6288 | (void)MD; |
6289 | (0) . __assert_fail ("(MissingImplicitThis || MD->isStatic() || isa(MD)) && \"Expected `this` for non-ctor instance methods\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6291, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((MissingImplicitThis || MD->isStatic() || |
6290 | (0) . __assert_fail ("(MissingImplicitThis || MD->isStatic() || isa(MD)) && \"Expected `this` for non-ctor instance methods\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6291, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> isa<CXXConstructorDecl>(MD)) && |
6291 | (0) . __assert_fail ("(MissingImplicitThis || MD->isStatic() || isa(MD)) && \"Expected `this` for non-ctor instance methods\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6291, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Expected `this` for non-ctor instance methods"); |
6292 | } |
6293 | ConvertedThis = nullptr; |
6294 | } |
6295 | |
6296 | |
6297 | |
6298 | unsigned ArgSizeNoVarargs = std::min(Function->param_size(), Args.size()); |
6299 | |
6300 | |
6301 | for (unsigned I = 0; I != ArgSizeNoVarargs; ++I) { |
6302 | ExprResult R; |
6303 | R = S.PerformCopyInitialization(InitializedEntity::InitializeParameter( |
6304 | S.Context, Function->getParamDecl(I)), |
6305 | SourceLocation(), Args[I]); |
6306 | |
6307 | if (R.isInvalid()) |
6308 | return false; |
6309 | |
6310 | ConvertedArgs.push_back(R.get()); |
6311 | } |
6312 | |
6313 | if (Trap.hasErrorOccurred()) |
6314 | return false; |
6315 | |
6316 | |
6317 | if (!Function->isVariadic() && Args.size() < Function->getNumParams()) { |
6318 | for (unsigned i = Args.size(), e = Function->getNumParams(); i != e; ++i) { |
6319 | ParmVarDecl *P = Function->getParamDecl(i); |
6320 | Expr *DefArg = P->hasUninstantiatedDefaultArg() |
6321 | ? P->getUninstantiatedDefaultArg() |
6322 | : P->getDefaultArg(); |
6323 | |
6324 | |
6325 | if (!DefArg) |
6326 | return false; |
6327 | ExprResult R = |
6328 | S.PerformCopyInitialization(InitializedEntity::InitializeParameter( |
6329 | S.Context, Function->getParamDecl(i)), |
6330 | SourceLocation(), DefArg); |
6331 | if (R.isInvalid()) |
6332 | return false; |
6333 | ConvertedArgs.push_back(R.get()); |
6334 | } |
6335 | |
6336 | if (Trap.hasErrorOccurred()) |
6337 | return false; |
6338 | } |
6339 | return true; |
6340 | } |
6341 | |
6342 | EnableIfAttr *Sema::CheckEnableIf(FunctionDecl *Function, ArrayRef<Expr *> Args, |
6343 | bool MissingImplicitThis) { |
6344 | auto EnableIfAttrs = Function->specific_attrs<EnableIfAttr>(); |
6345 | if (EnableIfAttrs.begin() == EnableIfAttrs.end()) |
6346 | return nullptr; |
6347 | |
6348 | SFINAETrap Trap(*this); |
6349 | SmallVector<Expr *, 16> ConvertedArgs; |
6350 | |
6351 | Expr *DiscardedThis; |
6352 | if (!convertArgsForAvailabilityChecks( |
6353 | *this, Function, , Args, Trap, |
6354 | , DiscardedThis, ConvertedArgs)) |
6355 | return *EnableIfAttrs.begin(); |
6356 | |
6357 | for (auto *EIA : EnableIfAttrs) { |
6358 | APValue Result; |
6359 | |
6360 | |
6361 | if (!EIA->getCond()->EvaluateWithSubstitution( |
6362 | Result, Context, Function, llvm::makeArrayRef(ConvertedArgs))) |
6363 | return EIA; |
6364 | |
6365 | if (!Result.isInt() || !Result.getInt().getBoolValue()) |
6366 | return EIA; |
6367 | } |
6368 | return nullptr; |
6369 | } |
6370 | |
6371 | template <typename CheckFn> |
6372 | static bool diagnoseDiagnoseIfAttrsWith(Sema &S, const NamedDecl *ND, |
6373 | bool ArgDependent, SourceLocation Loc, |
6374 | CheckFn &&IsSuccessful) { |
6375 | SmallVector<const DiagnoseIfAttr *, 8> Attrs; |
6376 | for (const auto *DIA : ND->specific_attrs<DiagnoseIfAttr>()) { |
6377 | if (ArgDependent == DIA->getArgDependent()) |
6378 | Attrs.push_back(DIA); |
6379 | } |
6380 | |
6381 | |
6382 | if (Attrs.empty()) |
6383 | return false; |
6384 | |
6385 | auto WarningBegin = std::stable_partition( |
6386 | Attrs.begin(), Attrs.end(), |
6387 | [](const DiagnoseIfAttr *DIA) { return DIA->isError(); }); |
6388 | |
6389 | |
6390 | |
6391 | auto ErrAttr = llvm::find_if(llvm::make_range(Attrs.begin(), WarningBegin), |
6392 | IsSuccessful); |
6393 | if (ErrAttr != WarningBegin) { |
6394 | const DiagnoseIfAttr *DIA = *ErrAttr; |
6395 | S.Diag(Loc, diag::err_diagnose_if_succeeded) << DIA->getMessage(); |
6396 | S.Diag(DIA->getLocation(), diag::note_from_diagnose_if) |
6397 | << DIA->getParent() << DIA->getCond()->getSourceRange(); |
6398 | return true; |
6399 | } |
6400 | |
6401 | for (const auto *DIA : llvm::make_range(WarningBegin, Attrs.end())) |
6402 | if (IsSuccessful(DIA)) { |
6403 | S.Diag(Loc, diag::warn_diagnose_if_succeeded) << DIA->getMessage(); |
6404 | S.Diag(DIA->getLocation(), diag::note_from_diagnose_if) |
6405 | << DIA->getParent() << DIA->getCond()->getSourceRange(); |
6406 | } |
6407 | |
6408 | return false; |
6409 | } |
6410 | |
6411 | bool Sema::diagnoseArgDependentDiagnoseIfAttrs(const FunctionDecl *Function, |
6412 | const Expr *ThisArg, |
6413 | ArrayRef<const Expr *> Args, |
6414 | SourceLocation Loc) { |
6415 | return diagnoseDiagnoseIfAttrsWith( |
6416 | *this, Function, , Loc, |
6417 | [&](const DiagnoseIfAttr *DIA) { |
6418 | APValue Result; |
6419 | |
6420 | |
6421 | |
6422 | if (!DIA->getCond()->EvaluateWithSubstitution( |
6423 | Result, Context, cast<FunctionDecl>(DIA->getParent()), Args, ThisArg)) |
6424 | return false; |
6425 | return Result.isInt() && Result.getInt().getBoolValue(); |
6426 | }); |
6427 | } |
6428 | |
6429 | bool Sema::diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND, |
6430 | SourceLocation Loc) { |
6431 | return diagnoseDiagnoseIfAttrsWith( |
6432 | *this, ND, , Loc, |
6433 | [&](const DiagnoseIfAttr *DIA) { |
6434 | bool Result; |
6435 | return DIA->getCond()->EvaluateAsBooleanCondition(Result, Context) && |
6436 | Result; |
6437 | }); |
6438 | } |
6439 | |
6440 | |
6441 | |
6442 | void Sema::AddFunctionCandidates(const UnresolvedSetImpl &Fns, |
6443 | ArrayRef<Expr *> Args, |
6444 | OverloadCandidateSet &CandidateSet, |
6445 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
6446 | bool SuppressUserConversions, |
6447 | bool PartialOverloading, |
6448 | bool FirstArgumentIsBase) { |
6449 | for (UnresolvedSetIterator F = Fns.begin(), E = Fns.end(); F != E; ++F) { |
6450 | NamedDecl *D = F.getDecl()->getUnderlyingDecl(); |
6451 | ArrayRef<Expr *> FunctionArgs = Args; |
6452 | |
6453 | FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D); |
6454 | FunctionDecl *FD = |
6455 | FunTmpl ? FunTmpl->getTemplatedDecl() : cast<FunctionDecl>(D); |
6456 | |
6457 | if (isa<CXXMethodDecl>(FD) && !cast<CXXMethodDecl>(FD)->isStatic()) { |
6458 | QualType ObjectType; |
6459 | Expr::Classification ObjectClassification; |
6460 | if (Args.size() > 0) { |
6461 | if (Expr *E = Args[0]) { |
6462 | |
6463 | ObjectType = E->getType(); |
6464 | |
6465 | |
6466 | if (!ObjectType.isNull() && ObjectType->isPointerType()) |
6467 | ObjectClassification = Expr::Classification::makeSimpleLValue(); |
6468 | else |
6469 | ObjectClassification = E->Classify(Context); |
6470 | } |
6471 | FunctionArgs = Args.slice(1); |
6472 | } |
6473 | if (FunTmpl) { |
6474 | AddMethodTemplateCandidate( |
6475 | FunTmpl, F.getPair(), |
6476 | cast<CXXRecordDecl>(FunTmpl->getDeclContext()), |
6477 | ExplicitTemplateArgs, ObjectType, ObjectClassification, |
6478 | FunctionArgs, CandidateSet, SuppressUserConversions, |
6479 | PartialOverloading); |
6480 | } else { |
6481 | AddMethodCandidate(cast<CXXMethodDecl>(FD), F.getPair(), |
6482 | cast<CXXMethodDecl>(FD)->getParent(), ObjectType, |
6483 | ObjectClassification, FunctionArgs, CandidateSet, |
6484 | SuppressUserConversions, PartialOverloading); |
6485 | } |
6486 | } else { |
6487 | |
6488 | |
6489 | |
6490 | |
6491 | if (Args.size() > 0 && |
6492 | (!Args[0] || (FirstArgumentIsBase && isa<CXXMethodDecl>(FD) && |
6493 | !isa<CXXConstructorDecl>(FD)))) { |
6494 | (FD)->isStatic()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6494, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(cast<CXXMethodDecl>(FD)->isStatic()); |
6495 | FunctionArgs = Args.slice(1); |
6496 | } |
6497 | if (FunTmpl) { |
6498 | AddTemplateOverloadCandidate( |
6499 | FunTmpl, F.getPair(), ExplicitTemplateArgs, FunctionArgs, |
6500 | CandidateSet, SuppressUserConversions, PartialOverloading); |
6501 | } else { |
6502 | AddOverloadCandidate(FD, F.getPair(), FunctionArgs, CandidateSet, |
6503 | SuppressUserConversions, PartialOverloading); |
6504 | } |
6505 | } |
6506 | } |
6507 | } |
6508 | |
6509 | |
6510 | |
6511 | void Sema::AddMethodCandidate(DeclAccessPair FoundDecl, |
6512 | QualType ObjectType, |
6513 | Expr::Classification ObjectClassification, |
6514 | ArrayRef<Expr *> Args, |
6515 | OverloadCandidateSet& CandidateSet, |
6516 | bool SuppressUserConversions) { |
6517 | NamedDecl *Decl = FoundDecl.getDecl(); |
6518 | CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(Decl->getDeclContext()); |
6519 | |
6520 | if (isa<UsingShadowDecl>(Decl)) |
6521 | Decl = cast<UsingShadowDecl>(Decl)->getTargetDecl(); |
6522 | |
6523 | if (FunctionTemplateDecl *TD = dyn_cast<FunctionTemplateDecl>(Decl)) { |
6524 | (0) . __assert_fail ("isa(TD->getTemplatedDecl()) && \"Expected a member function template\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6525, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<CXXMethodDecl>(TD->getTemplatedDecl()) && |
6525 | (0) . __assert_fail ("isa(TD->getTemplatedDecl()) && \"Expected a member function template\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6525, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Expected a member function template"); |
6526 | AddMethodTemplateCandidate(TD, FoundDecl, ActingContext, |
6527 | nullptr, ObjectType, |
6528 | ObjectClassification, Args, CandidateSet, |
6529 | SuppressUserConversions); |
6530 | } else { |
6531 | AddMethodCandidate(cast<CXXMethodDecl>(Decl), FoundDecl, ActingContext, |
6532 | ObjectType, ObjectClassification, Args, CandidateSet, |
6533 | SuppressUserConversions); |
6534 | } |
6535 | } |
6536 | |
6537 | |
6538 | |
6539 | |
6540 | |
6541 | |
6542 | |
6543 | |
6544 | void |
6545 | Sema::AddMethodCandidate(CXXMethodDecl *Method, DeclAccessPair FoundDecl, |
6546 | CXXRecordDecl *ActingContext, QualType ObjectType, |
6547 | Expr::Classification ObjectClassification, |
6548 | ArrayRef<Expr *> Args, |
6549 | OverloadCandidateSet &CandidateSet, |
6550 | bool SuppressUserConversions, |
6551 | bool PartialOverloading, |
6552 | ConversionSequenceList EarlyConversions) { |
6553 | const FunctionProtoType *Proto |
6554 | = dyn_cast<FunctionProtoType>(Method->getType()->getAs<FunctionType>()); |
6555 | (0) . __assert_fail ("Proto && \"Methods without a prototype cannot be overloaded\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6555, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Proto && "Methods without a prototype cannot be overloaded"); |
6556 | (0) . __assert_fail ("!isa(Method) && \"Use AddOverloadCandidate for constructors\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6557, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!isa<CXXConstructorDecl>(Method) && |
6557 | (0) . __assert_fail ("!isa(Method) && \"Use AddOverloadCandidate for constructors\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6557, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Use AddOverloadCandidate for constructors"); |
6558 | |
6559 | if (!CandidateSet.isNewCandidate(Method)) |
6560 | return; |
6561 | |
6562 | |
6563 | |
6564 | |
6565 | if (Method->isDefaulted() && Method->isDeleted() && |
6566 | Method->isMoveAssignmentOperator()) |
6567 | return; |
6568 | |
6569 | |
6570 | EnterExpressionEvaluationContext Unevaluated( |
6571 | *this, Sema::ExpressionEvaluationContext::Unevaluated); |
6572 | |
6573 | |
6574 | OverloadCandidate &Candidate = |
6575 | CandidateSet.addCandidate(Args.size() + 1, EarlyConversions); |
6576 | Candidate.FoundDecl = FoundDecl; |
6577 | Candidate.Function = Method; |
6578 | Candidate.IsSurrogate = false; |
6579 | Candidate.IgnoreObjectArgument = false; |
6580 | Candidate.ExplicitCallArguments = Args.size(); |
6581 | |
6582 | unsigned NumParams = Proto->getNumParams(); |
6583 | |
6584 | |
6585 | |
6586 | |
6587 | if (TooManyArguments(NumParams, Args.size(), PartialOverloading) && |
6588 | !Proto->isVariadic()) { |
6589 | Candidate.Viable = false; |
6590 | Candidate.FailureKind = ovl_fail_too_many_arguments; |
6591 | return; |
6592 | } |
6593 | |
6594 | |
6595 | |
6596 | |
6597 | |
6598 | |
6599 | unsigned MinRequiredArgs = Method->getMinRequiredArguments(); |
6600 | if (Args.size() < MinRequiredArgs && !PartialOverloading) { |
6601 | |
6602 | Candidate.Viable = false; |
6603 | Candidate.FailureKind = ovl_fail_too_few_arguments; |
6604 | return; |
6605 | } |
6606 | |
6607 | Candidate.Viable = true; |
6608 | |
6609 | if (Method->isStatic() || ObjectType.isNull()) |
6610 | |
6611 | Candidate.IgnoreObjectArgument = true; |
6612 | else { |
6613 | |
6614 | |
6615 | Candidate.Conversions[0] = TryObjectArgumentInitialization( |
6616 | *this, CandidateSet.getLocation(), ObjectType, ObjectClassification, |
6617 | Method, ActingContext); |
6618 | if (Candidate.Conversions[0].isBad()) { |
6619 | Candidate.Viable = false; |
6620 | Candidate.FailureKind = ovl_fail_bad_conversion; |
6621 | return; |
6622 | } |
6623 | } |
6624 | |
6625 | |
6626 | if (getLangOpts().CUDA) |
6627 | if (const FunctionDecl *Caller = dyn_cast<FunctionDecl>(CurContext)) |
6628 | if (!IsAllowedCUDACall(Caller, Method)) { |
6629 | Candidate.Viable = false; |
6630 | Candidate.FailureKind = ovl_fail_bad_target; |
6631 | return; |
6632 | } |
6633 | |
6634 | |
6635 | |
6636 | for (unsigned ArgIdx = 0; ArgIdx < Args.size(); ++ArgIdx) { |
6637 | if (Candidate.Conversions[ArgIdx + 1].isInitialized()) { |
6638 | |
6639 | |
6640 | } else if (ArgIdx < NumParams) { |
6641 | |
6642 | |
6643 | |
6644 | |
6645 | QualType ParamType = Proto->getParamType(ArgIdx); |
6646 | Candidate.Conversions[ArgIdx + 1] |
6647 | = TryCopyInitialization(*this, Args[ArgIdx], ParamType, |
6648 | SuppressUserConversions, |
6649 | , |
6650 | |
6651 | getLangOpts().ObjCAutoRefCount); |
6652 | if (Candidate.Conversions[ArgIdx + 1].isBad()) { |
6653 | Candidate.Viable = false; |
6654 | Candidate.FailureKind = ovl_fail_bad_conversion; |
6655 | return; |
6656 | } |
6657 | } else { |
6658 | |
6659 | |
6660 | |
6661 | Candidate.Conversions[ArgIdx + 1].setEllipsis(); |
6662 | } |
6663 | } |
6664 | |
6665 | if (EnableIfAttr *FailedAttr = CheckEnableIf(Method, Args, true)) { |
6666 | Candidate.Viable = false; |
6667 | Candidate.FailureKind = ovl_fail_enable_if; |
6668 | Candidate.DeductionFailure.Data = FailedAttr; |
6669 | return; |
6670 | } |
6671 | |
6672 | if (Method->isMultiVersion() && Method->hasAttr<TargetAttr>() && |
6673 | !Method->getAttr<TargetAttr>()->isDefaultVersion()) { |
6674 | Candidate.Viable = false; |
6675 | Candidate.FailureKind = ovl_non_default_multiversion_function; |
6676 | } |
6677 | } |
6678 | |
6679 | |
6680 | |
6681 | |
6682 | void |
6683 | Sema::AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, |
6684 | DeclAccessPair FoundDecl, |
6685 | CXXRecordDecl *ActingContext, |
6686 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
6687 | QualType ObjectType, |
6688 | Expr::Classification ObjectClassification, |
6689 | ArrayRef<Expr *> Args, |
6690 | OverloadCandidateSet& CandidateSet, |
6691 | bool SuppressUserConversions, |
6692 | bool PartialOverloading) { |
6693 | if (!CandidateSet.isNewCandidate(MethodTmpl)) |
6694 | return; |
6695 | |
6696 | |
6697 | |
6698 | |
6699 | |
6700 | |
6701 | |
6702 | |
6703 | |
6704 | |
6705 | TemplateDeductionInfo Info(CandidateSet.getLocation()); |
6706 | FunctionDecl *Specialization = nullptr; |
6707 | ConversionSequenceList Conversions; |
6708 | if (TemplateDeductionResult Result = DeduceTemplateArguments( |
6709 | MethodTmpl, ExplicitTemplateArgs, Args, Specialization, Info, |
6710 | PartialOverloading, [&](ArrayRef<QualType> ParamTypes) { |
6711 | return CheckNonDependentConversions( |
6712 | MethodTmpl, ParamTypes, Args, CandidateSet, Conversions, |
6713 | SuppressUserConversions, ActingContext, ObjectType, |
6714 | ObjectClassification); |
6715 | })) { |
6716 | OverloadCandidate &Candidate = |
6717 | CandidateSet.addCandidate(Conversions.size(), Conversions); |
6718 | Candidate.FoundDecl = FoundDecl; |
6719 | Candidate.Function = MethodTmpl->getTemplatedDecl(); |
6720 | Candidate.Viable = false; |
6721 | Candidate.IsSurrogate = false; |
6722 | Candidate.IgnoreObjectArgument = |
6723 | cast<CXXMethodDecl>(Candidate.Function)->isStatic() || |
6724 | ObjectType.isNull(); |
6725 | Candidate.ExplicitCallArguments = Args.size(); |
6726 | if (Result == TDK_NonDependentConversionFailure) |
6727 | Candidate.FailureKind = ovl_fail_bad_conversion; |
6728 | else { |
6729 | Candidate.FailureKind = ovl_fail_bad_deduction; |
6730 | Candidate.DeductionFailure = MakeDeductionFailureInfo(Context, Result, |
6731 | Info); |
6732 | } |
6733 | return; |
6734 | } |
6735 | |
6736 | |
6737 | |
6738 | (0) . __assert_fail ("Specialization && \"Missing member function template specialization?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6738, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Specialization && "Missing member function template specialization?"); |
6739 | (0) . __assert_fail ("isa(Specialization) && \"Specialization is not a member function?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6740, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<CXXMethodDecl>(Specialization) && |
6740 | (0) . __assert_fail ("isa(Specialization) && \"Specialization is not a member function?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6740, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Specialization is not a member function?"); |
6741 | AddMethodCandidate(cast<CXXMethodDecl>(Specialization), FoundDecl, |
6742 | ActingContext, ObjectType, ObjectClassification, Args, |
6743 | CandidateSet, SuppressUserConversions, PartialOverloading, |
6744 | Conversions); |
6745 | } |
6746 | |
6747 | |
6748 | |
6749 | |
6750 | void Sema::AddTemplateOverloadCandidate( |
6751 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
6752 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
6753 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions, |
6754 | bool PartialOverloading, ADLCallKind IsADLCandidate) { |
6755 | if (!CandidateSet.isNewCandidate(FunctionTemplate)) |
6756 | return; |
6757 | |
6758 | |
6759 | |
6760 | |
6761 | |
6762 | |
6763 | |
6764 | |
6765 | |
6766 | |
6767 | TemplateDeductionInfo Info(CandidateSet.getLocation()); |
6768 | FunctionDecl *Specialization = nullptr; |
6769 | ConversionSequenceList Conversions; |
6770 | if (TemplateDeductionResult Result = DeduceTemplateArguments( |
6771 | FunctionTemplate, ExplicitTemplateArgs, Args, Specialization, Info, |
6772 | PartialOverloading, [&](ArrayRef<QualType> ParamTypes) { |
6773 | return CheckNonDependentConversions(FunctionTemplate, ParamTypes, |
6774 | Args, CandidateSet, Conversions, |
6775 | SuppressUserConversions); |
6776 | })) { |
6777 | OverloadCandidate &Candidate = |
6778 | CandidateSet.addCandidate(Conversions.size(), Conversions); |
6779 | Candidate.FoundDecl = FoundDecl; |
6780 | Candidate.Function = FunctionTemplate->getTemplatedDecl(); |
6781 | Candidate.Viable = false; |
6782 | Candidate.IsSurrogate = false; |
6783 | Candidate.IsADLCandidate = IsADLCandidate; |
6784 | |
6785 | |
6786 | Candidate.IgnoreObjectArgument = |
6787 | isa<CXXMethodDecl>(Candidate.Function) && |
6788 | !isa<CXXConstructorDecl>(Candidate.Function); |
6789 | Candidate.ExplicitCallArguments = Args.size(); |
6790 | if (Result == TDK_NonDependentConversionFailure) |
6791 | Candidate.FailureKind = ovl_fail_bad_conversion; |
6792 | else { |
6793 | Candidate.FailureKind = ovl_fail_bad_deduction; |
6794 | Candidate.DeductionFailure = MakeDeductionFailureInfo(Context, Result, |
6795 | Info); |
6796 | } |
6797 | return; |
6798 | } |
6799 | |
6800 | |
6801 | |
6802 | (0) . __assert_fail ("Specialization && \"Missing function template specialization?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6802, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Specialization && "Missing function template specialization?"); |
6803 | AddOverloadCandidate(Specialization, FoundDecl, Args, CandidateSet, |
6804 | SuppressUserConversions, PartialOverloading, |
6805 | false, IsADLCandidate, Conversions); |
6806 | } |
6807 | |
6808 | |
6809 | |
6810 | |
6811 | bool Sema::CheckNonDependentConversions( |
6812 | FunctionTemplateDecl *FunctionTemplate, ArrayRef<QualType> ParamTypes, |
6813 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
6814 | ConversionSequenceList &Conversions, bool SuppressUserConversions, |
6815 | CXXRecordDecl *ActingContext, QualType ObjectType, |
6816 | Expr::Classification ObjectClassification) { |
6817 | |
6818 | |
6819 | |
6820 | const bool AllowExplicit = false; |
6821 | |
6822 | auto *FD = FunctionTemplate->getTemplatedDecl(); |
6823 | auto *Method = dyn_cast<CXXMethodDecl>(FD); |
6824 | bool HasThisConversion = Method && !isa<CXXConstructorDecl>(Method); |
6825 | unsigned ThisConversions = HasThisConversion ? 1 : 0; |
6826 | |
6827 | Conversions = |
6828 | CandidateSet.allocateConversionSequences(ThisConversions + Args.size()); |
6829 | |
6830 | |
6831 | EnterExpressionEvaluationContext Unevaluated( |
6832 | *this, Sema::ExpressionEvaluationContext::Unevaluated); |
6833 | |
6834 | |
6835 | |
6836 | |
6837 | if (HasThisConversion && !cast<CXXMethodDecl>(FD)->isStatic() && |
6838 | !ObjectType.isNull()) { |
6839 | Conversions[0] = TryObjectArgumentInitialization( |
6840 | *this, CandidateSet.getLocation(), ObjectType, ObjectClassification, |
6841 | Method, ActingContext); |
6842 | if (Conversions[0].isBad()) |
6843 | return true; |
6844 | } |
6845 | |
6846 | for (unsigned I = 0, N = std::min(ParamTypes.size(), Args.size()); I != N; |
6847 | ++I) { |
6848 | QualType ParamType = ParamTypes[I]; |
6849 | if (!ParamType->isDependentType()) { |
6850 | Conversions[ThisConversions + I] |
6851 | = TryCopyInitialization(*this, Args[I], ParamType, |
6852 | SuppressUserConversions, |
6853 | , |
6854 | |
6855 | getLangOpts().ObjCAutoRefCount, |
6856 | AllowExplicit); |
6857 | if (Conversions[ThisConversions + I].isBad()) |
6858 | return true; |
6859 | } |
6860 | } |
6861 | |
6862 | return false; |
6863 | } |
6864 | |
6865 | |
6866 | |
6867 | |
6868 | |
6869 | |
6870 | |
6871 | |
6872 | |
6873 | |
6874 | |
6875 | |
6876 | |
6877 | static bool isAllowableExplicitConversion(Sema &S, |
6878 | QualType ConvType, QualType ToType, |
6879 | bool AllowObjCPointerConversion) { |
6880 | QualType ToNonRefType = ToType.getNonReferenceType(); |
6881 | |
6882 | |
6883 | if (S.Context.hasSameUnqualifiedType(ConvType, ToNonRefType)) |
6884 | return true; |
6885 | |
6886 | |
6887 | bool ObjCLifetimeConversion; |
6888 | if (S.IsQualificationConversion(ConvType, ToNonRefType, , |
6889 | ObjCLifetimeConversion)) |
6890 | return true; |
6891 | |
6892 | |
6893 | |
6894 | if (!AllowObjCPointerConversion) |
6895 | return false; |
6896 | |
6897 | |
6898 | bool IncompatibleObjC = false; |
6899 | QualType ConvertedType; |
6900 | return S.isObjCPointerConversion(ConvType, ToNonRefType, ConvertedType, |
6901 | IncompatibleObjC); |
6902 | } |
6903 | |
6904 | |
6905 | |
6906 | |
6907 | |
6908 | |
6909 | |
6910 | void |
6911 | Sema::AddConversionCandidate(CXXConversionDecl *Conversion, |
6912 | DeclAccessPair FoundDecl, |
6913 | CXXRecordDecl *ActingContext, |
6914 | Expr *From, QualType ToType, |
6915 | OverloadCandidateSet& CandidateSet, |
6916 | bool AllowObjCConversionOnExplicit, |
6917 | bool AllowResultConversion) { |
6918 | (0) . __assert_fail ("!Conversion->getDescribedFunctionTemplate() && \"Conversion function templates use AddTemplateConversionCandidate\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6919, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Conversion->getDescribedFunctionTemplate() && |
6919 | (0) . __assert_fail ("!Conversion->getDescribedFunctionTemplate() && \"Conversion function templates use AddTemplateConversionCandidate\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 6919, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Conversion function templates use AddTemplateConversionCandidate"); |
6920 | QualType ConvType = Conversion->getConversionType().getNonReferenceType(); |
6921 | if (!CandidateSet.isNewCandidate(Conversion)) |
6922 | return; |
6923 | |
6924 | |
6925 | |
6926 | if (getLangOpts().CPlusPlus14 && ConvType->isUndeducedType()) { |
6927 | if (DeduceReturnType(Conversion, From->getExprLoc())) |
6928 | return; |
6929 | ConvType = Conversion->getConversionType().getNonReferenceType(); |
6930 | } |
6931 | |
6932 | |
6933 | |
6934 | if (!AllowResultConversion && |
6935 | !Context.hasSameUnqualifiedType(Conversion->getConversionType(), ToType)) |
6936 | return; |
6937 | |
6938 | |
6939 | |
6940 | |
6941 | if (Conversion->isExplicit() && |
6942 | !isAllowableExplicitConversion(*this, ConvType, ToType, |
6943 | AllowObjCConversionOnExplicit)) |
6944 | return; |
6945 | |
6946 | |
6947 | EnterExpressionEvaluationContext Unevaluated( |
6948 | *this, Sema::ExpressionEvaluationContext::Unevaluated); |
6949 | |
6950 | |
6951 | OverloadCandidate &Candidate = CandidateSet.addCandidate(1); |
6952 | Candidate.FoundDecl = FoundDecl; |
6953 | Candidate.Function = Conversion; |
6954 | Candidate.IsSurrogate = false; |
6955 | Candidate.IgnoreObjectArgument = false; |
6956 | Candidate.FinalConversion.setAsIdentityConversion(); |
6957 | Candidate.FinalConversion.setFromType(ConvType); |
6958 | Candidate.FinalConversion.setAllToTypes(ToType); |
6959 | Candidate.Viable = true; |
6960 | Candidate.ExplicitCallArguments = 1; |
6961 | |
6962 | |
6963 | |
6964 | |
6965 | |
6966 | |
6967 | |
6968 | |
6969 | QualType ImplicitParamType = From->getType(); |
6970 | if (const PointerType *FromPtrType = ImplicitParamType->getAs<PointerType>()) |
6971 | ImplicitParamType = FromPtrType->getPointeeType(); |
6972 | CXXRecordDecl *ConversionContext |
6973 | = cast<CXXRecordDecl>(ImplicitParamType->getAs<RecordType>()->getDecl()); |
6974 | |
6975 | Candidate.Conversions[0] = TryObjectArgumentInitialization( |
6976 | *this, CandidateSet.getLocation(), From->getType(), |
6977 | From->Classify(Context), Conversion, ConversionContext); |
6978 | |
6979 | if (Candidate.Conversions[0].isBad()) { |
6980 | Candidate.Viable = false; |
6981 | Candidate.FailureKind = ovl_fail_bad_conversion; |
6982 | return; |
6983 | } |
6984 | |
6985 | |
6986 | |
6987 | |
6988 | QualType FromCanon |
6989 | = Context.getCanonicalType(From->getType().getUnqualifiedType()); |
6990 | QualType ToCanon = Context.getCanonicalType(ToType).getUnqualifiedType(); |
6991 | if (FromCanon == ToCanon || |
6992 | IsDerivedFrom(CandidateSet.getLocation(), FromCanon, ToCanon)) { |
6993 | Candidate.Viable = false; |
6994 | Candidate.FailureKind = ovl_fail_trivial_conversion; |
6995 | return; |
6996 | } |
6997 | |
6998 | |
6999 | |
7000 | |
7001 | |
7002 | |
7003 | |
7004 | |
7005 | |
7006 | DeclRefExpr ConversionRef(Context, Conversion, false, Conversion->getType(), |
7007 | VK_LValue, From->getBeginLoc()); |
7008 | ImplicitCastExpr ConversionFn(ImplicitCastExpr::OnStack, |
7009 | Context.getPointerType(Conversion->getType()), |
7010 | CK_FunctionToPointerDecay, |
7011 | &ConversionRef, VK_RValue); |
7012 | |
7013 | QualType ConversionType = Conversion->getConversionType(); |
7014 | if (!isCompleteType(From->getBeginLoc(), ConversionType)) { |
7015 | Candidate.Viable = false; |
7016 | Candidate.FailureKind = ovl_fail_bad_final_conversion; |
7017 | return; |
7018 | } |
7019 | |
7020 | ExprValueKind VK = Expr::getValueKindForType(ConversionType); |
7021 | |
7022 | |
7023 | |
7024 | |
7025 | QualType CallResultType = ConversionType.getNonLValueExprType(Context); |
7026 | |
7027 | llvm::AlignedCharArray<alignof(CallExpr), sizeof(CallExpr) + sizeof(Stmt *)> |
7028 | Buffer; |
7029 | CallExpr *TheTemporaryCall = CallExpr::CreateTemporary( |
7030 | Buffer.buffer, &ConversionFn, CallResultType, VK, From->getBeginLoc()); |
7031 | |
7032 | ImplicitConversionSequence ICS = |
7033 | TryCopyInitialization(*this, TheTemporaryCall, ToType, |
7034 | , |
7035 | , |
7036 | ); |
7037 | |
7038 | switch (ICS.getKind()) { |
7039 | case ImplicitConversionSequence::StandardConversion: |
7040 | Candidate.FinalConversion = ICS.Standard; |
7041 | |
7042 | |
7043 | |
7044 | |
7045 | |
7046 | if (Conversion->getPrimaryTemplate() && |
7047 | GetConversionRank(ICS.Standard.Second) != ICR_Exact_Match) { |
7048 | Candidate.Viable = false; |
7049 | Candidate.FailureKind = ovl_fail_final_conversion_not_exact; |
7050 | return; |
7051 | } |
7052 | |
7053 | |
7054 | |
7055 | |
7056 | |
7057 | |
7058 | if (ToType->isRValueReferenceType() && |
7059 | ICS.Standard.First == ICK_Lvalue_To_Rvalue) { |
7060 | Candidate.Viable = false; |
7061 | Candidate.FailureKind = ovl_fail_bad_final_conversion; |
7062 | return; |
7063 | } |
7064 | break; |
7065 | |
7066 | case ImplicitConversionSequence::BadConversion: |
7067 | Candidate.Viable = false; |
7068 | Candidate.FailureKind = ovl_fail_bad_final_conversion; |
7069 | return; |
7070 | |
7071 | default: |
7072 | llvm_unreachable( |
7073 | "Can only end up with a standard conversion sequence or failure"); |
7074 | } |
7075 | |
7076 | if (EnableIfAttr *FailedAttr = CheckEnableIf(Conversion, None)) { |
7077 | Candidate.Viable = false; |
7078 | Candidate.FailureKind = ovl_fail_enable_if; |
7079 | Candidate.DeductionFailure.Data = FailedAttr; |
7080 | return; |
7081 | } |
7082 | |
7083 | if (Conversion->isMultiVersion() && Conversion->hasAttr<TargetAttr>() && |
7084 | !Conversion->getAttr<TargetAttr>()->isDefaultVersion()) { |
7085 | Candidate.Viable = false; |
7086 | Candidate.FailureKind = ovl_non_default_multiversion_function; |
7087 | } |
7088 | } |
7089 | |
7090 | |
7091 | |
7092 | |
7093 | |
7094 | |
7095 | void |
7096 | Sema::AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, |
7097 | DeclAccessPair FoundDecl, |
7098 | CXXRecordDecl *ActingDC, |
7099 | Expr *From, QualType ToType, |
7100 | OverloadCandidateSet &CandidateSet, |
7101 | bool AllowObjCConversionOnExplicit, |
7102 | bool AllowResultConversion) { |
7103 | (0) . __assert_fail ("isa(FunctionTemplate->getTemplatedDecl()) && \"Only conversion function templates permitted here\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 7104, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<CXXConversionDecl>(FunctionTemplate->getTemplatedDecl()) && |
7104 | (0) . __assert_fail ("isa(FunctionTemplate->getTemplatedDecl()) && \"Only conversion function templates permitted here\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 7104, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Only conversion function templates permitted here"); |
7105 | |
7106 | if (!CandidateSet.isNewCandidate(FunctionTemplate)) |
7107 | return; |
7108 | |
7109 | TemplateDeductionInfo Info(CandidateSet.getLocation()); |
7110 | CXXConversionDecl *Specialization = nullptr; |
7111 | if (TemplateDeductionResult Result |
7112 | = DeduceTemplateArguments(FunctionTemplate, ToType, |
7113 | Specialization, Info)) { |
7114 | OverloadCandidate &Candidate = CandidateSet.addCandidate(); |
7115 | Candidate.FoundDecl = FoundDecl; |
7116 | Candidate.Function = FunctionTemplate->getTemplatedDecl(); |
7117 | Candidate.Viable = false; |
7118 | Candidate.FailureKind = ovl_fail_bad_deduction; |
7119 | Candidate.IsSurrogate = false; |
7120 | Candidate.IgnoreObjectArgument = false; |
7121 | Candidate.ExplicitCallArguments = 1; |
7122 | Candidate.DeductionFailure = MakeDeductionFailureInfo(Context, Result, |
7123 | Info); |
7124 | return; |
7125 | } |
7126 | |
7127 | |
7128 | |
7129 | (0) . __assert_fail ("Specialization && \"Missing function template specialization?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 7129, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Specialization && "Missing function template specialization?"); |
7130 | AddConversionCandidate(Specialization, FoundDecl, ActingDC, From, ToType, |
7131 | CandidateSet, AllowObjCConversionOnExplicit, |
7132 | AllowResultConversion); |
7133 | } |
7134 | |
7135 | |
7136 | |
7137 | |
7138 | |
7139 | |
7140 | void Sema::AddSurrogateCandidate(CXXConversionDecl *Conversion, |
7141 | DeclAccessPair FoundDecl, |
7142 | CXXRecordDecl *ActingContext, |
7143 | const FunctionProtoType *Proto, |
7144 | Expr *Object, |
7145 | ArrayRef<Expr *> Args, |
7146 | OverloadCandidateSet& CandidateSet) { |
7147 | if (!CandidateSet.isNewCandidate(Conversion)) |
7148 | return; |
7149 | |
7150 | |
7151 | EnterExpressionEvaluationContext Unevaluated( |
7152 | *this, Sema::ExpressionEvaluationContext::Unevaluated); |
7153 | |
7154 | OverloadCandidate &Candidate = CandidateSet.addCandidate(Args.size() + 1); |
7155 | Candidate.FoundDecl = FoundDecl; |
7156 | Candidate.Function = nullptr; |
7157 | Candidate.Surrogate = Conversion; |
7158 | Candidate.Viable = true; |
7159 | Candidate.IsSurrogate = true; |
7160 | Candidate.IgnoreObjectArgument = false; |
7161 | Candidate.ExplicitCallArguments = Args.size(); |
7162 | |
7163 | |
7164 | |
7165 | ImplicitConversionSequence ObjectInit = TryObjectArgumentInitialization( |
7166 | *this, CandidateSet.getLocation(), Object->getType(), |
7167 | Object->Classify(Context), Conversion, ActingContext); |
7168 | if (ObjectInit.isBad()) { |
7169 | Candidate.Viable = false; |
7170 | Candidate.FailureKind = ovl_fail_bad_conversion; |
7171 | Candidate.Conversions[0] = ObjectInit; |
7172 | return; |
7173 | } |
7174 | |
7175 | |
7176 | |
7177 | |
7178 | Candidate.Conversions[0].setUserDefined(); |
7179 | Candidate.Conversions[0].UserDefined.Before = ObjectInit.Standard; |
7180 | Candidate.Conversions[0].UserDefined.EllipsisConversion = false; |
7181 | Candidate.Conversions[0].UserDefined.HadMultipleCandidates = false; |
7182 | Candidate.Conversions[0].UserDefined.ConversionFunction = Conversion; |
7183 | Candidate.Conversions[0].UserDefined.FoundConversionFunction = FoundDecl; |
7184 | Candidate.Conversions[0].UserDefined.After |
7185 | = Candidate.Conversions[0].UserDefined.Before; |
7186 | Candidate.Conversions[0].UserDefined.After.setAsIdentityConversion(); |
7187 | |
7188 | |
7189 | unsigned NumParams = Proto->getNumParams(); |
7190 | |
7191 | |
7192 | |
7193 | |
7194 | if (Args.size() > NumParams && !Proto->isVariadic()) { |
7195 | Candidate.Viable = false; |
7196 | Candidate.FailureKind = ovl_fail_too_many_arguments; |
7197 | return; |
7198 | } |
7199 | |
7200 | |
7201 | |
7202 | if (Args.size() < NumParams) { |
7203 | |
7204 | Candidate.Viable = false; |
7205 | Candidate.FailureKind = ovl_fail_too_few_arguments; |
7206 | return; |
7207 | } |
7208 | |
7209 | |
7210 | |
7211 | for (unsigned ArgIdx = 0, N = Args.size(); ArgIdx != N; ++ArgIdx) { |
7212 | if (ArgIdx < NumParams) { |
7213 | |
7214 | |
7215 | |
7216 | |
7217 | QualType ParamType = Proto->getParamType(ArgIdx); |
7218 | Candidate.Conversions[ArgIdx + 1] |
7219 | = TryCopyInitialization(*this, Args[ArgIdx], ParamType, |
7220 | , |
7221 | , |
7222 | |
7223 | getLangOpts().ObjCAutoRefCount); |
7224 | if (Candidate.Conversions[ArgIdx + 1].isBad()) { |
7225 | Candidate.Viable = false; |
7226 | Candidate.FailureKind = ovl_fail_bad_conversion; |
7227 | return; |
7228 | } |
7229 | } else { |
7230 | |
7231 | |
7232 | |
7233 | Candidate.Conversions[ArgIdx + 1].setEllipsis(); |
7234 | } |
7235 | } |
7236 | |
7237 | if (EnableIfAttr *FailedAttr = CheckEnableIf(Conversion, None)) { |
7238 | Candidate.Viable = false; |
7239 | Candidate.FailureKind = ovl_fail_enable_if; |
7240 | Candidate.DeductionFailure.Data = FailedAttr; |
7241 | return; |
7242 | } |
7243 | } |
7244 | |
7245 | |
7246 | |
7247 | |
7248 | |
7249 | |
7250 | |
7251 | |
7252 | |
7253 | void Sema::AddMemberOperatorCandidates(OverloadedOperatorKind Op, |
7254 | SourceLocation OpLoc, |
7255 | ArrayRef<Expr *> Args, |
7256 | OverloadCandidateSet& CandidateSet, |
7257 | SourceRange OpRange) { |
7258 | DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(Op); |
7259 | |
7260 | |
7261 | |
7262 | |
7263 | |
7264 | |
7265 | |
7266 | |
7267 | |
7268 | QualType T1 = Args[0]->getType(); |
7269 | |
7270 | |
7271 | |
7272 | |
7273 | |
7274 | if (const RecordType *T1Rec = T1->getAs<RecordType>()) { |
7275 | |
7276 | if (!isCompleteType(OpLoc, T1) && !T1Rec->isBeingDefined()) |
7277 | return; |
7278 | |
7279 | if (!T1Rec->getDecl()->getDefinition()) |
7280 | return; |
7281 | |
7282 | LookupResult Operators(*this, OpName, OpLoc, LookupOrdinaryName); |
7283 | LookupQualifiedName(Operators, T1Rec->getDecl()); |
7284 | Operators.suppressDiagnostics(); |
7285 | |
7286 | for (LookupResult::iterator Oper = Operators.begin(), |
7287 | OperEnd = Operators.end(); |
7288 | Oper != OperEnd; |
7289 | ++Oper) |
7290 | AddMethodCandidate(Oper.getPair(), Args[0]->getType(), |
7291 | Args[0]->Classify(Context), Args.slice(1), |
7292 | CandidateSet, ); |
7293 | } |
7294 | } |
7295 | |
7296 | |
7297 | |
7298 | |
7299 | |
7300 | |
7301 | |
7302 | |
7303 | |
7304 | void Sema::AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args, |
7305 | OverloadCandidateSet& CandidateSet, |
7306 | bool IsAssignmentOperator, |
7307 | unsigned NumContextualBoolArguments) { |
7308 | |
7309 | EnterExpressionEvaluationContext Unevaluated( |
7310 | *this, Sema::ExpressionEvaluationContext::Unevaluated); |
7311 | |
7312 | |
7313 | OverloadCandidate &Candidate = CandidateSet.addCandidate(Args.size()); |
7314 | Candidate.FoundDecl = DeclAccessPair::make(nullptr, AS_none); |
7315 | Candidate.Function = nullptr; |
7316 | Candidate.IsSurrogate = false; |
7317 | Candidate.IgnoreObjectArgument = false; |
7318 | std::copy(ParamTys, ParamTys + Args.size(), Candidate.BuiltinParamTypes); |
7319 | |
7320 | |
7321 | |
7322 | Candidate.Viable = true; |
7323 | Candidate.ExplicitCallArguments = Args.size(); |
7324 | for (unsigned ArgIdx = 0, N = Args.size(); ArgIdx != N; ++ArgIdx) { |
7325 | |
7326 | |
7327 | |
7328 | |
7329 | |
7330 | |
7331 | |
7332 | |
7333 | |
7334 | |
7335 | |
7336 | |
7337 | if (ArgIdx < NumContextualBoolArguments) { |
7338 | (0) . __assert_fail ("ParamTys[ArgIdx] == Context.BoolTy && \"Contextual conversion to bool requires bool type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 7339, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ParamTys[ArgIdx] == Context.BoolTy && |
7339 | (0) . __assert_fail ("ParamTys[ArgIdx] == Context.BoolTy && \"Contextual conversion to bool requires bool type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 7339, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Contextual conversion to bool requires bool type"); |
7340 | Candidate.Conversions[ArgIdx] |
7341 | = TryContextuallyConvertToBool(*this, Args[ArgIdx]); |
7342 | } else { |
7343 | Candidate.Conversions[ArgIdx] |
7344 | = TryCopyInitialization(*this, Args[ArgIdx], ParamTys[ArgIdx], |
7345 | ArgIdx == 0 && IsAssignmentOperator, |
7346 | , |
7347 | |
7348 | getLangOpts().ObjCAutoRefCount); |
7349 | } |
7350 | if (Candidate.Conversions[ArgIdx].isBad()) { |
7351 | Candidate.Viable = false; |
7352 | Candidate.FailureKind = ovl_fail_bad_conversion; |
7353 | break; |
7354 | } |
7355 | } |
7356 | } |
7357 | |
7358 | namespace { |
7359 | |
7360 | |
7361 | |
7362 | |
7363 | |
7364 | class BuiltinCandidateTypeSet { |
7365 | |
7366 | typedef llvm::SetVector<QualType, SmallVector<QualType, 8>, |
7367 | llvm::SmallPtrSet<QualType, 8>> TypeSet; |
7368 | |
7369 | |
7370 | |
7371 | TypeSet PointerTypes; |
7372 | |
7373 | |
7374 | |
7375 | TypeSet MemberPointerTypes; |
7376 | |
7377 | |
7378 | |
7379 | TypeSet EnumerationTypes; |
7380 | |
7381 | |
7382 | |
7383 | TypeSet VectorTypes; |
7384 | |
7385 | |
7386 | bool HasNonRecordTypes; |
7387 | |
7388 | |
7389 | |
7390 | bool HasArithmeticOrEnumeralTypes; |
7391 | |
7392 | |
7393 | |
7394 | bool HasNullPtrType; |
7395 | |
7396 | |
7397 | |
7398 | Sema &SemaRef; |
7399 | |
7400 | |
7401 | ASTContext &Context; |
7402 | |
7403 | bool AddPointerWithMoreQualifiedTypeVariants(QualType Ty, |
7404 | const Qualifiers &VisibleQuals); |
7405 | bool AddMemberPointerWithMoreQualifiedTypeVariants(QualType Ty); |
7406 | |
7407 | public: |
7408 | |
7409 | typedef TypeSet::iterator iterator; |
7410 | |
7411 | BuiltinCandidateTypeSet(Sema &SemaRef) |
7412 | : HasNonRecordTypes(false), |
7413 | HasArithmeticOrEnumeralTypes(false), |
7414 | HasNullPtrType(false), |
7415 | SemaRef(SemaRef), |
7416 | Context(SemaRef.Context) { } |
7417 | |
7418 | void AddTypesConvertedFrom(QualType Ty, |
7419 | SourceLocation Loc, |
7420 | bool AllowUserConversions, |
7421 | bool AllowExplicitConversions, |
7422 | const Qualifiers &VisibleTypeConversionsQuals); |
7423 | |
7424 | |
7425 | iterator pointer_begin() { return PointerTypes.begin(); } |
7426 | |
7427 | |
7428 | iterator pointer_end() { return PointerTypes.end(); } |
7429 | |
7430 | |
7431 | iterator member_pointer_begin() { return MemberPointerTypes.begin(); } |
7432 | |
7433 | |
7434 | iterator member_pointer_end() { return MemberPointerTypes.end(); } |
7435 | |
7436 | |
7437 | iterator enumeration_begin() { return EnumerationTypes.begin(); } |
7438 | |
7439 | |
7440 | iterator enumeration_end() { return EnumerationTypes.end(); } |
7441 | |
7442 | iterator vector_begin() { return VectorTypes.begin(); } |
7443 | iterator vector_end() { return VectorTypes.end(); } |
7444 | |
7445 | bool hasNonRecordTypes() { return HasNonRecordTypes; } |
7446 | bool hasArithmeticOrEnumeralTypes() { return HasArithmeticOrEnumeralTypes; } |
7447 | bool hasNullPtrType() const { return HasNullPtrType; } |
7448 | }; |
7449 | |
7450 | } |
7451 | |
7452 | |
7453 | |
7454 | |
7455 | |
7456 | |
7457 | |
7458 | |
7459 | |
7460 | |
7461 | bool |
7462 | BuiltinCandidateTypeSet::AddPointerWithMoreQualifiedTypeVariants(QualType Ty, |
7463 | const Qualifiers &VisibleQuals) { |
7464 | |
7465 | |
7466 | if (!PointerTypes.insert(Ty)) |
7467 | return false; |
7468 | |
7469 | QualType PointeeTy; |
7470 | const PointerType *PointerTy = Ty->getAs<PointerType>(); |
7471 | bool buildObjCPtr = false; |
7472 | if (!PointerTy) { |
7473 | const ObjCObjectPointerType *PTy = Ty->castAs<ObjCObjectPointerType>(); |
7474 | PointeeTy = PTy->getPointeeType(); |
7475 | buildObjCPtr = true; |
7476 | } else { |
7477 | PointeeTy = PointerTy->getPointeeType(); |
7478 | } |
7479 | |
7480 | |
7481 | |
7482 | |
7483 | |
7484 | if (PointeeTy->isArrayType()) |
7485 | return true; |
7486 | |
7487 | unsigned BaseCVR = PointeeTy.getCVRQualifiers(); |
7488 | bool hasVolatile = VisibleQuals.hasVolatile(); |
7489 | bool hasRestrict = VisibleQuals.hasRestrict(); |
7490 | |
7491 | |
7492 | for (unsigned CVR = BaseCVR+1; CVR <= Qualifiers::CVRMask; ++CVR) { |
7493 | if ((CVR | BaseCVR) != CVR) continue; |
7494 | |
7495 | if ((CVR & Qualifiers::Volatile) && !hasVolatile) continue; |
7496 | |
7497 | |
7498 | |
7499 | if ((CVR & Qualifiers::Restrict) && |
7500 | (!hasRestrict || |
7501 | (!(PointeeTy->isAnyPointerType() || PointeeTy->isReferenceType())))) |
7502 | continue; |
7503 | |
7504 | |
7505 | QualType QPointeeTy = Context.getCVRQualifiedType(PointeeTy, CVR); |
7506 | |
7507 | |
7508 | QualType QPointerTy; |
7509 | if (!buildObjCPtr) |
7510 | QPointerTy = Context.getPointerType(QPointeeTy); |
7511 | else |
7512 | QPointerTy = Context.getObjCObjectPointerType(QPointeeTy); |
7513 | |
7514 | |
7515 | PointerTypes.insert(QPointerTy); |
7516 | } |
7517 | |
7518 | return true; |
7519 | } |
7520 | |
7521 | |
7522 | |
7523 | |
7524 | |
7525 | |
7526 | |
7527 | |
7528 | |
7529 | |
7530 | bool |
7531 | BuiltinCandidateTypeSet::AddMemberPointerWithMoreQualifiedTypeVariants( |
7532 | QualType Ty) { |
7533 | |
7534 | if (!MemberPointerTypes.insert(Ty)) |
7535 | return false; |
7536 | |
7537 | const MemberPointerType *PointerTy = Ty->getAs<MemberPointerType>(); |
7538 | (0) . __assert_fail ("PointerTy && \"type was not a member pointer type!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 7538, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(PointerTy && "type was not a member pointer type!"); |
7539 | |
7540 | QualType PointeeTy = PointerTy->getPointeeType(); |
7541 | |
7542 | |
7543 | |
7544 | |
7545 | if (PointeeTy->isArrayType()) |
7546 | return true; |
7547 | const Type *ClassTy = PointerTy->getClass(); |
7548 | |
7549 | |
7550 | |
7551 | unsigned BaseCVR = PointeeTy.getCVRQualifiers(); |
7552 | for (unsigned CVR = BaseCVR+1; CVR <= Qualifiers::CVRMask; ++CVR) { |
7553 | if ((CVR | BaseCVR) != CVR) continue; |
7554 | |
7555 | QualType QPointeeTy = Context.getCVRQualifiedType(PointeeTy, CVR); |
7556 | MemberPointerTypes.insert( |
7557 | Context.getMemberPointerType(QPointeeTy, ClassTy)); |
7558 | } |
7559 | |
7560 | return true; |
7561 | } |
7562 | |
7563 | |
7564 | |
7565 | |
7566 | |
7567 | |
7568 | |
7569 | |
7570 | |
7571 | void |
7572 | BuiltinCandidateTypeSet::AddTypesConvertedFrom(QualType Ty, |
7573 | SourceLocation Loc, |
7574 | bool AllowUserConversions, |
7575 | bool AllowExplicitConversions, |
7576 | const Qualifiers &VisibleQuals) { |
7577 | |
7578 | Ty = Context.getCanonicalType(Ty); |
7579 | |
7580 | |
7581 | |
7582 | if (const ReferenceType *RefTy = Ty->getAs<ReferenceType>()) |
7583 | Ty = RefTy->getPointeeType(); |
7584 | |
7585 | |
7586 | if (Ty->isArrayType()) |
7587 | Ty = SemaRef.Context.getArrayDecayedType(Ty); |
7588 | |
7589 | |
7590 | Ty = Ty.getLocalUnqualifiedType(); |
7591 | |
7592 | |
7593 | const RecordType *TyRec = Ty->getAs<RecordType>(); |
7594 | HasNonRecordTypes = HasNonRecordTypes || !TyRec; |
7595 | |
7596 | |
7597 | HasArithmeticOrEnumeralTypes = |
7598 | HasArithmeticOrEnumeralTypes || Ty->isArithmeticType(); |
7599 | |
7600 | if (Ty->isObjCIdType() || Ty->isObjCClassType()) |
7601 | PointerTypes.insert(Ty); |
7602 | else if (Ty->getAs<PointerType>() || Ty->getAs<ObjCObjectPointerType>()) { |
7603 | |
7604 | |
7605 | if (!AddPointerWithMoreQualifiedTypeVariants(Ty, VisibleQuals)) |
7606 | return; |
7607 | } else if (Ty->isMemberPointerType()) { |
7608 | |
7609 | if (!AddMemberPointerWithMoreQualifiedTypeVariants(Ty)) |
7610 | return; |
7611 | } else if (Ty->isEnumeralType()) { |
7612 | HasArithmeticOrEnumeralTypes = true; |
7613 | EnumerationTypes.insert(Ty); |
7614 | } else if (Ty->isVectorType()) { |
7615 | |
7616 | |
7617 | HasArithmeticOrEnumeralTypes = true; |
7618 | VectorTypes.insert(Ty); |
7619 | } else if (Ty->isNullPtrType()) { |
7620 | HasNullPtrType = true; |
7621 | } else if (AllowUserConversions && TyRec) { |
7622 | |
7623 | if (!SemaRef.isCompleteType(Loc, Ty)) |
7624 | return; |
7625 | |
7626 | CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(TyRec->getDecl()); |
7627 | for (NamedDecl *D : ClassDecl->getVisibleConversionFunctions()) { |
7628 | if (isa<UsingShadowDecl>(D)) |
7629 | D = cast<UsingShadowDecl>(D)->getTargetDecl(); |
7630 | |
7631 | |
7632 | |
7633 | if (isa<FunctionTemplateDecl>(D)) |
7634 | continue; |
7635 | |
7636 | CXXConversionDecl *Conv = cast<CXXConversionDecl>(D); |
7637 | if (AllowExplicitConversions || !Conv->isExplicit()) { |
7638 | AddTypesConvertedFrom(Conv->getConversionType(), Loc, false, false, |
7639 | VisibleQuals); |
7640 | } |
7641 | } |
7642 | } |
7643 | } |
7644 | |
7645 | |
7646 | static QualType AdjustAddressSpaceForBuiltinOperandType(Sema &S, QualType T, |
7647 | Expr *Arg) { |
7648 | return S.Context.getAddrSpaceQualType(T, Arg->getType().getAddressSpace()); |
7649 | } |
7650 | |
7651 | |
7652 | |
7653 | |
7654 | static void AddBuiltinAssignmentOperatorCandidates(Sema &S, |
7655 | QualType T, |
7656 | ArrayRef<Expr *> Args, |
7657 | OverloadCandidateSet &CandidateSet) { |
7658 | QualType ParamTypes[2]; |
7659 | |
7660 | |
7661 | ParamTypes[0] = S.Context.getLValueReferenceType( |
7662 | AdjustAddressSpaceForBuiltinOperandType(S, T, Args[0])); |
7663 | ParamTypes[1] = T; |
7664 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
7665 | ); |
7666 | |
7667 | if (!S.Context.getCanonicalType(T).isVolatileQualified()) { |
7668 | |
7669 | ParamTypes[0] = S.Context.getLValueReferenceType( |
7670 | AdjustAddressSpaceForBuiltinOperandType(S, S.Context.getVolatileType(T), |
7671 | Args[0])); |
7672 | ParamTypes[1] = T; |
7673 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
7674 | ); |
7675 | } |
7676 | } |
7677 | |
7678 | |
7679 | |
7680 | static Qualifiers CollectVRQualifiers(ASTContext &Context, Expr* ArgExpr) { |
7681 | Qualifiers VRQuals; |
7682 | const RecordType *TyRec; |
7683 | if (const MemberPointerType *RHSMPType = |
7684 | ArgExpr->getType()->getAs<MemberPointerType>()) |
7685 | TyRec = RHSMPType->getClass()->getAs<RecordType>(); |
7686 | else |
7687 | TyRec = ArgExpr->getType()->getAs<RecordType>(); |
7688 | if (!TyRec) { |
7689 | |
7690 | VRQuals.addVolatile(); |
7691 | VRQuals.addRestrict(); |
7692 | return VRQuals; |
7693 | } |
7694 | |
7695 | CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(TyRec->getDecl()); |
7696 | if (!ClassDecl->hasDefinition()) |
7697 | return VRQuals; |
7698 | |
7699 | for (NamedDecl *D : ClassDecl->getVisibleConversionFunctions()) { |
7700 | if (isa<UsingShadowDecl>(D)) |
7701 | D = cast<UsingShadowDecl>(D)->getTargetDecl(); |
7702 | if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D)) { |
7703 | QualType CanTy = Context.getCanonicalType(Conv->getConversionType()); |
7704 | if (const ReferenceType *ResTypeRef = CanTy->getAs<ReferenceType>()) |
7705 | CanTy = ResTypeRef->getPointeeType(); |
7706 | |
7707 | |
7708 | bool done = false; |
7709 | while (!done) { |
7710 | if (CanTy.isRestrictQualified()) |
7711 | VRQuals.addRestrict(); |
7712 | if (const PointerType *ResTypePtr = CanTy->getAs<PointerType>()) |
7713 | CanTy = ResTypePtr->getPointeeType(); |
7714 | else if (const MemberPointerType *ResTypeMPtr = |
7715 | CanTy->getAs<MemberPointerType>()) |
7716 | CanTy = ResTypeMPtr->getPointeeType(); |
7717 | else |
7718 | done = true; |
7719 | if (CanTy.isVolatileQualified()) |
7720 | VRQuals.addVolatile(); |
7721 | if (VRQuals.hasRestrict() && VRQuals.hasVolatile()) |
7722 | return VRQuals; |
7723 | } |
7724 | } |
7725 | } |
7726 | return VRQuals; |
7727 | } |
7728 | |
7729 | namespace { |
7730 | |
7731 | |
7732 | |
7733 | |
7734 | |
7735 | class BuiltinOperatorOverloadBuilder { |
7736 | |
7737 | Sema &S; |
7738 | ArrayRef<Expr *> Args; |
7739 | Qualifiers VisibleTypeConversionsQuals; |
7740 | bool HasArithmeticOrEnumeralCandidateType; |
7741 | SmallVectorImpl<BuiltinCandidateTypeSet> &CandidateTypes; |
7742 | OverloadCandidateSet &CandidateSet; |
7743 | |
7744 | static constexpr int ArithmeticTypesCap = 24; |
7745 | SmallVector<CanQualType, ArithmeticTypesCap> ArithmeticTypes; |
7746 | |
7747 | |
7748 | |
7749 | |
7750 | unsigned FirstIntegralType, |
7751 | LastIntegralType; |
7752 | unsigned FirstPromotedIntegralType, |
7753 | LastPromotedIntegralType; |
7754 | unsigned FirstPromotedArithmeticType, |
7755 | LastPromotedArithmeticType; |
7756 | unsigned NumArithmeticTypes; |
7757 | |
7758 | void InitArithmeticTypes() { |
7759 | |
7760 | FirstPromotedArithmeticType = 0; |
7761 | ArithmeticTypes.push_back(S.Context.FloatTy); |
7762 | ArithmeticTypes.push_back(S.Context.DoubleTy); |
7763 | ArithmeticTypes.push_back(S.Context.LongDoubleTy); |
7764 | if (S.Context.getTargetInfo().hasFloat128Type()) |
7765 | ArithmeticTypes.push_back(S.Context.Float128Ty); |
7766 | |
7767 | |
7768 | FirstIntegralType = ArithmeticTypes.size(); |
7769 | FirstPromotedIntegralType = ArithmeticTypes.size(); |
7770 | ArithmeticTypes.push_back(S.Context.IntTy); |
7771 | ArithmeticTypes.push_back(S.Context.LongTy); |
7772 | ArithmeticTypes.push_back(S.Context.LongLongTy); |
7773 | if (S.Context.getTargetInfo().hasInt128Type()) |
7774 | ArithmeticTypes.push_back(S.Context.Int128Ty); |
7775 | ArithmeticTypes.push_back(S.Context.UnsignedIntTy); |
7776 | ArithmeticTypes.push_back(S.Context.UnsignedLongTy); |
7777 | ArithmeticTypes.push_back(S.Context.UnsignedLongLongTy); |
7778 | if (S.Context.getTargetInfo().hasInt128Type()) |
7779 | ArithmeticTypes.push_back(S.Context.UnsignedInt128Ty); |
7780 | LastPromotedIntegralType = ArithmeticTypes.size(); |
7781 | LastPromotedArithmeticType = ArithmeticTypes.size(); |
7782 | |
7783 | |
7784 | ArithmeticTypes.push_back(S.Context.BoolTy); |
7785 | ArithmeticTypes.push_back(S.Context.CharTy); |
7786 | ArithmeticTypes.push_back(S.Context.WCharTy); |
7787 | if (S.Context.getLangOpts().Char8) |
7788 | ArithmeticTypes.push_back(S.Context.Char8Ty); |
7789 | ArithmeticTypes.push_back(S.Context.Char16Ty); |
7790 | ArithmeticTypes.push_back(S.Context.Char32Ty); |
7791 | ArithmeticTypes.push_back(S.Context.SignedCharTy); |
7792 | ArithmeticTypes.push_back(S.Context.ShortTy); |
7793 | ArithmeticTypes.push_back(S.Context.UnsignedCharTy); |
7794 | ArithmeticTypes.push_back(S.Context.UnsignedShortTy); |
7795 | LastIntegralType = ArithmeticTypes.size(); |
7796 | NumArithmeticTypes = ArithmeticTypes.size(); |
7797 | |
7798 | |
7799 | |
7800 | (0) . __assert_fail ("ArithmeticTypes.size() <= ArithmeticTypesCap && \"Enough inline storage for all arithmetic types.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 7801, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ArithmeticTypes.size() <= ArithmeticTypesCap && |
7801 | (0) . __assert_fail ("ArithmeticTypes.size() <= ArithmeticTypesCap && \"Enough inline storage for all arithmetic types.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 7801, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Enough inline storage for all arithmetic types."); |
7802 | } |
7803 | |
7804 | |
7805 | |
7806 | void addPlusPlusMinusMinusStyleOverloads(QualType CandidateTy, |
7807 | bool HasVolatile, |
7808 | bool HasRestrict) { |
7809 | QualType ParamTypes[2] = { |
7810 | S.Context.getLValueReferenceType(CandidateTy), |
7811 | S.Context.IntTy |
7812 | }; |
7813 | |
7814 | |
7815 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
7816 | |
7817 | |
7818 | |
7819 | if (HasVolatile) { |
7820 | ParamTypes[0] = |
7821 | S.Context.getLValueReferenceType( |
7822 | S.Context.getVolatileType(CandidateTy)); |
7823 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
7824 | } |
7825 | |
7826 | |
7827 | |
7828 | if (HasRestrict && CandidateTy->isAnyPointerType() && |
7829 | !CandidateTy.isRestrictQualified()) { |
7830 | ParamTypes[0] |
7831 | = S.Context.getLValueReferenceType( |
7832 | S.Context.getCVRQualifiedType(CandidateTy, Qualifiers::Restrict)); |
7833 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
7834 | |
7835 | if (HasVolatile) { |
7836 | ParamTypes[0] |
7837 | = S.Context.getLValueReferenceType( |
7838 | S.Context.getCVRQualifiedType(CandidateTy, |
7839 | (Qualifiers::Volatile | |
7840 | Qualifiers::Restrict))); |
7841 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
7842 | } |
7843 | } |
7844 | |
7845 | } |
7846 | |
7847 | public: |
7848 | BuiltinOperatorOverloadBuilder( |
7849 | Sema &S, ArrayRef<Expr *> Args, |
7850 | Qualifiers VisibleTypeConversionsQuals, |
7851 | bool HasArithmeticOrEnumeralCandidateType, |
7852 | SmallVectorImpl<BuiltinCandidateTypeSet> &CandidateTypes, |
7853 | OverloadCandidateSet &CandidateSet) |
7854 | : S(S), Args(Args), |
7855 | VisibleTypeConversionsQuals(VisibleTypeConversionsQuals), |
7856 | HasArithmeticOrEnumeralCandidateType( |
7857 | HasArithmeticOrEnumeralCandidateType), |
7858 | CandidateTypes(CandidateTypes), |
7859 | CandidateSet(CandidateSet) { |
7860 | |
7861 | InitArithmeticTypes(); |
7862 | } |
7863 | |
7864 | |
7865 | |
7866 | |
7867 | |
7868 | |
7869 | |
7870 | |
7871 | |
7872 | |
7873 | |
7874 | |
7875 | |
7876 | |
7877 | |
7878 | |
7879 | |
7880 | |
7881 | |
7882 | |
7883 | void addPlusPlusMinusMinusArithmeticOverloads(OverloadedOperatorKind Op) { |
7884 | if (!HasArithmeticOrEnumeralCandidateType) |
7885 | return; |
7886 | |
7887 | for (unsigned Arith = 0; Arith < NumArithmeticTypes; ++Arith) { |
7888 | const auto TypeOfT = ArithmeticTypes[Arith]; |
7889 | if (TypeOfT == S.Context.BoolTy) { |
7890 | if (Op == OO_MinusMinus) |
7891 | continue; |
7892 | if (Op == OO_PlusPlus && S.getLangOpts().CPlusPlus17) |
7893 | continue; |
7894 | } |
7895 | addPlusPlusMinusMinusStyleOverloads( |
7896 | TypeOfT, |
7897 | VisibleTypeConversionsQuals.hasVolatile(), |
7898 | VisibleTypeConversionsQuals.hasRestrict()); |
7899 | } |
7900 | } |
7901 | |
7902 | |
7903 | |
7904 | |
7905 | |
7906 | |
7907 | |
7908 | |
7909 | |
7910 | |
7911 | |
7912 | void addPlusPlusMinusMinusPointerOverloads() { |
7913 | for (BuiltinCandidateTypeSet::iterator |
7914 | Ptr = CandidateTypes[0].pointer_begin(), |
7915 | PtrEnd = CandidateTypes[0].pointer_end(); |
7916 | Ptr != PtrEnd; ++Ptr) { |
7917 | |
7918 | if (!(*Ptr)->getPointeeType()->isObjectType()) |
7919 | continue; |
7920 | |
7921 | addPlusPlusMinusMinusStyleOverloads(*Ptr, |
7922 | (!(*Ptr).isVolatileQualified() && |
7923 | VisibleTypeConversionsQuals.hasVolatile()), |
7924 | (!(*Ptr).isRestrictQualified() && |
7925 | VisibleTypeConversionsQuals.hasRestrict())); |
7926 | } |
7927 | } |
7928 | |
7929 | |
7930 | |
7931 | |
7932 | |
7933 | |
7934 | |
7935 | |
7936 | |
7937 | |
7938 | |
7939 | void addUnaryStarPointerOverloads() { |
7940 | for (BuiltinCandidateTypeSet::iterator |
7941 | Ptr = CandidateTypes[0].pointer_begin(), |
7942 | PtrEnd = CandidateTypes[0].pointer_end(); |
7943 | Ptr != PtrEnd; ++Ptr) { |
7944 | QualType ParamTy = *Ptr; |
7945 | QualType PointeeTy = ParamTy->getPointeeType(); |
7946 | if (!PointeeTy->isObjectType() && !PointeeTy->isFunctionType()) |
7947 | continue; |
7948 | |
7949 | if (const FunctionProtoType *Proto =PointeeTy->getAs<FunctionProtoType>()) |
7950 | if (Proto->getMethodQuals() || Proto->getRefQualifier()) |
7951 | continue; |
7952 | |
7953 | S.AddBuiltinCandidate(&ParamTy, Args, CandidateSet); |
7954 | } |
7955 | } |
7956 | |
7957 | |
7958 | |
7959 | |
7960 | |
7961 | |
7962 | |
7963 | void addUnaryPlusOrMinusArithmeticOverloads() { |
7964 | if (!HasArithmeticOrEnumeralCandidateType) |
7965 | return; |
7966 | |
7967 | for (unsigned Arith = FirstPromotedArithmeticType; |
7968 | Arith < LastPromotedArithmeticType; ++Arith) { |
7969 | QualType ArithTy = ArithmeticTypes[Arith]; |
7970 | S.AddBuiltinCandidate(&ArithTy, Args, CandidateSet); |
7971 | } |
7972 | |
7973 | |
7974 | for (BuiltinCandidateTypeSet::iterator |
7975 | Vec = CandidateTypes[0].vector_begin(), |
7976 | VecEnd = CandidateTypes[0].vector_end(); |
7977 | Vec != VecEnd; ++Vec) { |
7978 | QualType VecTy = *Vec; |
7979 | S.AddBuiltinCandidate(&VecTy, Args, CandidateSet); |
7980 | } |
7981 | } |
7982 | |
7983 | |
7984 | |
7985 | |
7986 | |
7987 | |
7988 | void addUnaryPlusPointerOverloads() { |
7989 | for (BuiltinCandidateTypeSet::iterator |
7990 | Ptr = CandidateTypes[0].pointer_begin(), |
7991 | PtrEnd = CandidateTypes[0].pointer_end(); |
7992 | Ptr != PtrEnd; ++Ptr) { |
7993 | QualType ParamTy = *Ptr; |
7994 | S.AddBuiltinCandidate(&ParamTy, Args, CandidateSet); |
7995 | } |
7996 | } |
7997 | |
7998 | |
7999 | |
8000 | |
8001 | |
8002 | |
8003 | void addUnaryTildePromotedIntegralOverloads() { |
8004 | if (!HasArithmeticOrEnumeralCandidateType) |
8005 | return; |
8006 | |
8007 | for (unsigned Int = FirstPromotedIntegralType; |
8008 | Int < LastPromotedIntegralType; ++Int) { |
8009 | QualType IntTy = ArithmeticTypes[Int]; |
8010 | S.AddBuiltinCandidate(&IntTy, Args, CandidateSet); |
8011 | } |
8012 | |
8013 | |
8014 | for (BuiltinCandidateTypeSet::iterator |
8015 | Vec = CandidateTypes[0].vector_begin(), |
8016 | VecEnd = CandidateTypes[0].vector_end(); |
8017 | Vec != VecEnd; ++Vec) { |
8018 | QualType VecTy = *Vec; |
8019 | S.AddBuiltinCandidate(&VecTy, Args, CandidateSet); |
8020 | } |
8021 | } |
8022 | |
8023 | |
8024 | |
8025 | |
8026 | |
8027 | |
8028 | |
8029 | void addEqualEqualOrNotEqualMemberPointerOrNullptrOverloads() { |
8030 | |
8031 | llvm::SmallPtrSet<QualType, 8> AddedTypes; |
8032 | |
8033 | for (unsigned ArgIdx = 0, N = Args.size(); ArgIdx != N; ++ArgIdx) { |
8034 | for (BuiltinCandidateTypeSet::iterator |
8035 | MemPtr = CandidateTypes[ArgIdx].member_pointer_begin(), |
8036 | MemPtrEnd = CandidateTypes[ArgIdx].member_pointer_end(); |
8037 | MemPtr != MemPtrEnd; |
8038 | ++MemPtr) { |
8039 | |
8040 | if (!AddedTypes.insert(S.Context.getCanonicalType(*MemPtr)).second) |
8041 | continue; |
8042 | |
8043 | QualType ParamTypes[2] = { *MemPtr, *MemPtr }; |
8044 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
8045 | } |
8046 | |
8047 | if (CandidateTypes[ArgIdx].hasNullPtrType()) { |
8048 | CanQualType NullPtrTy = S.Context.getCanonicalType(S.Context.NullPtrTy); |
8049 | if (AddedTypes.insert(NullPtrTy).second) { |
8050 | QualType ParamTypes[2] = { NullPtrTy, NullPtrTy }; |
8051 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
8052 | } |
8053 | } |
8054 | } |
8055 | } |
8056 | |
8057 | |
8058 | |
8059 | |
8060 | |
8061 | |
8062 | |
8063 | |
8064 | |
8065 | |
8066 | |
8067 | |
8068 | |
8069 | void addGenericBinaryPointerOrEnumeralOverloads() { |
8070 | |
8071 | |
8072 | |
8073 | |
8074 | |
8075 | |
8076 | |
8077 | |
8078 | |
8079 | |
8080 | |
8081 | |
8082 | llvm::DenseSet<std::pair<CanQualType, CanQualType> > |
8083 | UserDefinedBinaryOperators; |
8084 | |
8085 | for (unsigned ArgIdx = 0, N = Args.size(); ArgIdx != N; ++ArgIdx) { |
8086 | if (CandidateTypes[ArgIdx].enumeration_begin() != |
8087 | CandidateTypes[ArgIdx].enumeration_end()) { |
8088 | for (OverloadCandidateSet::iterator C = CandidateSet.begin(), |
8089 | CEnd = CandidateSet.end(); |
8090 | C != CEnd; ++C) { |
8091 | if (!C->Viable || !C->Function || C->Function->getNumParams() != 2) |
8092 | continue; |
8093 | |
8094 | if (C->Function->isFunctionTemplateSpecialization()) |
8095 | continue; |
8096 | |
8097 | QualType FirstParamType = |
8098 | C->Function->getParamDecl(0)->getType().getUnqualifiedType(); |
8099 | QualType SecondParamType = |
8100 | C->Function->getParamDecl(1)->getType().getUnqualifiedType(); |
8101 | |
8102 | |
8103 | if (!FirstParamType->isEnumeralType() || |
8104 | !SecondParamType->isEnumeralType()) |
8105 | continue; |
8106 | |
8107 | |
8108 | UserDefinedBinaryOperators.insert( |
8109 | std::make_pair(S.Context.getCanonicalType(FirstParamType), |
8110 | S.Context.getCanonicalType(SecondParamType))); |
8111 | } |
8112 | } |
8113 | } |
8114 | |
8115 | |
8116 | llvm::SmallPtrSet<QualType, 8> AddedTypes; |
8117 | |
8118 | for (unsigned ArgIdx = 0, N = Args.size(); ArgIdx != N; ++ArgIdx) { |
8119 | for (BuiltinCandidateTypeSet::iterator |
8120 | Ptr = CandidateTypes[ArgIdx].pointer_begin(), |
8121 | PtrEnd = CandidateTypes[ArgIdx].pointer_end(); |
8122 | Ptr != PtrEnd; ++Ptr) { |
8123 | |
8124 | if (!AddedTypes.insert(S.Context.getCanonicalType(*Ptr)).second) |
8125 | continue; |
8126 | |
8127 | QualType ParamTypes[2] = { *Ptr, *Ptr }; |
8128 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
8129 | } |
8130 | for (BuiltinCandidateTypeSet::iterator |
8131 | Enum = CandidateTypes[ArgIdx].enumeration_begin(), |
8132 | EnumEnd = CandidateTypes[ArgIdx].enumeration_end(); |
8133 | Enum != EnumEnd; ++Enum) { |
8134 | CanQualType CanonType = S.Context.getCanonicalType(*Enum); |
8135 | |
8136 | |
8137 | |
8138 | if (!AddedTypes.insert(CanonType).second || |
8139 | UserDefinedBinaryOperators.count(std::make_pair(CanonType, |
8140 | CanonType))) |
8141 | continue; |
8142 | QualType ParamTypes[2] = { *Enum, *Enum }; |
8143 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
8144 | } |
8145 | } |
8146 | } |
8147 | |
8148 | |
8149 | |
8150 | |
8151 | |
8152 | |
8153 | |
8154 | |
8155 | |
8156 | |
8157 | |
8158 | |
8159 | |
8160 | |
8161 | |
8162 | |
8163 | |
8164 | |
8165 | void addBinaryPlusOrMinusPointerOverloads(OverloadedOperatorKind Op) { |
8166 | |
8167 | llvm::SmallPtrSet<QualType, 8> AddedTypes; |
8168 | |
8169 | for (int Arg = 0; Arg < 2; ++Arg) { |
8170 | QualType AsymmetricParamTypes[2] = { |
8171 | S.Context.getPointerDiffType(), |
8172 | S.Context.getPointerDiffType(), |
8173 | }; |
8174 | for (BuiltinCandidateTypeSet::iterator |
8175 | Ptr = CandidateTypes[Arg].pointer_begin(), |
8176 | PtrEnd = CandidateTypes[Arg].pointer_end(); |
8177 | Ptr != PtrEnd; ++Ptr) { |
8178 | QualType PointeeTy = (*Ptr)->getPointeeType(); |
8179 | if (!PointeeTy->isObjectType()) |
8180 | continue; |
8181 | |
8182 | AsymmetricParamTypes[Arg] = *Ptr; |
8183 | if (Arg == 0 || Op == OO_Plus) { |
8184 | |
8185 | |
8186 | S.AddBuiltinCandidate(AsymmetricParamTypes, Args, CandidateSet); |
8187 | } |
8188 | if (Op == OO_Minus) { |
8189 | |
8190 | if (!AddedTypes.insert(S.Context.getCanonicalType(*Ptr)).second) |
8191 | continue; |
8192 | |
8193 | QualType ParamTypes[2] = { *Ptr, *Ptr }; |
8194 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
8195 | } |
8196 | } |
8197 | } |
8198 | } |
8199 | |
8200 | |
8201 | |
8202 | |
8203 | |
8204 | |
8205 | |
8206 | |
8207 | |
8208 | |
8209 | |
8210 | |
8211 | |
8212 | |
8213 | |
8214 | |
8215 | |
8216 | |
8217 | |
8218 | |
8219 | |
8220 | |
8221 | |
8222 | |
8223 | |
8224 | |
8225 | |
8226 | |
8227 | |
8228 | |
8229 | void addGenericBinaryArithmeticOverloads() { |
8230 | if (!HasArithmeticOrEnumeralCandidateType) |
8231 | return; |
8232 | |
8233 | for (unsigned Left = FirstPromotedArithmeticType; |
8234 | Left < LastPromotedArithmeticType; ++Left) { |
8235 | for (unsigned Right = FirstPromotedArithmeticType; |
8236 | Right < LastPromotedArithmeticType; ++Right) { |
8237 | QualType LandR[2] = { ArithmeticTypes[Left], |
8238 | ArithmeticTypes[Right] }; |
8239 | S.AddBuiltinCandidate(LandR, Args, CandidateSet); |
8240 | } |
8241 | } |
8242 | |
8243 | |
8244 | |
8245 | for (BuiltinCandidateTypeSet::iterator |
8246 | Vec1 = CandidateTypes[0].vector_begin(), |
8247 | Vec1End = CandidateTypes[0].vector_end(); |
8248 | Vec1 != Vec1End; ++Vec1) { |
8249 | for (BuiltinCandidateTypeSet::iterator |
8250 | Vec2 = CandidateTypes[1].vector_begin(), |
8251 | Vec2End = CandidateTypes[1].vector_end(); |
8252 | Vec2 != Vec2End; ++Vec2) { |
8253 | QualType LandR[2] = { *Vec1, *Vec2 }; |
8254 | S.AddBuiltinCandidate(LandR, Args, CandidateSet); |
8255 | } |
8256 | } |
8257 | } |
8258 | |
8259 | |
8260 | |
8261 | |
8262 | |
8263 | |
8264 | |
8265 | |
8266 | |
8267 | |
8268 | |
8269 | |
8270 | |
8271 | |
8272 | |
8273 | |
8274 | |
8275 | |
8276 | |
8277 | |
8278 | |
8279 | |
8280 | |
8281 | |
8282 | |
8283 | |
8284 | |
8285 | |
8286 | |
8287 | |
8288 | |
8289 | |
8290 | void addThreeWayArithmeticOverloads() { |
8291 | addGenericBinaryArithmeticOverloads(); |
8292 | } |
8293 | |
8294 | |
8295 | |
8296 | |
8297 | |
8298 | |
8299 | |
8300 | |
8301 | |
8302 | |
8303 | |
8304 | |
8305 | |
8306 | |
8307 | |
8308 | void addBinaryBitwiseArithmeticOverloads(OverloadedOperatorKind Op) { |
8309 | if (!HasArithmeticOrEnumeralCandidateType) |
8310 | return; |
8311 | |
8312 | for (unsigned Left = FirstPromotedIntegralType; |
8313 | Left < LastPromotedIntegralType; ++Left) { |
8314 | for (unsigned Right = FirstPromotedIntegralType; |
8315 | Right < LastPromotedIntegralType; ++Right) { |
8316 | QualType LandR[2] = { ArithmeticTypes[Left], |
8317 | ArithmeticTypes[Right] }; |
8318 | S.AddBuiltinCandidate(LandR, Args, CandidateSet); |
8319 | } |
8320 | } |
8321 | } |
8322 | |
8323 | |
8324 | |
8325 | |
8326 | |
8327 | |
8328 | |
8329 | |
8330 | void addAssignmentMemberPointerOrEnumeralOverloads() { |
8331 | |
8332 | llvm::SmallPtrSet<QualType, 8> AddedTypes; |
8333 | |
8334 | for (unsigned ArgIdx = 0; ArgIdx < 2; ++ArgIdx) { |
8335 | for (BuiltinCandidateTypeSet::iterator |
8336 | Enum = CandidateTypes[ArgIdx].enumeration_begin(), |
8337 | EnumEnd = CandidateTypes[ArgIdx].enumeration_end(); |
8338 | Enum != EnumEnd; ++Enum) { |
8339 | if (!AddedTypes.insert(S.Context.getCanonicalType(*Enum)).second) |
8340 | continue; |
8341 | |
8342 | AddBuiltinAssignmentOperatorCandidates(S, *Enum, Args, CandidateSet); |
8343 | } |
8344 | |
8345 | for (BuiltinCandidateTypeSet::iterator |
8346 | MemPtr = CandidateTypes[ArgIdx].member_pointer_begin(), |
8347 | MemPtrEnd = CandidateTypes[ArgIdx].member_pointer_end(); |
8348 | MemPtr != MemPtrEnd; ++MemPtr) { |
8349 | if (!AddedTypes.insert(S.Context.getCanonicalType(*MemPtr)).second) |
8350 | continue; |
8351 | |
8352 | AddBuiltinAssignmentOperatorCandidates(S, *MemPtr, Args, CandidateSet); |
8353 | } |
8354 | } |
8355 | } |
8356 | |
8357 | |
8358 | |
8359 | |
8360 | |
8361 | |
8362 | |
8363 | |
8364 | |
8365 | |
8366 | |
8367 | |
8368 | |
8369 | |
8370 | |
8371 | |
8372 | |
8373 | void addAssignmentPointerOverloads(bool isEqualOp) { |
8374 | |
8375 | llvm::SmallPtrSet<QualType, 8> AddedTypes; |
8376 | |
8377 | for (BuiltinCandidateTypeSet::iterator |
8378 | Ptr = CandidateTypes[0].pointer_begin(), |
8379 | PtrEnd = CandidateTypes[0].pointer_end(); |
8380 | Ptr != PtrEnd; ++Ptr) { |
8381 | |
8382 | if (isEqualOp) |
8383 | AddedTypes.insert(S.Context.getCanonicalType(*Ptr)); |
8384 | else if (!(*Ptr)->getPointeeType()->isObjectType()) |
8385 | continue; |
8386 | |
8387 | |
8388 | QualType ParamTypes[2] = { |
8389 | S.Context.getLValueReferenceType(*Ptr), |
8390 | isEqualOp ? *Ptr : S.Context.getPointerDiffType(), |
8391 | }; |
8392 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
8393 | isEqualOp); |
8394 | |
8395 | bool NeedVolatile = !(*Ptr).isVolatileQualified() && |
8396 | VisibleTypeConversionsQuals.hasVolatile(); |
8397 | if (NeedVolatile) { |
8398 | |
8399 | ParamTypes[0] = |
8400 | S.Context.getLValueReferenceType(S.Context.getVolatileType(*Ptr)); |
8401 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
8402 | isEqualOp); |
8403 | } |
8404 | |
8405 | if (!(*Ptr).isRestrictQualified() && |
8406 | VisibleTypeConversionsQuals.hasRestrict()) { |
8407 | |
8408 | ParamTypes[0] |
8409 | = S.Context.getLValueReferenceType(S.Context.getRestrictType(*Ptr)); |
8410 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
8411 | isEqualOp); |
8412 | |
8413 | if (NeedVolatile) { |
8414 | |
8415 | ParamTypes[0] |
8416 | = S.Context.getLValueReferenceType( |
8417 | S.Context.getCVRQualifiedType(*Ptr, |
8418 | (Qualifiers::Volatile | |
8419 | Qualifiers::Restrict))); |
8420 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
8421 | isEqualOp); |
8422 | } |
8423 | } |
8424 | } |
8425 | |
8426 | if (isEqualOp) { |
8427 | for (BuiltinCandidateTypeSet::iterator |
8428 | Ptr = CandidateTypes[1].pointer_begin(), |
8429 | PtrEnd = CandidateTypes[1].pointer_end(); |
8430 | Ptr != PtrEnd; ++Ptr) { |
8431 | |
8432 | if (!AddedTypes.insert(S.Context.getCanonicalType(*Ptr)).second) |
8433 | continue; |
8434 | |
8435 | QualType ParamTypes[2] = { |
8436 | S.Context.getLValueReferenceType(*Ptr), |
8437 | *Ptr, |
8438 | }; |
8439 | |
8440 | |
8441 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
8442 | ); |
8443 | |
8444 | bool NeedVolatile = !(*Ptr).isVolatileQualified() && |
8445 | VisibleTypeConversionsQuals.hasVolatile(); |
8446 | if (NeedVolatile) { |
8447 | |
8448 | ParamTypes[0] = |
8449 | S.Context.getLValueReferenceType(S.Context.getVolatileType(*Ptr)); |
8450 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
8451 | ); |
8452 | } |
8453 | |
8454 | if (!(*Ptr).isRestrictQualified() && |
8455 | VisibleTypeConversionsQuals.hasRestrict()) { |
8456 | |
8457 | ParamTypes[0] |
8458 | = S.Context.getLValueReferenceType(S.Context.getRestrictType(*Ptr)); |
8459 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
8460 | ); |
8461 | |
8462 | if (NeedVolatile) { |
8463 | |
8464 | ParamTypes[0] |
8465 | = S.Context.getLValueReferenceType( |
8466 | S.Context.getCVRQualifiedType(*Ptr, |
8467 | (Qualifiers::Volatile | |
8468 | Qualifiers::Restrict))); |
8469 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
8470 | ); |
8471 | } |
8472 | } |
8473 | } |
8474 | } |
8475 | } |
8476 | |
8477 | |
8478 | |
8479 | |
8480 | |
8481 | |
8482 | |
8483 | |
8484 | |
8485 | |
8486 | |
8487 | |
8488 | |
8489 | void addAssignmentArithmeticOverloads(bool isEqualOp) { |
8490 | if (!HasArithmeticOrEnumeralCandidateType) |
8491 | return; |
8492 | |
8493 | for (unsigned Left = 0; Left < NumArithmeticTypes; ++Left) { |
8494 | for (unsigned Right = FirstPromotedArithmeticType; |
8495 | Right < LastPromotedArithmeticType; ++Right) { |
8496 | QualType ParamTypes[2]; |
8497 | ParamTypes[1] = ArithmeticTypes[Right]; |
8498 | auto LeftBaseTy = AdjustAddressSpaceForBuiltinOperandType( |
8499 | S, ArithmeticTypes[Left], Args[0]); |
8500 | |
8501 | ParamTypes[0] = S.Context.getLValueReferenceType(LeftBaseTy); |
8502 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
8503 | isEqualOp); |
8504 | |
8505 | |
8506 | if (VisibleTypeConversionsQuals.hasVolatile()) { |
8507 | ParamTypes[0] = S.Context.getVolatileType(LeftBaseTy); |
8508 | ParamTypes[0] = S.Context.getLValueReferenceType(ParamTypes[0]); |
8509 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
8510 | isEqualOp); |
8511 | } |
8512 | } |
8513 | } |
8514 | |
8515 | |
8516 | for (BuiltinCandidateTypeSet::iterator |
8517 | Vec1 = CandidateTypes[0].vector_begin(), |
8518 | Vec1End = CandidateTypes[0].vector_end(); |
8519 | Vec1 != Vec1End; ++Vec1) { |
8520 | for (BuiltinCandidateTypeSet::iterator |
8521 | Vec2 = CandidateTypes[1].vector_begin(), |
8522 | Vec2End = CandidateTypes[1].vector_end(); |
8523 | Vec2 != Vec2End; ++Vec2) { |
8524 | QualType ParamTypes[2]; |
8525 | ParamTypes[1] = *Vec2; |
8526 | |
8527 | ParamTypes[0] = S.Context.getLValueReferenceType(*Vec1); |
8528 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
8529 | isEqualOp); |
8530 | |
8531 | |
8532 | if (VisibleTypeConversionsQuals.hasVolatile()) { |
8533 | ParamTypes[0] = S.Context.getVolatileType(*Vec1); |
8534 | ParamTypes[0] = S.Context.getLValueReferenceType(ParamTypes[0]); |
8535 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
8536 | isEqualOp); |
8537 | } |
8538 | } |
8539 | } |
8540 | } |
8541 | |
8542 | |
8543 | |
8544 | |
8545 | |
8546 | |
8547 | |
8548 | |
8549 | |
8550 | |
8551 | |
8552 | |
8553 | |
8554 | void addAssignmentIntegralOverloads() { |
8555 | if (!HasArithmeticOrEnumeralCandidateType) |
8556 | return; |
8557 | |
8558 | for (unsigned Left = FirstIntegralType; Left < LastIntegralType; ++Left) { |
8559 | for (unsigned Right = FirstPromotedIntegralType; |
8560 | Right < LastPromotedIntegralType; ++Right) { |
8561 | QualType ParamTypes[2]; |
8562 | ParamTypes[1] = ArithmeticTypes[Right]; |
8563 | auto LeftBaseTy = AdjustAddressSpaceForBuiltinOperandType( |
8564 | S, ArithmeticTypes[Left], Args[0]); |
8565 | |
8566 | ParamTypes[0] = S.Context.getLValueReferenceType(LeftBaseTy); |
8567 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
8568 | if (VisibleTypeConversionsQuals.hasVolatile()) { |
8569 | |
8570 | ParamTypes[0] = LeftBaseTy; |
8571 | ParamTypes[0] = S.Context.getVolatileType(ParamTypes[0]); |
8572 | ParamTypes[0] = S.Context.getLValueReferenceType(ParamTypes[0]); |
8573 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
8574 | } |
8575 | } |
8576 | } |
8577 | } |
8578 | |
8579 | |
8580 | |
8581 | |
8582 | |
8583 | |
8584 | |
8585 | |
8586 | void addExclaimOverload() { |
8587 | QualType ParamTy = S.Context.BoolTy; |
8588 | S.AddBuiltinCandidate(&ParamTy, Args, CandidateSet, |
8589 | , |
8590 | ); |
8591 | } |
8592 | void addAmpAmpOrPipePipeOverload() { |
8593 | QualType ParamTypes[2] = { S.Context.BoolTy, S.Context.BoolTy }; |
8594 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, |
8595 | , |
8596 | ); |
8597 | } |
8598 | |
8599 | |
8600 | |
8601 | |
8602 | |
8603 | |
8604 | |
8605 | |
8606 | |
8607 | |
8608 | |
8609 | void addSubscriptOverloads() { |
8610 | for (BuiltinCandidateTypeSet::iterator |
8611 | Ptr = CandidateTypes[0].pointer_begin(), |
8612 | PtrEnd = CandidateTypes[0].pointer_end(); |
8613 | Ptr != PtrEnd; ++Ptr) { |
8614 | QualType ParamTypes[2] = { *Ptr, S.Context.getPointerDiffType() }; |
8615 | QualType PointeeType = (*Ptr)->getPointeeType(); |
8616 | if (!PointeeType->isObjectType()) |
8617 | continue; |
8618 | |
8619 | |
8620 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
8621 | } |
8622 | |
8623 | for (BuiltinCandidateTypeSet::iterator |
8624 | Ptr = CandidateTypes[1].pointer_begin(), |
8625 | PtrEnd = CandidateTypes[1].pointer_end(); |
8626 | Ptr != PtrEnd; ++Ptr) { |
8627 | QualType ParamTypes[2] = { S.Context.getPointerDiffType(), *Ptr }; |
8628 | QualType PointeeType = (*Ptr)->getPointeeType(); |
8629 | if (!PointeeType->isObjectType()) |
8630 | continue; |
8631 | |
8632 | |
8633 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
8634 | } |
8635 | } |
8636 | |
8637 | |
8638 | |
8639 | |
8640 | |
8641 | |
8642 | |
8643 | |
8644 | |
8645 | |
8646 | void addArrowStarOverloads() { |
8647 | for (BuiltinCandidateTypeSet::iterator |
8648 | Ptr = CandidateTypes[0].pointer_begin(), |
8649 | PtrEnd = CandidateTypes[0].pointer_end(); |
8650 | Ptr != PtrEnd; ++Ptr) { |
8651 | QualType C1Ty = (*Ptr); |
8652 | QualType C1; |
8653 | QualifierCollector Q1; |
8654 | C1 = QualType(Q1.strip(C1Ty->getPointeeType()), 0); |
8655 | if (!isa<RecordType>(C1)) |
8656 | continue; |
8657 | |
8658 | |
8659 | |
8660 | if (!VisibleTypeConversionsQuals.hasVolatile() && Q1.hasVolatile()) |
8661 | continue; |
8662 | if (!VisibleTypeConversionsQuals.hasRestrict() && Q1.hasRestrict()) |
8663 | continue; |
8664 | for (BuiltinCandidateTypeSet::iterator |
8665 | MemPtr = CandidateTypes[1].member_pointer_begin(), |
8666 | MemPtrEnd = CandidateTypes[1].member_pointer_end(); |
8667 | MemPtr != MemPtrEnd; ++MemPtr) { |
8668 | const MemberPointerType *mptr = cast<MemberPointerType>(*MemPtr); |
8669 | QualType C2 = QualType(mptr->getClass(), 0); |
8670 | C2 = C2.getUnqualifiedType(); |
8671 | if (C1 != C2 && !S.IsDerivedFrom(CandidateSet.getLocation(), C1, C2)) |
8672 | break; |
8673 | QualType ParamTypes[2] = { *Ptr, *MemPtr }; |
8674 | |
8675 | QualType T = mptr->getPointeeType(); |
8676 | if (!VisibleTypeConversionsQuals.hasVolatile() && |
8677 | T.isVolatileQualified()) |
8678 | continue; |
8679 | if (!VisibleTypeConversionsQuals.hasRestrict() && |
8680 | T.isRestrictQualified()) |
8681 | continue; |
8682 | T = Q1.apply(S.Context, T); |
8683 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
8684 | } |
8685 | } |
8686 | } |
8687 | |
8688 | |
8689 | |
8690 | |
8691 | |
8692 | |
8693 | |
8694 | |
8695 | |
8696 | |
8697 | |
8698 | void addConditionalOperatorOverloads() { |
8699 | |
8700 | llvm::SmallPtrSet<QualType, 8> AddedTypes; |
8701 | |
8702 | for (unsigned ArgIdx = 0; ArgIdx < 2; ++ArgIdx) { |
8703 | for (BuiltinCandidateTypeSet::iterator |
8704 | Ptr = CandidateTypes[ArgIdx].pointer_begin(), |
8705 | PtrEnd = CandidateTypes[ArgIdx].pointer_end(); |
8706 | Ptr != PtrEnd; ++Ptr) { |
8707 | if (!AddedTypes.insert(S.Context.getCanonicalType(*Ptr)).second) |
8708 | continue; |
8709 | |
8710 | QualType ParamTypes[2] = { *Ptr, *Ptr }; |
8711 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
8712 | } |
8713 | |
8714 | for (BuiltinCandidateTypeSet::iterator |
8715 | MemPtr = CandidateTypes[ArgIdx].member_pointer_begin(), |
8716 | MemPtrEnd = CandidateTypes[ArgIdx].member_pointer_end(); |
8717 | MemPtr != MemPtrEnd; ++MemPtr) { |
8718 | if (!AddedTypes.insert(S.Context.getCanonicalType(*MemPtr)).second) |
8719 | continue; |
8720 | |
8721 | QualType ParamTypes[2] = { *MemPtr, *MemPtr }; |
8722 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
8723 | } |
8724 | |
8725 | if (S.getLangOpts().CPlusPlus11) { |
8726 | for (BuiltinCandidateTypeSet::iterator |
8727 | Enum = CandidateTypes[ArgIdx].enumeration_begin(), |
8728 | EnumEnd = CandidateTypes[ArgIdx].enumeration_end(); |
8729 | Enum != EnumEnd; ++Enum) { |
8730 | if (!(*Enum)->getAs<EnumType>()->getDecl()->isScoped()) |
8731 | continue; |
8732 | |
8733 | if (!AddedTypes.insert(S.Context.getCanonicalType(*Enum)).second) |
8734 | continue; |
8735 | |
8736 | QualType ParamTypes[2] = { *Enum, *Enum }; |
8737 | S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet); |
8738 | } |
8739 | } |
8740 | } |
8741 | } |
8742 | }; |
8743 | |
8744 | } |
8745 | |
8746 | |
8747 | |
8748 | |
8749 | |
8750 | |
8751 | void Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, |
8752 | SourceLocation OpLoc, |
8753 | ArrayRef<Expr *> Args, |
8754 | OverloadCandidateSet &CandidateSet) { |
8755 | |
8756 | |
8757 | |
8758 | |
8759 | Qualifiers VisibleTypeConversionsQuals; |
8760 | VisibleTypeConversionsQuals.addConst(); |
8761 | for (unsigned ArgIdx = 0, N = Args.size(); ArgIdx != N; ++ArgIdx) |
8762 | VisibleTypeConversionsQuals += CollectVRQualifiers(Context, Args[ArgIdx]); |
8763 | |
8764 | bool HasNonRecordCandidateType = false; |
8765 | bool HasArithmeticOrEnumeralCandidateType = false; |
8766 | SmallVector<BuiltinCandidateTypeSet, 2> CandidateTypes; |
8767 | for (unsigned ArgIdx = 0, N = Args.size(); ArgIdx != N; ++ArgIdx) { |
8768 | CandidateTypes.emplace_back(*this); |
8769 | CandidateTypes[ArgIdx].AddTypesConvertedFrom(Args[ArgIdx]->getType(), |
8770 | OpLoc, |
8771 | true, |
8772 | (Op == OO_Exclaim || |
8773 | Op == OO_AmpAmp || |
8774 | Op == OO_PipePipe), |
8775 | VisibleTypeConversionsQuals); |
8776 | HasNonRecordCandidateType = HasNonRecordCandidateType || |
8777 | CandidateTypes[ArgIdx].hasNonRecordTypes(); |
8778 | HasArithmeticOrEnumeralCandidateType = |
8779 | HasArithmeticOrEnumeralCandidateType || |
8780 | CandidateTypes[ArgIdx].hasArithmeticOrEnumeralTypes(); |
8781 | } |
8782 | |
8783 | |
8784 | |
8785 | |
8786 | |
8787 | |
8788 | if (!HasNonRecordCandidateType && |
8789 | !(Op == OO_Exclaim || Op == OO_AmpAmp || Op == OO_PipePipe)) |
8790 | return; |
8791 | |
8792 | |
8793 | BuiltinOperatorOverloadBuilder OpBuilder(*this, Args, |
8794 | VisibleTypeConversionsQuals, |
8795 | HasArithmeticOrEnumeralCandidateType, |
8796 | CandidateTypes, CandidateSet); |
8797 | |
8798 | |
8799 | switch (Op) { |
8800 | case OO_None: |
8801 | case NUM_OVERLOADED_OPERATORS: |
8802 | llvm_unreachable("Expected an overloaded operator"); |
8803 | |
8804 | case OO_New: |
8805 | case OO_Delete: |
8806 | case OO_Array_New: |
8807 | case OO_Array_Delete: |
8808 | case OO_Call: |
8809 | llvm_unreachable( |
8810 | "Special operators don't use AddBuiltinOperatorCandidates"); |
8811 | |
8812 | case OO_Comma: |
8813 | case OO_Arrow: |
8814 | case OO_Coawait: |
8815 | |
8816 | |
8817 | |
8818 | |
8819 | break; |
8820 | |
8821 | case OO_Plus: |
8822 | if (Args.size() == 1) |
8823 | OpBuilder.addUnaryPlusPointerOverloads(); |
8824 | LLVM_FALLTHROUGH; |
8825 | |
8826 | case OO_Minus: |
8827 | if (Args.size() == 1) { |
8828 | OpBuilder.addUnaryPlusOrMinusArithmeticOverloads(); |
8829 | } else { |
8830 | OpBuilder.addBinaryPlusOrMinusPointerOverloads(Op); |
8831 | OpBuilder.addGenericBinaryArithmeticOverloads(); |
8832 | } |
8833 | break; |
8834 | |
8835 | case OO_Star: |
8836 | if (Args.size() == 1) |
8837 | OpBuilder.addUnaryStarPointerOverloads(); |
8838 | else |
8839 | OpBuilder.addGenericBinaryArithmeticOverloads(); |
8840 | break; |
8841 | |
8842 | case OO_Slash: |
8843 | OpBuilder.addGenericBinaryArithmeticOverloads(); |
8844 | break; |
8845 | |
8846 | case OO_PlusPlus: |
8847 | case OO_MinusMinus: |
8848 | OpBuilder.addPlusPlusMinusMinusArithmeticOverloads(Op); |
8849 | OpBuilder.addPlusPlusMinusMinusPointerOverloads(); |
8850 | break; |
8851 | |
8852 | case OO_EqualEqual: |
8853 | case OO_ExclaimEqual: |
8854 | OpBuilder.addEqualEqualOrNotEqualMemberPointerOrNullptrOverloads(); |
8855 | LLVM_FALLTHROUGH; |
8856 | |
8857 | case OO_Less: |
8858 | case OO_Greater: |
8859 | case OO_LessEqual: |
8860 | case OO_GreaterEqual: |
8861 | OpBuilder.addGenericBinaryPointerOrEnumeralOverloads(); |
8862 | OpBuilder.addGenericBinaryArithmeticOverloads(); |
8863 | break; |
8864 | |
8865 | case OO_Spaceship: |
8866 | OpBuilder.addGenericBinaryPointerOrEnumeralOverloads(); |
8867 | OpBuilder.addThreeWayArithmeticOverloads(); |
8868 | break; |
8869 | |
8870 | case OO_Percent: |
8871 | case OO_Caret: |
8872 | case OO_Pipe: |
8873 | case OO_LessLess: |
8874 | case OO_GreaterGreater: |
8875 | OpBuilder.addBinaryBitwiseArithmeticOverloads(Op); |
8876 | break; |
8877 | |
8878 | case OO_Amp: |
8879 | if (Args.size() == 1) |
8880 | |
8881 | |
8882 | |
8883 | break; |
8884 | |
8885 | OpBuilder.addBinaryBitwiseArithmeticOverloads(Op); |
8886 | break; |
8887 | |
8888 | case OO_Tilde: |
8889 | OpBuilder.addUnaryTildePromotedIntegralOverloads(); |
8890 | break; |
8891 | |
8892 | case OO_Equal: |
8893 | OpBuilder.addAssignmentMemberPointerOrEnumeralOverloads(); |
8894 | LLVM_FALLTHROUGH; |
8895 | |
8896 | case OO_PlusEqual: |
8897 | case OO_MinusEqual: |
8898 | OpBuilder.addAssignmentPointerOverloads(Op == OO_Equal); |
8899 | LLVM_FALLTHROUGH; |
8900 | |
8901 | case OO_StarEqual: |
8902 | case OO_SlashEqual: |
8903 | OpBuilder.addAssignmentArithmeticOverloads(Op == OO_Equal); |
8904 | break; |
8905 | |
8906 | case OO_PercentEqual: |
8907 | case OO_LessLessEqual: |
8908 | case OO_GreaterGreaterEqual: |
8909 | case OO_AmpEqual: |
8910 | case OO_CaretEqual: |
8911 | case OO_PipeEqual: |
8912 | OpBuilder.addAssignmentIntegralOverloads(); |
8913 | break; |
8914 | |
8915 | case OO_Exclaim: |
8916 | OpBuilder.addExclaimOverload(); |
8917 | break; |
8918 | |
8919 | case OO_AmpAmp: |
8920 | case OO_PipePipe: |
8921 | OpBuilder.addAmpAmpOrPipePipeOverload(); |
8922 | break; |
8923 | |
8924 | case OO_Subscript: |
8925 | OpBuilder.addSubscriptOverloads(); |
8926 | break; |
8927 | |
8928 | case OO_ArrowStar: |
8929 | OpBuilder.addArrowStarOverloads(); |
8930 | break; |
8931 | |
8932 | case OO_Conditional: |
8933 | OpBuilder.addConditionalOperatorOverloads(); |
8934 | OpBuilder.addGenericBinaryArithmeticOverloads(); |
8935 | break; |
8936 | } |
8937 | } |
8938 | |
8939 | |
8940 | |
8941 | |
8942 | |
8943 | |
8944 | |
8945 | |
8946 | void |
8947 | Sema::AddArgumentDependentLookupCandidates(DeclarationName Name, |
8948 | SourceLocation Loc, |
8949 | ArrayRef<Expr *> Args, |
8950 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
8951 | OverloadCandidateSet& CandidateSet, |
8952 | bool PartialOverloading) { |
8953 | ADLResult Fns; |
8954 | |
8955 | |
8956 | |
8957 | |
8958 | |
8959 | |
8960 | |
8961 | |
8962 | |
8963 | ArgumentDependentLookup(Name, Loc, Args, Fns); |
8964 | |
8965 | |
8966 | for (OverloadCandidateSet::iterator Cand = CandidateSet.begin(), |
8967 | CandEnd = CandidateSet.end(); |
8968 | Cand != CandEnd; ++Cand) |
8969 | if (Cand->Function) { |
8970 | Fns.erase(Cand->Function); |
8971 | if (FunctionTemplateDecl *FunTmpl = Cand->Function->getPrimaryTemplate()) |
8972 | Fns.erase(FunTmpl); |
8973 | } |
8974 | |
8975 | |
8976 | |
8977 | for (ADLResult::iterator I = Fns.begin(), E = Fns.end(); I != E; ++I) { |
8978 | DeclAccessPair FoundDecl = DeclAccessPair::make(*I, AS_none); |
8979 | |
8980 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) { |
8981 | if (ExplicitTemplateArgs) |
8982 | continue; |
8983 | |
8984 | AddOverloadCandidate(FD, FoundDecl, Args, CandidateSet, |
8985 | , PartialOverloading, |
8986 | , ADLCallKind::UsesADL); |
8987 | } else { |
8988 | AddTemplateOverloadCandidate(cast<FunctionTemplateDecl>(*I), FoundDecl, |
8989 | ExplicitTemplateArgs, Args, CandidateSet, |
8990 | , |
8991 | PartialOverloading, ADLCallKind::UsesADL); |
8992 | } |
8993 | } |
8994 | } |
8995 | |
8996 | namespace { |
8997 | enum class Comparison { Equal, Better, Worse }; |
8998 | } |
8999 | |
9000 | |
9001 | |
9002 | |
9003 | |
9004 | |
9005 | |
9006 | |
9007 | |
9008 | |
9009 | |
9010 | |
9011 | static Comparison compareEnableIfAttrs(const Sema &S, const FunctionDecl *Cand1, |
9012 | const FunctionDecl *Cand2) { |
9013 | |
9014 | bool Cand1Attr = Cand1->hasAttr<EnableIfAttr>(); |
9015 | bool Cand2Attr = Cand2->hasAttr<EnableIfAttr>(); |
9016 | if (!Cand1Attr || !Cand2Attr) { |
9017 | if (Cand1Attr == Cand2Attr) |
9018 | return Comparison::Equal; |
9019 | return Cand1Attr ? Comparison::Better : Comparison::Worse; |
9020 | } |
9021 | |
9022 | auto Cand1Attrs = Cand1->specific_attrs<EnableIfAttr>(); |
9023 | auto Cand2Attrs = Cand2->specific_attrs<EnableIfAttr>(); |
9024 | |
9025 | llvm::FoldingSetNodeID Cand1ID, Cand2ID; |
9026 | for (auto Pair : zip_longest(Cand1Attrs, Cand2Attrs)) { |
9027 | Optional<EnableIfAttr *> Cand1A = std::get<0>(Pair); |
9028 | Optional<EnableIfAttr *> Cand2A = std::get<1>(Pair); |
9029 | |
9030 | |
9031 | |
9032 | if (!Cand1A) |
9033 | return Comparison::Worse; |
9034 | if (!Cand2A) |
9035 | return Comparison::Better; |
9036 | |
9037 | Cand1ID.clear(); |
9038 | Cand2ID.clear(); |
9039 | |
9040 | (*Cand1A)->getCond()->Profile(Cand1ID, S.getASTContext(), true); |
9041 | (*Cand2A)->getCond()->Profile(Cand2ID, S.getASTContext(), true); |
9042 | if (Cand1ID != Cand2ID) |
9043 | return Comparison::Worse; |
9044 | } |
9045 | |
9046 | return Comparison::Equal; |
9047 | } |
9048 | |
9049 | static bool isBetterMultiversionCandidate(const OverloadCandidate &Cand1, |
9050 | const OverloadCandidate &Cand2) { |
9051 | if (!Cand1.Function || !Cand1.Function->isMultiVersion() || !Cand2.Function || |
9052 | !Cand2.Function->isMultiVersion()) |
9053 | return false; |
9054 | |
9055 | |
9056 | |
9057 | if (Cand1.Function->isInvalidDecl()) return false; |
9058 | if (Cand2.Function->isInvalidDecl()) return true; |
9059 | |
9060 | |
9061 | |
9062 | bool Cand1CPUDisp = Cand1.Function->hasAttr<CPUDispatchAttr>(); |
9063 | bool Cand2CPUDisp = Cand2.Function->hasAttr<CPUDispatchAttr>(); |
9064 | const auto *Cand1CPUSpec = Cand1.Function->getAttr<CPUSpecificAttr>(); |
9065 | const auto *Cand2CPUSpec = Cand2.Function->getAttr<CPUSpecificAttr>(); |
9066 | |
9067 | if (!Cand1CPUDisp && !Cand2CPUDisp && !Cand1CPUSpec && !Cand2CPUSpec) |
9068 | return false; |
9069 | |
9070 | if (Cand1CPUDisp && !Cand2CPUDisp) |
9071 | return true; |
9072 | if (Cand2CPUDisp && !Cand1CPUDisp) |
9073 | return false; |
9074 | |
9075 | if (Cand1CPUSpec && Cand2CPUSpec) { |
9076 | if (Cand1CPUSpec->cpus_size() != Cand2CPUSpec->cpus_size()) |
9077 | return Cand1CPUSpec->cpus_size() < Cand2CPUSpec->cpus_size(); |
9078 | |
9079 | std::pair<CPUSpecificAttr::cpus_iterator, CPUSpecificAttr::cpus_iterator> |
9080 | FirstDiff = std::mismatch( |
9081 | Cand1CPUSpec->cpus_begin(), Cand1CPUSpec->cpus_end(), |
9082 | Cand2CPUSpec->cpus_begin(), |
9083 | [](const IdentifierInfo *LHS, const IdentifierInfo *RHS) { |
9084 | return LHS->getName() == RHS->getName(); |
9085 | }); |
9086 | |
9087 | (0) . __assert_fail ("FirstDiff.first != Cand1CPUSpec->cpus_end() && \"Two different cpu-specific versions should not have the same \" \"identifier list, otherwise they'd be the same decl!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9089, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(FirstDiff.first != Cand1CPUSpec->cpus_end() && |
9088 | (0) . __assert_fail ("FirstDiff.first != Cand1CPUSpec->cpus_end() && \"Two different cpu-specific versions should not have the same \" \"identifier list, otherwise they'd be the same decl!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9089, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Two different cpu-specific versions should not have the same " |
9089 | (0) . __assert_fail ("FirstDiff.first != Cand1CPUSpec->cpus_end() && \"Two different cpu-specific versions should not have the same \" \"identifier list, otherwise they'd be the same decl!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9089, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "identifier list, otherwise they'd be the same decl!"); |
9090 | return (*FirstDiff.first)->getName() < (*FirstDiff.second)->getName(); |
9091 | } |
9092 | llvm_unreachable("No way to get here unless both had cpu_dispatch"); |
9093 | } |
9094 | |
9095 | |
9096 | |
9097 | bool clang::isBetterOverloadCandidate( |
9098 | Sema &S, const OverloadCandidate &Cand1, const OverloadCandidate &Cand2, |
9099 | SourceLocation Loc, OverloadCandidateSet::CandidateSetKind Kind) { |
9100 | |
9101 | |
9102 | if (!Cand2.Viable) |
9103 | return Cand1.Viable; |
9104 | else if (!Cand1.Viable) |
9105 | return false; |
9106 | |
9107 | |
9108 | |
9109 | |
9110 | |
9111 | |
9112 | |
9113 | unsigned StartArg = 0; |
9114 | if (Cand1.IgnoreObjectArgument || Cand2.IgnoreObjectArgument) |
9115 | StartArg = 1; |
9116 | |
9117 | auto IsIllFormedConversion = [&](const ImplicitConversionSequence &ICS) { |
9118 | |
9119 | if (!S.getLangOpts().CPlusPlus) |
9120 | return ICS.isStandard() && |
9121 | ICS.Standard.Second == ICK_Incompatible_Pointer_Conversion; |
9122 | |
9123 | |
9124 | |
9125 | return S.getLangOpts().CPlusPlus11 && !S.getLangOpts().WritableStrings && |
9126 | hasDeprecatedStringLiteralToCharPtrConversion(ICS); |
9127 | }; |
9128 | |
9129 | |
9130 | |
9131 | unsigned NumArgs = Cand1.Conversions.size(); |
9132 | (0) . __assert_fail ("Cand2.Conversions.size() == NumArgs && \"Overload candidate mismatch\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9132, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Cand2.Conversions.size() == NumArgs && "Overload candidate mismatch"); |
9133 | bool HasBetterConversion = false; |
9134 | for (unsigned ArgIdx = StartArg; ArgIdx < NumArgs; ++ArgIdx) { |
9135 | bool Cand1Bad = IsIllFormedConversion(Cand1.Conversions[ArgIdx]); |
9136 | bool Cand2Bad = IsIllFormedConversion(Cand2.Conversions[ArgIdx]); |
9137 | if (Cand1Bad != Cand2Bad) { |
9138 | if (Cand1Bad) |
9139 | return false; |
9140 | HasBetterConversion = true; |
9141 | } |
9142 | } |
9143 | |
9144 | if (HasBetterConversion) |
9145 | return true; |
9146 | |
9147 | |
9148 | |
9149 | |
9150 | |
9151 | for (unsigned ArgIdx = StartArg; ArgIdx < NumArgs; ++ArgIdx) { |
9152 | switch (CompareImplicitConversionSequences(S, Loc, |
9153 | Cand1.Conversions[ArgIdx], |
9154 | Cand2.Conversions[ArgIdx])) { |
9155 | case ImplicitConversionSequence::Better: |
9156 | |
9157 | HasBetterConversion = true; |
9158 | break; |
9159 | |
9160 | case ImplicitConversionSequence::Worse: |
9161 | |
9162 | return false; |
9163 | |
9164 | case ImplicitConversionSequence::Indistinguishable: |
9165 | |
9166 | break; |
9167 | } |
9168 | } |
9169 | |
9170 | |
9171 | |
9172 | if (HasBetterConversion) |
9173 | return true; |
9174 | |
9175 | |
9176 | |
9177 | |
9178 | |
9179 | |
9180 | |
9181 | if (Kind == OverloadCandidateSet::CSK_InitByUserDefinedConversion && |
9182 | Cand1.Function && Cand2.Function && |
9183 | isa<CXXConversionDecl>(Cand1.Function) && |
9184 | isa<CXXConversionDecl>(Cand2.Function)) { |
9185 | |
9186 | |
9187 | |
9188 | |
9189 | ImplicitConversionSequence::CompareKind Result = |
9190 | compareConversionFunctions(S, Cand1.Function, Cand2.Function); |
9191 | if (Result == ImplicitConversionSequence::Indistinguishable) |
9192 | Result = CompareStandardConversionSequences(S, Loc, |
9193 | Cand1.FinalConversion, |
9194 | Cand2.FinalConversion); |
9195 | |
9196 | if (Result != ImplicitConversionSequence::Indistinguishable) |
9197 | return Result == ImplicitConversionSequence::Better; |
9198 | |
9199 | |
9200 | |
9201 | |
9202 | } |
9203 | |
9204 | |
9205 | |
9206 | |
9207 | |
9208 | |
9209 | |
9210 | if (Kind == OverloadCandidateSet::CSK_InitByConstructor && NumArgs == 1 && |
9211 | Cand1.Function && Cand2.Function && |
9212 | isa<CXXConstructorDecl>(Cand1.Function) != |
9213 | isa<CXXConstructorDecl>(Cand2.Function)) |
9214 | return isa<CXXConstructorDecl>(Cand1.Function); |
9215 | |
9216 | |
9217 | |
9218 | bool Cand1IsSpecialization = Cand1.Function && |
9219 | Cand1.Function->getPrimaryTemplate(); |
9220 | bool Cand2IsSpecialization = Cand2.Function && |
9221 | Cand2.Function->getPrimaryTemplate(); |
9222 | if (Cand1IsSpecialization != Cand2IsSpecialization) |
9223 | return Cand2IsSpecialization; |
9224 | |
9225 | |
9226 | |
9227 | |
9228 | |
9229 | if (Cand1IsSpecialization && Cand2IsSpecialization) { |
9230 | if (FunctionTemplateDecl *BetterTemplate |
9231 | = S.getMoreSpecializedTemplate(Cand1.Function->getPrimaryTemplate(), |
9232 | Cand2.Function->getPrimaryTemplate(), |
9233 | Loc, |
9234 | isa<CXXConversionDecl>(Cand1.Function)? TPOC_Conversion |
9235 | : TPOC_Call, |
9236 | Cand1.ExplicitCallArguments, |
9237 | Cand2.ExplicitCallArguments)) |
9238 | return BetterTemplate == Cand1.Function->getPrimaryTemplate(); |
9239 | } |
9240 | |
9241 | |
9242 | |
9243 | bool Cand1IsInherited = |
9244 | dyn_cast_or_null<ConstructorUsingShadowDecl>(Cand1.FoundDecl.getDecl()); |
9245 | bool Cand2IsInherited = |
9246 | dyn_cast_or_null<ConstructorUsingShadowDecl>(Cand2.FoundDecl.getDecl()); |
9247 | if (Cand1IsInherited != Cand2IsInherited) |
9248 | return Cand2IsInherited; |
9249 | else if (Cand1IsInherited) { |
9250 | assert(Cand2IsInherited); |
9251 | auto *Cand1Class = cast<CXXRecordDecl>(Cand1.Function->getDeclContext()); |
9252 | auto *Cand2Class = cast<CXXRecordDecl>(Cand2.Function->getDeclContext()); |
9253 | if (Cand1Class->isDerivedFrom(Cand2Class)) |
9254 | return true; |
9255 | if (Cand2Class->isDerivedFrom(Cand1Class)) |
9256 | return false; |
9257 | |
9258 | } |
9259 | |
9260 | |
9261 | { |
9262 | auto *Guide1 = dyn_cast_or_null<CXXDeductionGuideDecl>(Cand1.Function); |
9263 | auto *Guide2 = dyn_cast_or_null<CXXDeductionGuideDecl>(Cand2.Function); |
9264 | if (Guide1 && Guide2) { |
9265 | |
9266 | if (Guide1->isImplicit() != Guide2->isImplicit()) |
9267 | return Guide2->isImplicit(); |
9268 | |
9269 | |
9270 | if (Guide1->isCopyDeductionCandidate()) |
9271 | return true; |
9272 | } |
9273 | } |
9274 | |
9275 | |
9276 | if (Cand1.Function && Cand2.Function) { |
9277 | Comparison Cmp = compareEnableIfAttrs(S, Cand1.Function, Cand2.Function); |
9278 | if (Cmp != Comparison::Equal) |
9279 | return Cmp == Comparison::Better; |
9280 | } |
9281 | |
9282 | if (S.getLangOpts().CUDA && Cand1.Function && Cand2.Function) { |
9283 | FunctionDecl *Caller = dyn_cast<FunctionDecl>(S.CurContext); |
9284 | return S.IdentifyCUDAPreference(Caller, Cand1.Function) > |
9285 | S.IdentifyCUDAPreference(Caller, Cand2.Function); |
9286 | } |
9287 | |
9288 | bool HasPS1 = Cand1.Function != nullptr && |
9289 | functionHasPassObjectSizeParams(Cand1.Function); |
9290 | bool HasPS2 = Cand2.Function != nullptr && |
9291 | functionHasPassObjectSizeParams(Cand2.Function); |
9292 | if (HasPS1 != HasPS2 && HasPS1) |
9293 | return true; |
9294 | |
9295 | return isBetterMultiversionCandidate(Cand1, Cand2); |
9296 | } |
9297 | |
9298 | |
9299 | |
9300 | |
9301 | |
9302 | |
9303 | |
9304 | |
9305 | bool Sema::isEquivalentInternalLinkageDeclaration(const NamedDecl *A, |
9306 | const NamedDecl *B) { |
9307 | auto *VA = dyn_cast_or_null<ValueDecl>(A); |
9308 | auto *VB = dyn_cast_or_null<ValueDecl>(B); |
9309 | if (!VA || !VB) |
9310 | return false; |
9311 | |
9312 | |
9313 | |
9314 | if (!VA->getDeclContext()->getRedeclContext()->Equals( |
9315 | VB->getDeclContext()->getRedeclContext()) || |
9316 | getOwningModule(const_cast<ValueDecl *>(VA)) == |
9317 | getOwningModule(const_cast<ValueDecl *>(VB)) || |
9318 | VA->isExternallyVisible() || VB->isExternallyVisible()) |
9319 | return false; |
9320 | |
9321 | |
9322 | |
9323 | |
9324 | |
9325 | |
9326 | if (Context.hasSameType(VA->getType(), VB->getType())) |
9327 | return true; |
9328 | |
9329 | |
9330 | |
9331 | if (auto *EA = dyn_cast<EnumConstantDecl>(VA)) { |
9332 | if (auto *EB = dyn_cast<EnumConstantDecl>(VB)) { |
9333 | |
9334 | |
9335 | auto *EnumA = cast<EnumDecl>(EA->getDeclContext()); |
9336 | auto *EnumB = cast<EnumDecl>(EB->getDeclContext()); |
9337 | if (EnumA->hasNameForLinkage() || EnumB->hasNameForLinkage() || |
9338 | !Context.hasSameType(EnumA->getIntegerType(), |
9339 | EnumB->getIntegerType())) |
9340 | return false; |
9341 | |
9342 | return llvm::APSInt::isSameValue(EA->getInitVal(), EB->getInitVal()); |
9343 | } |
9344 | } |
9345 | |
9346 | |
9347 | return false; |
9348 | } |
9349 | |
9350 | void Sema::diagnoseEquivalentInternalLinkageDeclarations( |
9351 | SourceLocation Loc, const NamedDecl *D, ArrayRef<const NamedDecl *> Equiv) { |
9352 | Diag(Loc, diag::ext_equivalent_internal_linkage_decl_in_modules) << D; |
9353 | |
9354 | Module *M = getOwningModule(const_cast<NamedDecl*>(D)); |
9355 | Diag(D->getLocation(), diag::note_equivalent_internal_linkage_decl) |
9356 | << !M << (M ? M->getFullModuleName() : ""); |
9357 | |
9358 | for (auto *E : Equiv) { |
9359 | Module *M = getOwningModule(const_cast<NamedDecl*>(E)); |
9360 | Diag(E->getLocation(), diag::note_equivalent_internal_linkage_decl) |
9361 | << !M << (M ? M->getFullModuleName() : ""); |
9362 | } |
9363 | } |
9364 | |
9365 | |
9366 | |
9367 | |
9368 | |
9369 | |
9370 | |
9371 | |
9372 | |
9373 | |
9374 | |
9375 | OverloadingResult |
9376 | OverloadCandidateSet::BestViableFunction(Sema &S, SourceLocation Loc, |
9377 | iterator &Best) { |
9378 | llvm::SmallVector<OverloadCandidate *, 16> Candidates; |
9379 | std::transform(begin(), end(), std::back_inserter(Candidates), |
9380 | [](OverloadCandidate &Cand) { return &Cand; }); |
9381 | |
9382 | |
9383 | |
9384 | |
9385 | |
9386 | |
9387 | |
9388 | |
9389 | if (S.getLangOpts().CUDA) { |
9390 | const FunctionDecl *Caller = dyn_cast<FunctionDecl>(S.CurContext); |
9391 | bool ContainsSameSideCandidate = |
9392 | llvm::any_of(Candidates, [&](OverloadCandidate *Cand) { |
9393 | return Cand->Function && |
9394 | S.IdentifyCUDAPreference(Caller, Cand->Function) == |
9395 | Sema::CFP_SameSide; |
9396 | }); |
9397 | if (ContainsSameSideCandidate) { |
9398 | auto IsWrongSideCandidate = [&](OverloadCandidate *Cand) { |
9399 | return Cand->Function && |
9400 | S.IdentifyCUDAPreference(Caller, Cand->Function) == |
9401 | Sema::CFP_WrongSide; |
9402 | }; |
9403 | llvm::erase_if(Candidates, IsWrongSideCandidate); |
9404 | } |
9405 | } |
9406 | |
9407 | |
9408 | Best = end(); |
9409 | for (auto *Cand : Candidates) |
9410 | if (Cand->Viable) |
9411 | if (Best == end() || |
9412 | isBetterOverloadCandidate(S, *Cand, *Best, Loc, Kind)) |
9413 | Best = Cand; |
9414 | |
9415 | |
9416 | if (Best == end()) |
9417 | return OR_No_Viable_Function; |
9418 | |
9419 | llvm::SmallVector<const NamedDecl *, 4> EquivalentCands; |
9420 | |
9421 | |
9422 | |
9423 | for (auto *Cand : Candidates) { |
9424 | if (Cand->Viable && Cand != Best && |
9425 | !isBetterOverloadCandidate(S, *Best, *Cand, Loc, Kind)) { |
9426 | if (S.isEquivalentInternalLinkageDeclaration(Best->Function, |
9427 | Cand->Function)) { |
9428 | EquivalentCands.push_back(Cand->Function); |
9429 | continue; |
9430 | } |
9431 | |
9432 | Best = end(); |
9433 | return OR_Ambiguous; |
9434 | } |
9435 | } |
9436 | |
9437 | |
9438 | if (Best->Function && Best->Function->isDeleted()) |
9439 | return OR_Deleted; |
9440 | |
9441 | if (!EquivalentCands.empty()) |
9442 | S.diagnoseEquivalentInternalLinkageDeclarations(Loc, Best->Function, |
9443 | EquivalentCands); |
9444 | |
9445 | return OR_Success; |
9446 | } |
9447 | |
9448 | namespace { |
9449 | |
9450 | enum OverloadCandidateKind { |
9451 | oc_function, |
9452 | oc_method, |
9453 | oc_constructor, |
9454 | oc_implicit_default_constructor, |
9455 | oc_implicit_copy_constructor, |
9456 | oc_implicit_move_constructor, |
9457 | oc_implicit_copy_assignment, |
9458 | oc_implicit_move_assignment, |
9459 | oc_inherited_constructor |
9460 | }; |
9461 | |
9462 | enum OverloadCandidateSelect { |
9463 | ocs_non_template, |
9464 | ocs_template, |
9465 | ocs_described_template, |
9466 | }; |
9467 | |
9468 | static std::pair<OverloadCandidateKind, OverloadCandidateSelect> |
9469 | ClassifyOverloadCandidate(Sema &S, NamedDecl *Found, FunctionDecl *Fn, |
9470 | std::string &Description) { |
9471 | |
9472 | bool isTemplate = Fn->isTemplateDecl() || Found->isTemplateDecl(); |
9473 | if (FunctionTemplateDecl *FunTmpl = Fn->getPrimaryTemplate()) { |
9474 | isTemplate = true; |
9475 | Description = S.getTemplateArgumentBindingsText( |
9476 | FunTmpl->getTemplateParameters(), *Fn->getTemplateSpecializationArgs()); |
9477 | } |
9478 | |
9479 | OverloadCandidateSelect Select = [&]() { |
9480 | if (!Description.empty()) |
9481 | return ocs_described_template; |
9482 | return isTemplate ? ocs_template : ocs_non_template; |
9483 | }(); |
9484 | |
9485 | OverloadCandidateKind Kind = [&]() { |
9486 | if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(Fn)) { |
9487 | if (!Ctor->isImplicit()) { |
9488 | if (isa<ConstructorUsingShadowDecl>(Found)) |
9489 | return oc_inherited_constructor; |
9490 | else |
9491 | return oc_constructor; |
9492 | } |
9493 | |
9494 | if (Ctor->isDefaultConstructor()) |
9495 | return oc_implicit_default_constructor; |
9496 | |
9497 | if (Ctor->isMoveConstructor()) |
9498 | return oc_implicit_move_constructor; |
9499 | |
9500 | (0) . __assert_fail ("Ctor->isCopyConstructor() && \"unexpected sort of implicit constructor\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9501, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Ctor->isCopyConstructor() && |
9501 | (0) . __assert_fail ("Ctor->isCopyConstructor() && \"unexpected sort of implicit constructor\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9501, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "unexpected sort of implicit constructor"); |
9502 | return oc_implicit_copy_constructor; |
9503 | } |
9504 | |
9505 | if (CXXMethodDecl *Meth = dyn_cast<CXXMethodDecl>(Fn)) { |
9506 | |
9507 | |
9508 | if (!Meth->isImplicit()) |
9509 | return oc_method; |
9510 | |
9511 | if (Meth->isMoveAssignmentOperator()) |
9512 | return oc_implicit_move_assignment; |
9513 | |
9514 | if (Meth->isCopyAssignmentOperator()) |
9515 | return oc_implicit_copy_assignment; |
9516 | |
9517 | (0) . __assert_fail ("isa(Meth) && \"expected conversion\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9517, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<CXXConversionDecl>(Meth) && "expected conversion"); |
9518 | return oc_method; |
9519 | } |
9520 | |
9521 | return oc_function; |
9522 | }(); |
9523 | |
9524 | return std::make_pair(Kind, Select); |
9525 | } |
9526 | |
9527 | void MaybeEmitInheritedConstructorNote(Sema &S, Decl *FoundDecl) { |
9528 | |
9529 | |
9530 | if (auto *Shadow = dyn_cast<ConstructorUsingShadowDecl>(FoundDecl)) |
9531 | S.Diag(FoundDecl->getLocation(), |
9532 | diag::note_ovl_candidate_inherited_constructor) |
9533 | << Shadow->getNominatedBaseClass(); |
9534 | } |
9535 | |
9536 | } |
9537 | |
9538 | static bool isFunctionAlwaysEnabled(const ASTContext &Ctx, |
9539 | const FunctionDecl *FD) { |
9540 | for (auto *EnableIf : FD->specific_attrs<EnableIfAttr>()) { |
9541 | bool AlwaysTrue; |
9542 | if (!EnableIf->getCond()->EvaluateAsBooleanCondition(AlwaysTrue, Ctx)) |
9543 | return false; |
9544 | if (!AlwaysTrue) |
9545 | return false; |
9546 | } |
9547 | return true; |
9548 | } |
9549 | |
9550 | |
9551 | |
9552 | |
9553 | |
9554 | |
9555 | |
9556 | |
9557 | static bool checkAddressOfFunctionIsAvailable(Sema &S, const FunctionDecl *FD, |
9558 | bool Complain, |
9559 | bool InOverloadResolution, |
9560 | SourceLocation Loc) { |
9561 | if (!isFunctionAlwaysEnabled(S.Context, FD)) { |
9562 | if (Complain) { |
9563 | if (InOverloadResolution) |
9564 | S.Diag(FD->getBeginLoc(), |
9565 | diag::note_addrof_ovl_candidate_disabled_by_enable_if_attr); |
9566 | else |
9567 | S.Diag(Loc, diag::err_addrof_function_disabled_by_enable_if_attr) << FD; |
9568 | } |
9569 | return false; |
9570 | } |
9571 | |
9572 | auto I = llvm::find_if(FD->parameters(), [](const ParmVarDecl *P) { |
9573 | return P->hasAttr<PassObjectSizeAttr>(); |
9574 | }); |
9575 | if (I == FD->param_end()) |
9576 | return true; |
9577 | |
9578 | if (Complain) { |
9579 | |
9580 | unsigned ParamNo = std::distance(FD->param_begin(), I) + 1; |
9581 | if (InOverloadResolution) |
9582 | S.Diag(FD->getLocation(), |
9583 | diag::note_ovl_candidate_has_pass_object_size_params) |
9584 | << ParamNo; |
9585 | else |
9586 | S.Diag(Loc, diag::err_address_of_function_with_pass_object_size_params) |
9587 | << FD << ParamNo; |
9588 | } |
9589 | return false; |
9590 | } |
9591 | |
9592 | static bool checkAddressOfCandidateIsAvailable(Sema &S, |
9593 | const FunctionDecl *FD) { |
9594 | return checkAddressOfFunctionIsAvailable(S, FD, , |
9595 | , |
9596 | ()); |
9597 | } |
9598 | |
9599 | bool Sema::checkAddressOfFunctionIsAvailable(const FunctionDecl *Function, |
9600 | bool Complain, |
9601 | SourceLocation Loc) { |
9602 | return ::checkAddressOfFunctionIsAvailable(*this, Function, Complain, |
9603 | , |
9604 | Loc); |
9605 | } |
9606 | |
9607 | |
9608 | void Sema::NoteOverloadCandidate(NamedDecl *Found, FunctionDecl *Fn, |
9609 | QualType DestType, bool TakingAddress) { |
9610 | if (TakingAddress && !checkAddressOfCandidateIsAvailable(*this, Fn)) |
9611 | return; |
9612 | if (Fn->isMultiVersion() && Fn->hasAttr<TargetAttr>() && |
9613 | !Fn->getAttr<TargetAttr>()->isDefaultVersion()) |
9614 | return; |
9615 | |
9616 | std::string FnDesc; |
9617 | std::pair<OverloadCandidateKind, OverloadCandidateSelect> KSPair = |
9618 | ClassifyOverloadCandidate(*this, Found, Fn, FnDesc); |
9619 | PartialDiagnostic PD = PDiag(diag::note_ovl_candidate) |
9620 | << (unsigned)KSPair.first << (unsigned)KSPair.second |
9621 | << Fn << FnDesc; |
9622 | |
9623 | HandleFunctionTypeMismatch(PD, Fn->getType(), DestType); |
9624 | Diag(Fn->getLocation(), PD); |
9625 | MaybeEmitInheritedConstructorNote(*this, Found); |
9626 | } |
9627 | |
9628 | |
9629 | |
9630 | void Sema::NoteAllOverloadCandidates(Expr *OverloadedExpr, QualType DestType, |
9631 | bool TakingAddress) { |
9632 | getType() == Context.OverloadTy", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9632, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(OverloadedExpr->getType() == Context.OverloadTy); |
9633 | |
9634 | OverloadExpr::FindResult Ovl = OverloadExpr::find(OverloadedExpr); |
9635 | OverloadExpr *OvlExpr = Ovl.Expression; |
9636 | |
9637 | for (UnresolvedSetIterator I = OvlExpr->decls_begin(), |
9638 | IEnd = OvlExpr->decls_end(); |
9639 | I != IEnd; ++I) { |
9640 | if (FunctionTemplateDecl *FunTmpl = |
9641 | dyn_cast<FunctionTemplateDecl>((*I)->getUnderlyingDecl()) ) { |
9642 | NoteOverloadCandidate(*I, FunTmpl->getTemplatedDecl(), DestType, |
9643 | TakingAddress); |
9644 | } else if (FunctionDecl *Fun |
9645 | = dyn_cast<FunctionDecl>((*I)->getUnderlyingDecl()) ) { |
9646 | NoteOverloadCandidate(*I, Fun, DestType, TakingAddress); |
9647 | } |
9648 | } |
9649 | } |
9650 | |
9651 | |
9652 | |
9653 | |
9654 | void ImplicitConversionSequence::DiagnoseAmbiguousConversion( |
9655 | Sema &S, |
9656 | SourceLocation CaretLoc, |
9657 | const PartialDiagnostic &PDiag) const { |
9658 | S.Diag(CaretLoc, PDiag) |
9659 | << Ambiguous.getFromType() << Ambiguous.getToType(); |
9660 | |
9661 | |
9662 | |
9663 | const OverloadsShown ShowOverloads = S.Diags.getShowOverloads(); |
9664 | unsigned CandsShown = 0; |
9665 | AmbiguousConversionSequence::const_iterator I, E; |
9666 | for (I = Ambiguous.begin(), E = Ambiguous.end(); I != E; ++I) { |
9667 | if (CandsShown >= 4 && ShowOverloads == Ovl_Best) |
9668 | break; |
9669 | ++CandsShown; |
9670 | S.NoteOverloadCandidate(I->first, I->second); |
9671 | } |
9672 | if (I != E) |
9673 | S.Diag(SourceLocation(), diag::note_ovl_too_many_candidates) << int(E - I); |
9674 | } |
9675 | |
9676 | static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand, |
9677 | unsigned I, bool TakingCandidateAddress) { |
9678 | const ImplicitConversionSequence &Conv = Cand->Conversions[I]; |
9679 | assert(Conv.isBad()); |
9680 | (0) . __assert_fail ("Cand->Function && \"for now, candidate must be a function\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9680, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Cand->Function && "for now, candidate must be a function"); |
9681 | FunctionDecl *Fn = Cand->Function; |
9682 | |
9683 | |
9684 | |
9685 | |
9686 | bool isObjectArgument = false; |
9687 | if (isa<CXXMethodDecl>(Fn) && !isa<CXXConstructorDecl>(Fn)) { |
9688 | if (I == 0) |
9689 | isObjectArgument = true; |
9690 | else |
9691 | I--; |
9692 | } |
9693 | |
9694 | std::string FnDesc; |
9695 | std::pair<OverloadCandidateKind, OverloadCandidateSelect> FnKindPair = |
9696 | ClassifyOverloadCandidate(S, Cand->FoundDecl, Fn, FnDesc); |
9697 | |
9698 | Expr *FromExpr = Conv.Bad.FromExpr; |
9699 | QualType FromTy = Conv.Bad.getFromType(); |
9700 | QualType ToTy = Conv.Bad.getToType(); |
9701 | |
9702 | if (FromTy == S.Context.OverloadTy) { |
9703 | (0) . __assert_fail ("FromExpr && \"overload set argument came from implicit argument?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9703, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(FromExpr && "overload set argument came from implicit argument?"); |
9704 | Expr *E = FromExpr->IgnoreParens(); |
9705 | if (isa<UnaryOperator>(E)) |
9706 | E = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens(); |
9707 | DeclarationName Name = cast<OverloadExpr>(E)->getName(); |
9708 | |
9709 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_overload) |
9710 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc |
9711 | << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << ToTy |
9712 | << Name << I + 1; |
9713 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
9714 | return; |
9715 | } |
9716 | |
9717 | |
9718 | |
9719 | CanQualType CFromTy = S.Context.getCanonicalType(FromTy); |
9720 | CanQualType CToTy = S.Context.getCanonicalType(ToTy); |
9721 | if (CanQual<ReferenceType> RT = CToTy->getAs<ReferenceType>()) |
9722 | CToTy = RT->getPointeeType(); |
9723 | else { |
9724 | |
9725 | if (CanQual<PointerType> FromPT = CFromTy->getAs<PointerType>()) |
9726 | if (CanQual<PointerType> ToPT = CToTy->getAs<PointerType>()) { |
9727 | CFromTy = FromPT->getPointeeType(); |
9728 | CToTy = ToPT->getPointeeType(); |
9729 | } |
9730 | } |
9731 | |
9732 | if (CToTy.getUnqualifiedType() == CFromTy.getUnqualifiedType() && |
9733 | !CToTy.isAtLeastAsQualifiedAs(CFromTy)) { |
9734 | Qualifiers FromQs = CFromTy.getQualifiers(); |
9735 | Qualifiers ToQs = CToTy.getQualifiers(); |
9736 | |
9737 | if (FromQs.getAddressSpace() != ToQs.getAddressSpace()) { |
9738 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_addrspace) |
9739 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc |
9740 | << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy |
9741 | << ToTy << (unsigned)isObjectArgument << I + 1; |
9742 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
9743 | return; |
9744 | } |
9745 | |
9746 | if (FromQs.getObjCLifetime() != ToQs.getObjCLifetime()) { |
9747 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_ownership) |
9748 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc |
9749 | << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy |
9750 | << FromQs.getObjCLifetime() << ToQs.getObjCLifetime() |
9751 | << (unsigned)isObjectArgument << I + 1; |
9752 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
9753 | return; |
9754 | } |
9755 | |
9756 | if (FromQs.getObjCGCAttr() != ToQs.getObjCGCAttr()) { |
9757 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_gc) |
9758 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc |
9759 | << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy |
9760 | << FromQs.getObjCGCAttr() << ToQs.getObjCGCAttr() |
9761 | << (unsigned)isObjectArgument << I + 1; |
9762 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
9763 | return; |
9764 | } |
9765 | |
9766 | if (FromQs.hasUnaligned() != ToQs.hasUnaligned()) { |
9767 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_unaligned) |
9768 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc |
9769 | << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy |
9770 | << FromQs.hasUnaligned() << I + 1; |
9771 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
9772 | return; |
9773 | } |
9774 | |
9775 | unsigned CVR = FromQs.getCVRQualifiers() & ~ToQs.getCVRQualifiers(); |
9776 | (0) . __assert_fail ("CVR && \"unexpected qualifiers mismatch\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9776, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(CVR && "unexpected qualifiers mismatch"); |
9777 | |
9778 | if (isObjectArgument) { |
9779 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_cvr_this) |
9780 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc |
9781 | << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy |
9782 | << (CVR - 1); |
9783 | } else { |
9784 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_cvr) |
9785 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc |
9786 | << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy |
9787 | << (CVR - 1) << I + 1; |
9788 | } |
9789 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
9790 | return; |
9791 | } |
9792 | |
9793 | |
9794 | |
9795 | if (FromExpr && isa<InitListExpr>(FromExpr)) { |
9796 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_list_argument) |
9797 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc |
9798 | << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy |
9799 | << ToTy << (unsigned)isObjectArgument << I + 1; |
9800 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
9801 | return; |
9802 | } |
9803 | |
9804 | |
9805 | |
9806 | |
9807 | QualType TempFromTy = FromTy.getNonReferenceType(); |
9808 | if (const PointerType *PTy = TempFromTy->getAs<PointerType>()) |
9809 | TempFromTy = PTy->getPointeeType(); |
9810 | if (TempFromTy->isIncompleteType()) { |
9811 | |
9812 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_conv_incomplete) |
9813 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc |
9814 | << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy |
9815 | << ToTy << (unsigned)isObjectArgument << I + 1 |
9816 | << (unsigned)(Cand->Fix.Kind); |
9817 | |
9818 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
9819 | return; |
9820 | } |
9821 | |
9822 | |
9823 | unsigned BaseToDerivedConversion = 0; |
9824 | if (const PointerType *FromPtrTy = FromTy->getAs<PointerType>()) { |
9825 | if (const PointerType *ToPtrTy = ToTy->getAs<PointerType>()) { |
9826 | if (ToPtrTy->getPointeeType().isAtLeastAsQualifiedAs( |
9827 | FromPtrTy->getPointeeType()) && |
9828 | !FromPtrTy->getPointeeType()->isIncompleteType() && |
9829 | !ToPtrTy->getPointeeType()->isIncompleteType() && |
9830 | S.IsDerivedFrom(SourceLocation(), ToPtrTy->getPointeeType(), |
9831 | FromPtrTy->getPointeeType())) |
9832 | BaseToDerivedConversion = 1; |
9833 | } |
9834 | } else if (const ObjCObjectPointerType *FromPtrTy |
9835 | = FromTy->getAs<ObjCObjectPointerType>()) { |
9836 | if (const ObjCObjectPointerType *ToPtrTy |
9837 | = ToTy->getAs<ObjCObjectPointerType>()) |
9838 | if (const ObjCInterfaceDecl *FromIface = FromPtrTy->getInterfaceDecl()) |
9839 | if (const ObjCInterfaceDecl *ToIface = ToPtrTy->getInterfaceDecl()) |
9840 | if (ToPtrTy->getPointeeType().isAtLeastAsQualifiedAs( |
9841 | FromPtrTy->getPointeeType()) && |
9842 | FromIface->isSuperClassOf(ToIface)) |
9843 | BaseToDerivedConversion = 2; |
9844 | } else if (const ReferenceType *ToRefTy = ToTy->getAs<ReferenceType>()) { |
9845 | if (ToRefTy->getPointeeType().isAtLeastAsQualifiedAs(FromTy) && |
9846 | !FromTy->isIncompleteType() && |
9847 | !ToRefTy->getPointeeType()->isIncompleteType() && |
9848 | S.IsDerivedFrom(SourceLocation(), ToRefTy->getPointeeType(), FromTy)) { |
9849 | BaseToDerivedConversion = 3; |
9850 | } else if (ToTy->isLValueReferenceType() && !FromExpr->isLValue() && |
9851 | ToTy.getNonReferenceType().getCanonicalType() == |
9852 | FromTy.getNonReferenceType().getCanonicalType()) { |
9853 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_lvalue) |
9854 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc |
9855 | << (unsigned)isObjectArgument << I + 1 |
9856 | << (FromExpr ? FromExpr->getSourceRange() : SourceRange()); |
9857 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
9858 | return; |
9859 | } |
9860 | } |
9861 | |
9862 | if (BaseToDerivedConversion) { |
9863 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_base_to_derived_conv) |
9864 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc |
9865 | << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) |
9866 | << (BaseToDerivedConversion - 1) << FromTy << ToTy << I + 1; |
9867 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
9868 | return; |
9869 | } |
9870 | |
9871 | if (isa<ObjCObjectPointerType>(CFromTy) && |
9872 | isa<PointerType>(CToTy)) { |
9873 | Qualifiers FromQs = CFromTy.getQualifiers(); |
9874 | Qualifiers ToQs = CToTy.getQualifiers(); |
9875 | if (FromQs.getObjCLifetime() != ToQs.getObjCLifetime()) { |
9876 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_arc_conv) |
9877 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second |
9878 | << FnDesc << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) |
9879 | << FromTy << ToTy << (unsigned)isObjectArgument << I + 1; |
9880 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
9881 | return; |
9882 | } |
9883 | } |
9884 | |
9885 | if (TakingCandidateAddress && |
9886 | !checkAddressOfCandidateIsAvailable(S, Cand->Function)) |
9887 | return; |
9888 | |
9889 | |
9890 | PartialDiagnostic FDiag = S.PDiag(diag::note_ovl_candidate_bad_conv); |
9891 | FDiag << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc |
9892 | << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy |
9893 | << ToTy << (unsigned)isObjectArgument << I + 1 |
9894 | << (unsigned)(Cand->Fix.Kind); |
9895 | |
9896 | |
9897 | for (std::vector<FixItHint>::iterator HI = Cand->Fix.Hints.begin(), |
9898 | HE = Cand->Fix.Hints.end(); HI != HE; ++HI) |
9899 | FDiag << *HI; |
9900 | S.Diag(Fn->getLocation(), FDiag); |
9901 | |
9902 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
9903 | } |
9904 | |
9905 | |
9906 | |
9907 | |
9908 | static bool CheckArityMismatch(Sema &S, OverloadCandidate *Cand, |
9909 | unsigned NumArgs) { |
9910 | FunctionDecl *Fn = Cand->Function; |
9911 | unsigned MinParams = Fn->getMinRequiredArguments(); |
9912 | |
9913 | |
9914 | |
9915 | |
9916 | |
9917 | |
9918 | if (Fn->isInvalidDecl() && |
9919 | Fn->getDeclName().getNameKind() == DeclarationName::CXXOperatorName) |
9920 | return true; |
9921 | |
9922 | if (NumArgs < MinParams) { |
9923 | FailureKind == ovl_fail_too_few_arguments) || (Cand->FailureKind == ovl_fail_bad_deduction && Cand->DeductionFailure.Result == Sema..TDK_TooFewArguments)", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9925, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((Cand->FailureKind == ovl_fail_too_few_arguments) || |
9924 | FailureKind == ovl_fail_too_few_arguments) || (Cand->FailureKind == ovl_fail_bad_deduction && Cand->DeductionFailure.Result == Sema..TDK_TooFewArguments)", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9925, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> (Cand->FailureKind == ovl_fail_bad_deduction && |
9925 | FailureKind == ovl_fail_too_few_arguments) || (Cand->FailureKind == ovl_fail_bad_deduction && Cand->DeductionFailure.Result == Sema..TDK_TooFewArguments)", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9925, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> Cand->DeductionFailure.Result == Sema::TDK_TooFewArguments)); |
9926 | } else { |
9927 | FailureKind == ovl_fail_too_many_arguments) || (Cand->FailureKind == ovl_fail_bad_deduction && Cand->DeductionFailure.Result == Sema..TDK_TooManyArguments)", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9929, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((Cand->FailureKind == ovl_fail_too_many_arguments) || |
9928 | FailureKind == ovl_fail_too_many_arguments) || (Cand->FailureKind == ovl_fail_bad_deduction && Cand->DeductionFailure.Result == Sema..TDK_TooManyArguments)", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9929, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> (Cand->FailureKind == ovl_fail_bad_deduction && |
9929 | FailureKind == ovl_fail_too_many_arguments) || (Cand->FailureKind == ovl_fail_bad_deduction && Cand->DeductionFailure.Result == Sema..TDK_TooManyArguments)", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9929, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> Cand->DeductionFailure.Result == Sema::TDK_TooManyArguments)); |
9930 | } |
9931 | |
9932 | return false; |
9933 | } |
9934 | |
9935 | |
9936 | static void DiagnoseArityMismatch(Sema &S, NamedDecl *Found, Decl *D, |
9937 | unsigned NumFormalArgs) { |
9938 | (0) . __assert_fail ("isa(D) && \"The templated declaration should at least be a function\" \" when diagnosing bad template argument deduction due to too many\" \" or too few arguments\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9941, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<FunctionDecl>(D) && |
9939 | (0) . __assert_fail ("isa(D) && \"The templated declaration should at least be a function\" \" when diagnosing bad template argument deduction due to too many\" \" or too few arguments\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9941, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "The templated declaration should at least be a function" |
9940 | (0) . __assert_fail ("isa(D) && \"The templated declaration should at least be a function\" \" when diagnosing bad template argument deduction due to too many\" \" or too few arguments\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9941, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> " when diagnosing bad template argument deduction due to too many" |
9941 | (0) . __assert_fail ("isa(D) && \"The templated declaration should at least be a function\" \" when diagnosing bad template argument deduction due to too many\" \" or too few arguments\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 9941, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> " or too few arguments"); |
9942 | |
9943 | FunctionDecl *Fn = cast<FunctionDecl>(D); |
9944 | |
9945 | |
9946 | const FunctionProtoType *FnTy = Fn->getType()->getAs<FunctionProtoType>(); |
9947 | unsigned MinParams = Fn->getMinRequiredArguments(); |
9948 | |
9949 | |
9950 | unsigned mode, modeCount; |
9951 | if (NumFormalArgs < MinParams) { |
9952 | if (MinParams != FnTy->getNumParams() || FnTy->isVariadic() || |
9953 | FnTy->isTemplateVariadic()) |
9954 | mode = 0; |
9955 | else |
9956 | mode = 2; |
9957 | modeCount = MinParams; |
9958 | } else { |
9959 | if (MinParams != FnTy->getNumParams()) |
9960 | mode = 1; |
9961 | else |
9962 | mode = 2; |
9963 | modeCount = FnTy->getNumParams(); |
9964 | } |
9965 | |
9966 | std::string Description; |
9967 | std::pair<OverloadCandidateKind, OverloadCandidateSelect> FnKindPair = |
9968 | ClassifyOverloadCandidate(S, Found, Fn, Description); |
9969 | |
9970 | if (modeCount == 1 && Fn->getParamDecl(0)->getDeclName()) |
9971 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity_one) |
9972 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second |
9973 | << Description << mode << Fn->getParamDecl(0) << NumFormalArgs; |
9974 | else |
9975 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity) |
9976 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second |
9977 | << Description << mode << modeCount << NumFormalArgs; |
9978 | |
9979 | MaybeEmitInheritedConstructorNote(S, Found); |
9980 | } |
9981 | |
9982 | |
9983 | static void DiagnoseArityMismatch(Sema &S, OverloadCandidate *Cand, |
9984 | unsigned NumFormalArgs) { |
9985 | if (!CheckArityMismatch(S, Cand, NumFormalArgs)) |
9986 | DiagnoseArityMismatch(S, Cand->FoundDecl, Cand->Function, NumFormalArgs); |
9987 | } |
9988 | |
9989 | static TemplateDecl *getDescribedTemplate(Decl *Templated) { |
9990 | if (TemplateDecl *TD = Templated->getDescribedTemplate()) |
9991 | return TD; |
9992 | llvm_unreachable("Unsupported: Getting the described template declaration" |
9993 | " for bad deduction diagnosis"); |
9994 | } |
9995 | |
9996 | |
9997 | static void DiagnoseBadDeduction(Sema &S, NamedDecl *Found, Decl *Templated, |
9998 | DeductionFailureInfo &DeductionFailure, |
9999 | unsigned NumArgs, |
10000 | bool TakingCandidateAddress) { |
10001 | TemplateParameter Param = DeductionFailure.getTemplateParameter(); |
10002 | NamedDecl *ParamD; |
10003 | (ParamD = Param.dyn_cast<TemplateTypeParmDecl*>()) || |
10004 | (ParamD = Param.dyn_cast<NonTypeTemplateParmDecl*>()) || |
10005 | (ParamD = Param.dyn_cast<TemplateTemplateParmDecl*>()); |
10006 | switch (DeductionFailure.Result) { |
10007 | case Sema::TDK_Success: |
10008 | llvm_unreachable("TDK_success while diagnosing bad deduction"); |
10009 | |
10010 | case Sema::TDK_Incomplete: { |
10011 | (0) . __assert_fail ("ParamD && \"no parameter found for incomplete deduction result\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10011, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ParamD && "no parameter found for incomplete deduction result"); |
10012 | S.Diag(Templated->getLocation(), |
10013 | diag::note_ovl_candidate_incomplete_deduction) |
10014 | << ParamD->getDeclName(); |
10015 | MaybeEmitInheritedConstructorNote(S, Found); |
10016 | return; |
10017 | } |
10018 | |
10019 | case Sema::TDK_IncompletePack: { |
10020 | (0) . __assert_fail ("ParamD && \"no parameter found for incomplete deduction result\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10020, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ParamD && "no parameter found for incomplete deduction result"); |
10021 | S.Diag(Templated->getLocation(), |
10022 | diag::note_ovl_candidate_incomplete_deduction_pack) |
10023 | << ParamD->getDeclName() |
10024 | << (DeductionFailure.getFirstArg()->pack_size() + 1) |
10025 | << *DeductionFailure.getFirstArg(); |
10026 | MaybeEmitInheritedConstructorNote(S, Found); |
10027 | return; |
10028 | } |
10029 | |
10030 | case Sema::TDK_Underqualified: { |
10031 | (0) . __assert_fail ("ParamD && \"no parameter found for bad qualifiers deduction result\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10031, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ParamD && "no parameter found for bad qualifiers deduction result"); |
10032 | TemplateTypeParmDecl *TParam = cast<TemplateTypeParmDecl>(ParamD); |
10033 | |
10034 | QualType Param = DeductionFailure.getFirstArg()->getAsType(); |
10035 | |
10036 | |
10037 | |
10038 | QualifierCollector Qs; |
10039 | Qs.strip(Param); |
10040 | QualType NonCanonParam = Qs.apply(S.Context, TParam->getTypeForDecl()); |
10041 | assert(S.Context.hasSameType(Param, NonCanonParam)); |
10042 | |
10043 | |
10044 | |
10045 | |
10046 | |
10047 | QualType Arg = DeductionFailure.getSecondArg()->getAsType(); |
10048 | |
10049 | S.Diag(Templated->getLocation(), diag::note_ovl_candidate_underqualified) |
10050 | << ParamD->getDeclName() << Arg << NonCanonParam; |
10051 | MaybeEmitInheritedConstructorNote(S, Found); |
10052 | return; |
10053 | } |
10054 | |
10055 | case Sema::TDK_Inconsistent: { |
10056 | (0) . __assert_fail ("ParamD && \"no parameter found for inconsistent deduction result\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10056, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ParamD && "no parameter found for inconsistent deduction result"); |
10057 | int which = 0; |
10058 | if (isa<TemplateTypeParmDecl>(ParamD)) |
10059 | which = 0; |
10060 | else if (isa<NonTypeTemplateParmDecl>(ParamD)) { |
10061 | |
10062 | |
10063 | |
10064 | QualType T1 = |
10065 | DeductionFailure.getFirstArg()->getNonTypeTemplateArgumentType(); |
10066 | QualType T2 = |
10067 | DeductionFailure.getSecondArg()->getNonTypeTemplateArgumentType(); |
10068 | if (!T1.isNull() && !T2.isNull() && !S.Context.hasSameType(T1, T2)) { |
10069 | S.Diag(Templated->getLocation(), |
10070 | diag::note_ovl_candidate_inconsistent_deduction_types) |
10071 | << ParamD->getDeclName() << *DeductionFailure.getFirstArg() << T1 |
10072 | << *DeductionFailure.getSecondArg() << T2; |
10073 | MaybeEmitInheritedConstructorNote(S, Found); |
10074 | return; |
10075 | } |
10076 | |
10077 | which = 1; |
10078 | } else { |
10079 | which = 2; |
10080 | } |
10081 | |
10082 | S.Diag(Templated->getLocation(), |
10083 | diag::note_ovl_candidate_inconsistent_deduction) |
10084 | << which << ParamD->getDeclName() << *DeductionFailure.getFirstArg() |
10085 | << *DeductionFailure.getSecondArg(); |
10086 | MaybeEmitInheritedConstructorNote(S, Found); |
10087 | return; |
10088 | } |
10089 | |
10090 | case Sema::TDK_InvalidExplicitArguments: |
10091 | (0) . __assert_fail ("ParamD && \"no parameter found for invalid explicit arguments\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10091, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ParamD && "no parameter found for invalid explicit arguments"); |
10092 | if (ParamD->getDeclName()) |
10093 | S.Diag(Templated->getLocation(), |
10094 | diag::note_ovl_candidate_explicit_arg_mismatch_named) |
10095 | << ParamD->getDeclName(); |
10096 | else { |
10097 | int index = 0; |
10098 | if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(ParamD)) |
10099 | index = TTP->getIndex(); |
10100 | else if (NonTypeTemplateParmDecl *NTTP |
10101 | = dyn_cast<NonTypeTemplateParmDecl>(ParamD)) |
10102 | index = NTTP->getIndex(); |
10103 | else |
10104 | index = cast<TemplateTemplateParmDecl>(ParamD)->getIndex(); |
10105 | S.Diag(Templated->getLocation(), |
10106 | diag::note_ovl_candidate_explicit_arg_mismatch_unnamed) |
10107 | << (index + 1); |
10108 | } |
10109 | MaybeEmitInheritedConstructorNote(S, Found); |
10110 | return; |
10111 | |
10112 | case Sema::TDK_TooManyArguments: |
10113 | case Sema::TDK_TooFewArguments: |
10114 | DiagnoseArityMismatch(S, Found, Templated, NumArgs); |
10115 | return; |
10116 | |
10117 | case Sema::TDK_InstantiationDepth: |
10118 | S.Diag(Templated->getLocation(), |
10119 | diag::note_ovl_candidate_instantiation_depth); |
10120 | MaybeEmitInheritedConstructorNote(S, Found); |
10121 | return; |
10122 | |
10123 | case Sema::TDK_SubstitutionFailure: { |
10124 | |
10125 | SmallString<128> TemplateArgString; |
10126 | if (TemplateArgumentList *Args = |
10127 | DeductionFailure.getTemplateArgumentList()) { |
10128 | TemplateArgString = " "; |
10129 | TemplateArgString += S.getTemplateArgumentBindingsText( |
10130 | getDescribedTemplate(Templated)->getTemplateParameters(), *Args); |
10131 | } |
10132 | |
10133 | |
10134 | PartialDiagnosticAt *PDiag = DeductionFailure.getSFINAEDiagnostic(); |
10135 | if (PDiag && PDiag->second.getDiagID() == |
10136 | diag::err_typename_nested_not_found_enable_if) { |
10137 | |
10138 | |
10139 | S.Diag(PDiag->first, diag::note_ovl_candidate_disabled_by_enable_if) |
10140 | << "'enable_if'" << TemplateArgString; |
10141 | return; |
10142 | } |
10143 | |
10144 | |
10145 | if (PDiag && PDiag->second.getDiagID() == |
10146 | diag::err_typename_nested_not_found_requirement) { |
10147 | S.Diag(Templated->getLocation(), |
10148 | diag::note_ovl_candidate_disabled_by_requirement) |
10149 | << PDiag->second.getStringArg(0) << TemplateArgString; |
10150 | return; |
10151 | } |
10152 | |
10153 | |
10154 | |
10155 | |
10156 | SmallString<128> SFINAEArgString; |
10157 | SourceRange R; |
10158 | if (PDiag) { |
10159 | SFINAEArgString = ": "; |
10160 | R = SourceRange(PDiag->first, PDiag->first); |
10161 | PDiag->second.EmitToString(S.getDiagnostics(), SFINAEArgString); |
10162 | } |
10163 | |
10164 | S.Diag(Templated->getLocation(), |
10165 | diag::note_ovl_candidate_substitution_failure) |
10166 | << TemplateArgString << SFINAEArgString << R; |
10167 | MaybeEmitInheritedConstructorNote(S, Found); |
10168 | return; |
10169 | } |
10170 | |
10171 | case Sema::TDK_DeducedMismatch: |
10172 | case Sema::TDK_DeducedMismatchNested: { |
10173 | |
10174 | SmallString<128> TemplateArgString; |
10175 | if (TemplateArgumentList *Args = |
10176 | DeductionFailure.getTemplateArgumentList()) { |
10177 | TemplateArgString = " "; |
10178 | TemplateArgString += S.getTemplateArgumentBindingsText( |
10179 | getDescribedTemplate(Templated)->getTemplateParameters(), *Args); |
10180 | } |
10181 | |
10182 | S.Diag(Templated->getLocation(), diag::note_ovl_candidate_deduced_mismatch) |
10183 | << (*DeductionFailure.getCallArgIndex() + 1) |
10184 | << *DeductionFailure.getFirstArg() << *DeductionFailure.getSecondArg() |
10185 | << TemplateArgString |
10186 | << (DeductionFailure.Result == Sema::TDK_DeducedMismatchNested); |
10187 | break; |
10188 | } |
10189 | |
10190 | case Sema::TDK_NonDeducedMismatch: { |
10191 | |
10192 | TemplateArgument FirstTA = *DeductionFailure.getFirstArg(); |
10193 | TemplateArgument SecondTA = *DeductionFailure.getSecondArg(); |
10194 | if (FirstTA.getKind() == TemplateArgument::Template && |
10195 | SecondTA.getKind() == TemplateArgument::Template) { |
10196 | TemplateName FirstTN = FirstTA.getAsTemplate(); |
10197 | TemplateName SecondTN = SecondTA.getAsTemplate(); |
10198 | if (FirstTN.getKind() == TemplateName::Template && |
10199 | SecondTN.getKind() == TemplateName::Template) { |
10200 | if (FirstTN.getAsTemplateDecl()->getName() == |
10201 | SecondTN.getAsTemplateDecl()->getName()) { |
10202 | |
10203 | |
10204 | |
10205 | |
10206 | |
10207 | |
10208 | S.Diag(Templated->getLocation(), |
10209 | diag::note_ovl_candidate_non_deduced_mismatch_qualified) |
10210 | << FirstTN.getAsTemplateDecl() << SecondTN.getAsTemplateDecl(); |
10211 | return; |
10212 | } |
10213 | } |
10214 | } |
10215 | |
10216 | if (TakingCandidateAddress && isa<FunctionDecl>(Templated) && |
10217 | !checkAddressOfCandidateIsAvailable(S, cast<FunctionDecl>(Templated))) |
10218 | return; |
10219 | |
10220 | |
10221 | |
10222 | |
10223 | |
10224 | S.Diag(Templated->getLocation(), |
10225 | diag::note_ovl_candidate_non_deduced_mismatch) |
10226 | << FirstTA << SecondTA; |
10227 | return; |
10228 | } |
10229 | |
10230 | |
10231 | case Sema::TDK_MiscellaneousDeductionFailure: |
10232 | S.Diag(Templated->getLocation(), diag::note_ovl_candidate_bad_deduction); |
10233 | MaybeEmitInheritedConstructorNote(S, Found); |
10234 | return; |
10235 | case Sema::TDK_CUDATargetMismatch: |
10236 | S.Diag(Templated->getLocation(), |
10237 | diag::note_cuda_ovl_candidate_target_mismatch); |
10238 | return; |
10239 | } |
10240 | } |
10241 | |
10242 | |
10243 | static void DiagnoseBadDeduction(Sema &S, OverloadCandidate *Cand, |
10244 | unsigned NumArgs, |
10245 | bool TakingCandidateAddress) { |
10246 | unsigned TDK = Cand->DeductionFailure.Result; |
10247 | if (TDK == Sema::TDK_TooFewArguments || TDK == Sema::TDK_TooManyArguments) { |
10248 | if (CheckArityMismatch(S, Cand, NumArgs)) |
10249 | return; |
10250 | } |
10251 | DiagnoseBadDeduction(S, Cand->FoundDecl, Cand->Function, |
10252 | Cand->DeductionFailure, NumArgs, TakingCandidateAddress); |
10253 | } |
10254 | |
10255 | |
10256 | static void DiagnoseBadTarget(Sema &S, OverloadCandidate *Cand) { |
10257 | FunctionDecl *Caller = cast<FunctionDecl>(S.CurContext); |
10258 | FunctionDecl *Callee = Cand->Function; |
10259 | |
10260 | Sema::CUDAFunctionTarget CallerTarget = S.IdentifyCUDATarget(Caller), |
10261 | CalleeTarget = S.IdentifyCUDATarget(Callee); |
10262 | |
10263 | std::string FnDesc; |
10264 | std::pair<OverloadCandidateKind, OverloadCandidateSelect> FnKindPair = |
10265 | ClassifyOverloadCandidate(S, Cand->FoundDecl, Callee, FnDesc); |
10266 | |
10267 | S.Diag(Callee->getLocation(), diag::note_ovl_candidate_bad_target) |
10268 | << (unsigned)FnKindPair.first << (unsigned)ocs_non_template |
10269 | << FnDesc |
10270 | << CalleeTarget << CallerTarget; |
10271 | |
10272 | |
10273 | |
10274 | CXXMethodDecl *Meth = dyn_cast<CXXMethodDecl>(Callee); |
10275 | if (Meth != nullptr && Meth->isImplicit()) { |
10276 | CXXRecordDecl *ParentClass = Meth->getParent(); |
10277 | Sema::CXXSpecialMember CSM; |
10278 | |
10279 | switch (FnKindPair.first) { |
10280 | default: |
10281 | return; |
10282 | case oc_implicit_default_constructor: |
10283 | CSM = Sema::CXXDefaultConstructor; |
10284 | break; |
10285 | case oc_implicit_copy_constructor: |
10286 | CSM = Sema::CXXCopyConstructor; |
10287 | break; |
10288 | case oc_implicit_move_constructor: |
10289 | CSM = Sema::CXXMoveConstructor; |
10290 | break; |
10291 | case oc_implicit_copy_assignment: |
10292 | CSM = Sema::CXXCopyAssignment; |
10293 | break; |
10294 | case oc_implicit_move_assignment: |
10295 | CSM = Sema::CXXMoveAssignment; |
10296 | break; |
10297 | }; |
10298 | |
10299 | bool ConstRHS = false; |
10300 | if (Meth->getNumParams()) { |
10301 | if (const ReferenceType *RT = |
10302 | Meth->getParamDecl(0)->getType()->getAs<ReferenceType>()) { |
10303 | ConstRHS = RT->getPointeeType().isConstQualified(); |
10304 | } |
10305 | } |
10306 | |
10307 | S.inferCUDATargetForImplicitSpecialMember(ParentClass, CSM, Meth, |
10308 | ConstRHS, |
10309 | true); |
10310 | } |
10311 | } |
10312 | |
10313 | static void DiagnoseFailedEnableIfAttr(Sema &S, OverloadCandidate *Cand) { |
10314 | FunctionDecl *Callee = Cand->Function; |
10315 | EnableIfAttr *Attr = static_cast<EnableIfAttr*>(Cand->DeductionFailure.Data); |
10316 | |
10317 | S.Diag(Callee->getLocation(), |
10318 | diag::note_ovl_candidate_disabled_by_function_cond_attr) |
10319 | << Attr->getCond()->getSourceRange() << Attr->getMessage(); |
10320 | } |
10321 | |
10322 | static void DiagnoseOpenCLExtensionDisabled(Sema &S, OverloadCandidate *Cand) { |
10323 | FunctionDecl *Callee = Cand->Function; |
10324 | |
10325 | S.Diag(Callee->getLocation(), |
10326 | diag::note_ovl_candidate_disabled_by_extension) |
10327 | << S.getOpenCLExtensionsFromDeclExtMap(Callee); |
10328 | } |
10329 | |
10330 | |
10331 | |
10332 | |
10333 | |
10334 | |
10335 | |
10336 | |
10337 | |
10338 | |
10339 | |
10340 | |
10341 | |
10342 | |
10343 | static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand, |
10344 | unsigned NumArgs, |
10345 | bool TakingCandidateAddress) { |
10346 | FunctionDecl *Fn = Cand->Function; |
10347 | |
10348 | |
10349 | if (Cand->Viable) { |
10350 | if (Fn->isDeleted()) { |
10351 | std::string FnDesc; |
10352 | std::pair<OverloadCandidateKind, OverloadCandidateSelect> FnKindPair = |
10353 | ClassifyOverloadCandidate(S, Cand->FoundDecl, Fn, FnDesc); |
10354 | |
10355 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_deleted) |
10356 | << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc |
10357 | << (Fn->isDeleted() ? (Fn->isDeletedAsWritten() ? 1 : 2) : 0); |
10358 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
10359 | return; |
10360 | } |
10361 | |
10362 | |
10363 | S.NoteOverloadCandidate(Cand->FoundDecl, Fn); |
10364 | return; |
10365 | } |
10366 | |
10367 | switch (Cand->FailureKind) { |
10368 | case ovl_fail_too_many_arguments: |
10369 | case ovl_fail_too_few_arguments: |
10370 | return DiagnoseArityMismatch(S, Cand, NumArgs); |
10371 | |
10372 | case ovl_fail_bad_deduction: |
10373 | return DiagnoseBadDeduction(S, Cand, NumArgs, |
10374 | TakingCandidateAddress); |
10375 | |
10376 | case ovl_fail_illegal_constructor: { |
10377 | S.Diag(Fn->getLocation(), diag::note_ovl_candidate_illegal_constructor) |
10378 | << (Fn->getPrimaryTemplate() ? 1 : 0); |
10379 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
10380 | return; |
10381 | } |
10382 | |
10383 | case ovl_fail_trivial_conversion: |
10384 | case ovl_fail_bad_final_conversion: |
10385 | case ovl_fail_final_conversion_not_exact: |
10386 | return S.NoteOverloadCandidate(Cand->FoundDecl, Fn); |
10387 | |
10388 | case ovl_fail_bad_conversion: { |
10389 | unsigned I = (Cand->IgnoreObjectArgument ? 1 : 0); |
10390 | for (unsigned N = Cand->Conversions.size(); I != N; ++I) |
10391 | if (Cand->Conversions[I].isBad()) |
10392 | return DiagnoseBadConversion(S, Cand, I, TakingCandidateAddress); |
10393 | |
10394 | |
10395 | |
10396 | |
10397 | return S.NoteOverloadCandidate(Cand->FoundDecl, Fn); |
10398 | } |
10399 | |
10400 | case ovl_fail_bad_target: |
10401 | return DiagnoseBadTarget(S, Cand); |
10402 | |
10403 | case ovl_fail_enable_if: |
10404 | return DiagnoseFailedEnableIfAttr(S, Cand); |
10405 | |
10406 | case ovl_fail_ext_disabled: |
10407 | return DiagnoseOpenCLExtensionDisabled(S, Cand); |
10408 | |
10409 | case ovl_fail_inhctor_slice: |
10410 | |
10411 | if (cast<CXXConstructorDecl>(Fn)->isCopyOrMoveConstructor()) |
10412 | return; |
10413 | S.Diag(Fn->getLocation(), |
10414 | diag::note_ovl_candidate_inherited_constructor_slice) |
10415 | << (Fn->getPrimaryTemplate() ? 1 : 0) |
10416 | << Fn->getParamDecl(0)->getType()->isRValueReferenceType(); |
10417 | MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); |
10418 | return; |
10419 | |
10420 | case ovl_fail_addr_not_available: { |
10421 | bool Available = checkAddressOfCandidateIsAvailable(S, Cand->Function); |
10422 | (void)Available; |
10423 | assert(!Available); |
10424 | break; |
10425 | } |
10426 | case ovl_non_default_multiversion_function: |
10427 | |
10428 | break; |
10429 | } |
10430 | } |
10431 | |
10432 | static void NoteSurrogateCandidate(Sema &S, OverloadCandidate *Cand) { |
10433 | |
10434 | |
10435 | |
10436 | QualType FnType = Cand->Surrogate->getConversionType(); |
10437 | bool isLValueReference = false; |
10438 | bool isRValueReference = false; |
10439 | bool isPointer = false; |
10440 | if (const LValueReferenceType *FnTypeRef = |
10441 | FnType->getAs<LValueReferenceType>()) { |
10442 | FnType = FnTypeRef->getPointeeType(); |
10443 | isLValueReference = true; |
10444 | } else if (const RValueReferenceType *FnTypeRef = |
10445 | FnType->getAs<RValueReferenceType>()) { |
10446 | FnType = FnTypeRef->getPointeeType(); |
10447 | isRValueReference = true; |
10448 | } |
10449 | if (const PointerType *FnTypePtr = FnType->getAs<PointerType>()) { |
10450 | FnType = FnTypePtr->getPointeeType(); |
10451 | isPointer = true; |
10452 | } |
10453 | |
10454 | FnType = QualType(FnType->getAs<FunctionType>(), 0); |
10455 | |
10456 | if (isPointer) FnType = S.Context.getPointerType(FnType); |
10457 | if (isRValueReference) FnType = S.Context.getRValueReferenceType(FnType); |
10458 | if (isLValueReference) FnType = S.Context.getLValueReferenceType(FnType); |
10459 | |
10460 | S.Diag(Cand->Surrogate->getLocation(), diag::note_ovl_surrogate_cand) |
10461 | << FnType; |
10462 | } |
10463 | |
10464 | static void NoteBuiltinOperatorCandidate(Sema &S, StringRef Opc, |
10465 | SourceLocation OpLoc, |
10466 | OverloadCandidate *Cand) { |
10467 | (0) . __assert_fail ("Cand->Conversions.size() <= 2 && \"builtin operator is not binary\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10467, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Cand->Conversions.size() <= 2 && "builtin operator is not binary"); |
10468 | std::string TypeStr("operator"); |
10469 | TypeStr += Opc; |
10470 | TypeStr += "("; |
10471 | TypeStr += Cand->BuiltinParamTypes[0].getAsString(); |
10472 | if (Cand->Conversions.size() == 1) { |
10473 | TypeStr += ")"; |
10474 | S.Diag(OpLoc, diag::note_ovl_builtin_unary_candidate) << TypeStr; |
10475 | } else { |
10476 | TypeStr += ", "; |
10477 | TypeStr += Cand->BuiltinParamTypes[1].getAsString(); |
10478 | TypeStr += ")"; |
10479 | S.Diag(OpLoc, diag::note_ovl_builtin_binary_candidate) << TypeStr; |
10480 | } |
10481 | } |
10482 | |
10483 | static void NoteAmbiguousUserConversions(Sema &S, SourceLocation OpLoc, |
10484 | OverloadCandidate *Cand) { |
10485 | for (const ImplicitConversionSequence &ICS : Cand->Conversions) { |
10486 | if (ICS.isBad()) break; |
10487 | if (!ICS.isAmbiguous()) continue; |
10488 | |
10489 | ICS.DiagnoseAmbiguousConversion( |
10490 | S, OpLoc, S.PDiag(diag::note_ambiguous_type_conversion)); |
10491 | } |
10492 | } |
10493 | |
10494 | static SourceLocation GetLocationForCandidate(const OverloadCandidate *Cand) { |
10495 | if (Cand->Function) |
10496 | return Cand->Function->getLocation(); |
10497 | if (Cand->IsSurrogate) |
10498 | return Cand->Surrogate->getLocation(); |
10499 | return SourceLocation(); |
10500 | } |
10501 | |
10502 | static unsigned RankDeductionFailure(const DeductionFailureInfo &DFI) { |
10503 | switch ((Sema::TemplateDeductionResult)DFI.Result) { |
10504 | case Sema::TDK_Success: |
10505 | case Sema::TDK_NonDependentConversionFailure: |
10506 | llvm_unreachable("non-deduction failure while diagnosing bad deduction"); |
10507 | |
10508 | case Sema::TDK_Invalid: |
10509 | case Sema::TDK_Incomplete: |
10510 | case Sema::TDK_IncompletePack: |
10511 | return 1; |
10512 | |
10513 | case Sema::TDK_Underqualified: |
10514 | case Sema::TDK_Inconsistent: |
10515 | return 2; |
10516 | |
10517 | case Sema::TDK_SubstitutionFailure: |
10518 | case Sema::TDK_DeducedMismatch: |
10519 | case Sema::TDK_DeducedMismatchNested: |
10520 | case Sema::TDK_NonDeducedMismatch: |
10521 | case Sema::TDK_MiscellaneousDeductionFailure: |
10522 | case Sema::TDK_CUDATargetMismatch: |
10523 | return 3; |
10524 | |
10525 | case Sema::TDK_InstantiationDepth: |
10526 | return 4; |
10527 | |
10528 | case Sema::TDK_InvalidExplicitArguments: |
10529 | return 5; |
10530 | |
10531 | case Sema::TDK_TooManyArguments: |
10532 | case Sema::TDK_TooFewArguments: |
10533 | return 6; |
10534 | } |
10535 | llvm_unreachable("Unhandled deduction result"); |
10536 | } |
10537 | |
10538 | namespace { |
10539 | struct CompareOverloadCandidatesForDisplay { |
10540 | Sema &S; |
10541 | SourceLocation Loc; |
10542 | size_t NumArgs; |
10543 | OverloadCandidateSet::CandidateSetKind CSK; |
10544 | |
10545 | CompareOverloadCandidatesForDisplay( |
10546 | Sema &S, SourceLocation Loc, size_t NArgs, |
10547 | OverloadCandidateSet::CandidateSetKind CSK) |
10548 | : S(S), NumArgs(NArgs), CSK(CSK) {} |
10549 | |
10550 | bool operator()(const OverloadCandidate *L, |
10551 | const OverloadCandidate *R) { |
10552 | |
10553 | if (L == R) return false; |
10554 | |
10555 | |
10556 | if (L->Viable) { |
10557 | if (!R->Viable) return true; |
10558 | |
10559 | |
10560 | |
10561 | |
10562 | if (isBetterOverloadCandidate(S, *L, *R, SourceLocation(), CSK)) |
10563 | return true; |
10564 | if (isBetterOverloadCandidate(S, *R, *L, SourceLocation(), CSK)) |
10565 | return false; |
10566 | } else if (R->Viable) |
10567 | return false; |
10568 | |
10569 | Viable == R->Viable", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10569, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(L->Viable == R->Viable); |
10570 | |
10571 | |
10572 | if (!L->Viable) { |
10573 | |
10574 | if (L->FailureKind == ovl_fail_too_many_arguments || |
10575 | L->FailureKind == ovl_fail_too_few_arguments) { |
10576 | if (R->FailureKind == ovl_fail_too_many_arguments || |
10577 | R->FailureKind == ovl_fail_too_few_arguments) { |
10578 | int LDist = std::abs((int)L->getNumParams() - (int)NumArgs); |
10579 | int RDist = std::abs((int)R->getNumParams() - (int)NumArgs); |
10580 | if (LDist == RDist) { |
10581 | if (L->FailureKind == R->FailureKind) |
10582 | |
10583 | return !L->IsSurrogate && R->IsSurrogate; |
10584 | |
10585 | |
10586 | |
10587 | return L->FailureKind == ovl_fail_too_many_arguments; |
10588 | } |
10589 | return LDist < RDist; |
10590 | } |
10591 | return false; |
10592 | } |
10593 | if (R->FailureKind == ovl_fail_too_many_arguments || |
10594 | R->FailureKind == ovl_fail_too_few_arguments) |
10595 | return true; |
10596 | |
10597 | |
10598 | |
10599 | if (L->FailureKind == ovl_fail_bad_conversion) { |
10600 | if (R->FailureKind != ovl_fail_bad_conversion) |
10601 | return true; |
10602 | |
10603 | |
10604 | |
10605 | unsigned numLFixes = L->Fix.NumConversionsFixed; |
10606 | unsigned numRFixes = R->Fix.NumConversionsFixed; |
10607 | numLFixes = (numLFixes == 0) ? UINT_MAX : numLFixes; |
10608 | numRFixes = (numRFixes == 0) ? UINT_MAX : numRFixes; |
10609 | if (numLFixes != numRFixes) { |
10610 | return numLFixes < numRFixes; |
10611 | } |
10612 | |
10613 | |
10614 | |
10615 | Conversions.size() == R->Conversions.size()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10615, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(L->Conversions.size() == R->Conversions.size()); |
10616 | |
10617 | int leftBetter = 0; |
10618 | unsigned I = (L->IgnoreObjectArgument || R->IgnoreObjectArgument); |
10619 | for (unsigned E = L->Conversions.size(); I != E; ++I) { |
10620 | switch (CompareImplicitConversionSequences(S, Loc, |
10621 | L->Conversions[I], |
10622 | R->Conversions[I])) { |
10623 | case ImplicitConversionSequence::Better: |
10624 | leftBetter++; |
10625 | break; |
10626 | |
10627 | case ImplicitConversionSequence::Worse: |
10628 | leftBetter--; |
10629 | break; |
10630 | |
10631 | case ImplicitConversionSequence::Indistinguishable: |
10632 | break; |
10633 | } |
10634 | } |
10635 | if (leftBetter > 0) return true; |
10636 | if (leftBetter < 0) return false; |
10637 | |
10638 | } else if (R->FailureKind == ovl_fail_bad_conversion) |
10639 | return false; |
10640 | |
10641 | if (L->FailureKind == ovl_fail_bad_deduction) { |
10642 | if (R->FailureKind != ovl_fail_bad_deduction) |
10643 | return true; |
10644 | |
10645 | if (L->DeductionFailure.Result != R->DeductionFailure.Result) |
10646 | return RankDeductionFailure(L->DeductionFailure) |
10647 | < RankDeductionFailure(R->DeductionFailure); |
10648 | } else if (R->FailureKind == ovl_fail_bad_deduction) |
10649 | return false; |
10650 | |
10651 | |
10652 | } |
10653 | |
10654 | |
10655 | SourceLocation LLoc = GetLocationForCandidate(L); |
10656 | SourceLocation RLoc = GetLocationForCandidate(R); |
10657 | |
10658 | |
10659 | if (LLoc.isInvalid()) return false; |
10660 | if (RLoc.isInvalid()) return true; |
10661 | |
10662 | return S.SourceMgr.isBeforeInTranslationUnit(LLoc, RLoc); |
10663 | } |
10664 | }; |
10665 | } |
10666 | |
10667 | |
10668 | |
10669 | |
10670 | static void CompleteNonViableCandidate(Sema &S, OverloadCandidate *Cand, |
10671 | ArrayRef<Expr *> Args) { |
10672 | Viable", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10672, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Cand->Viable); |
10673 | |
10674 | |
10675 | if (Cand->FailureKind != ovl_fail_bad_conversion) return; |
10676 | |
10677 | |
10678 | bool Unfixable = false; |
10679 | |
10680 | Cand->Fix.setConversionChecker(TryCopyInitialization); |
10681 | |
10682 | |
10683 | unsigned ConvCount = Cand->Conversions.size(); |
10684 | for (unsigned ConvIdx = (Cand->IgnoreObjectArgument ? 1 : 0); ; |
10685 | ++ConvIdx) { |
10686 | (0) . __assert_fail ("ConvIdx != ConvCount && \"no bad conversion in candidate\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10686, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ConvIdx != ConvCount && "no bad conversion in candidate"); |
10687 | if (Cand->Conversions[ConvIdx].isInitialized() && |
10688 | Cand->Conversions[ConvIdx].isBad()) { |
10689 | Unfixable = !Cand->TryToFixBadConversion(ConvIdx, S); |
10690 | break; |
10691 | } |
10692 | } |
10693 | |
10694 | |
10695 | |
10696 | bool SuppressUserConversions = false; |
10697 | |
10698 | unsigned ConvIdx = 0; |
10699 | ArrayRef<QualType> ParamTypes; |
10700 | |
10701 | if (Cand->IsSurrogate) { |
10702 | QualType ConvType |
10703 | = Cand->Surrogate->getConversionType().getNonReferenceType(); |
10704 | if (const PointerType *ConvPtrType = ConvType->getAs<PointerType>()) |
10705 | ConvType = ConvPtrType->getPointeeType(); |
10706 | ParamTypes = ConvType->getAs<FunctionProtoType>()->getParamTypes(); |
10707 | |
10708 | ConvIdx = 1; |
10709 | } else if (Cand->Function) { |
10710 | ParamTypes = |
10711 | Cand->Function->getType()->getAs<FunctionProtoType>()->getParamTypes(); |
10712 | if (isa<CXXMethodDecl>(Cand->Function) && |
10713 | !isa<CXXConstructorDecl>(Cand->Function)) { |
10714 | |
10715 | ConvIdx = 1; |
10716 | } |
10717 | } else { |
10718 | |
10719 | assert(ConvCount <= 3); |
10720 | ParamTypes = Cand->BuiltinParamTypes; |
10721 | } |
10722 | |
10723 | |
10724 | for (unsigned ArgIdx = 0; ConvIdx != ConvCount; ++ConvIdx, ++ArgIdx) { |
10725 | if (Cand->Conversions[ConvIdx].isInitialized()) { |
10726 | |
10727 | } else if (ArgIdx < ParamTypes.size()) { |
10728 | if (ParamTypes[ArgIdx]->isDependentType()) |
10729 | Cand->Conversions[ConvIdx].setAsIdentityConversion( |
10730 | Args[ArgIdx]->getType()); |
10731 | else { |
10732 | Cand->Conversions[ConvIdx] = |
10733 | TryCopyInitialization(S, Args[ArgIdx], ParamTypes[ArgIdx], |
10734 | SuppressUserConversions, |
10735 | , |
10736 | |
10737 | S.getLangOpts().ObjCAutoRefCount); |
10738 | |
10739 | if (!Unfixable && Cand->Conversions[ConvIdx].isBad()) |
10740 | Unfixable = !Cand->TryToFixBadConversion(ConvIdx, S); |
10741 | } |
10742 | } else |
10743 | Cand->Conversions[ConvIdx].setEllipsis(); |
10744 | } |
10745 | } |
10746 | |
10747 | |
10748 | |
10749 | void OverloadCandidateSet::NoteCandidates( |
10750 | Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef<Expr *> Args, |
10751 | StringRef Opc, SourceLocation OpLoc, |
10752 | llvm::function_ref<bool(OverloadCandidate &)> Filter) { |
10753 | |
10754 | |
10755 | SmallVector<OverloadCandidate*, 32> Cands; |
10756 | if (OCD == OCD_AllCandidates) Cands.reserve(size()); |
10757 | for (iterator Cand = begin(), LastCand = end(); Cand != LastCand; ++Cand) { |
10758 | if (!Filter(*Cand)) |
10759 | continue; |
10760 | if (Cand->Viable) |
10761 | Cands.push_back(Cand); |
10762 | else if (OCD == OCD_AllCandidates) { |
10763 | CompleteNonViableCandidate(S, Cand, Args); |
10764 | if (Cand->Function || Cand->IsSurrogate) |
10765 | Cands.push_back(Cand); |
10766 | |
10767 | |
10768 | } |
10769 | } |
10770 | |
10771 | std::stable_sort(Cands.begin(), Cands.end(), |
10772 | CompareOverloadCandidatesForDisplay(S, OpLoc, Args.size(), Kind)); |
10773 | |
10774 | bool ReportedAmbiguousConversions = false; |
10775 | |
10776 | SmallVectorImpl<OverloadCandidate*>::iterator I, E; |
10777 | const OverloadsShown ShowOverloads = S.Diags.getShowOverloads(); |
10778 | unsigned CandsShown = 0; |
10779 | for (I = Cands.begin(), E = Cands.end(); I != E; ++I) { |
10780 | OverloadCandidate *Cand = *I; |
10781 | |
10782 | |
10783 | |
10784 | |
10785 | if (CandsShown >= 4 && ShowOverloads == Ovl_Best) { |
10786 | break; |
10787 | } |
10788 | ++CandsShown; |
10789 | |
10790 | if (Cand->Function) |
10791 | NoteFunctionCandidate(S, Cand, Args.size(), |
10792 | ); |
10793 | else if (Cand->IsSurrogate) |
10794 | NoteSurrogateCandidate(S, Cand); |
10795 | else { |
10796 | (0) . __assert_fail ("Cand->Viable && \"Non-viable built-in candidates are not added to Cands.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10797, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Cand->Viable && |
10797 | (0) . __assert_fail ("Cand->Viable && \"Non-viable built-in candidates are not added to Cands.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10797, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Non-viable built-in candidates are not added to Cands."); |
10798 | |
10799 | |
10800 | |
10801 | |
10802 | |
10803 | |
10804 | if (!ReportedAmbiguousConversions) { |
10805 | NoteAmbiguousUserConversions(S, OpLoc, Cand); |
10806 | ReportedAmbiguousConversions = true; |
10807 | } |
10808 | |
10809 | |
10810 | NoteBuiltinOperatorCandidate(S, Opc, OpLoc, Cand); |
10811 | } |
10812 | } |
10813 | |
10814 | if (I != E) |
10815 | S.Diag(OpLoc, diag::note_ovl_too_many_candidates) << int(E - I); |
10816 | } |
10817 | |
10818 | static SourceLocation |
10819 | GetLocationForCandidate(const TemplateSpecCandidate *Cand) { |
10820 | return Cand->Specialization ? Cand->Specialization->getLocation() |
10821 | : SourceLocation(); |
10822 | } |
10823 | |
10824 | namespace { |
10825 | struct CompareTemplateSpecCandidatesForDisplay { |
10826 | Sema &S; |
10827 | CompareTemplateSpecCandidatesForDisplay(Sema &S) : S(S) {} |
10828 | |
10829 | bool operator()(const TemplateSpecCandidate *L, |
10830 | const TemplateSpecCandidate *R) { |
10831 | |
10832 | if (L == R) |
10833 | return false; |
10834 | |
10835 | |
10836 | |
10837 | |
10838 | if (L->DeductionFailure.Result != R->DeductionFailure.Result) |
10839 | return RankDeductionFailure(L->DeductionFailure) < |
10840 | RankDeductionFailure(R->DeductionFailure); |
10841 | |
10842 | |
10843 | SourceLocation LLoc = GetLocationForCandidate(L); |
10844 | SourceLocation RLoc = GetLocationForCandidate(R); |
10845 | |
10846 | |
10847 | if (LLoc.isInvalid()) |
10848 | return false; |
10849 | if (RLoc.isInvalid()) |
10850 | return true; |
10851 | |
10852 | return S.SourceMgr.isBeforeInTranslationUnit(LLoc, RLoc); |
10853 | } |
10854 | }; |
10855 | } |
10856 | |
10857 | |
10858 | |
10859 | |
10860 | void TemplateSpecCandidate::NoteDeductionFailure(Sema &S, |
10861 | bool ForTakingAddress) { |
10862 | DiagnoseBadDeduction(S, FoundDecl, Specialization, |
10863 | DeductionFailure, , ForTakingAddress); |
10864 | } |
10865 | |
10866 | void TemplateSpecCandidateSet::destroyCandidates() { |
10867 | for (iterator i = begin(), e = end(); i != e; ++i) { |
10868 | i->DeductionFailure.Destroy(); |
10869 | } |
10870 | } |
10871 | |
10872 | void TemplateSpecCandidateSet::clear() { |
10873 | destroyCandidates(); |
10874 | Candidates.clear(); |
10875 | } |
10876 | |
10877 | |
10878 | |
10879 | |
10880 | |
10881 | |
10882 | void TemplateSpecCandidateSet::NoteCandidates(Sema &S, SourceLocation Loc) { |
10883 | |
10884 | |
10885 | |
10886 | SmallVector<TemplateSpecCandidate *, 32> Cands; |
10887 | Cands.reserve(size()); |
10888 | for (iterator Cand = begin(), LastCand = end(); Cand != LastCand; ++Cand) { |
10889 | if (Cand->Specialization) |
10890 | Cands.push_back(Cand); |
10891 | |
10892 | |
10893 | } |
10894 | |
10895 | llvm::sort(Cands, CompareTemplateSpecCandidatesForDisplay(S)); |
10896 | |
10897 | |
10898 | |
10899 | const OverloadsShown ShowOverloads = S.Diags.getShowOverloads(); |
10900 | |
10901 | SmallVectorImpl<TemplateSpecCandidate *>::iterator I, E; |
10902 | unsigned CandsShown = 0; |
10903 | for (I = Cands.begin(), E = Cands.end(); I != E; ++I) { |
10904 | TemplateSpecCandidate *Cand = *I; |
10905 | |
10906 | |
10907 | |
10908 | |
10909 | if (CandsShown >= 4 && ShowOverloads == Ovl_Best) |
10910 | break; |
10911 | ++CandsShown; |
10912 | |
10913 | (0) . __assert_fail ("Cand->Specialization && \"Non-matching built-in candidates are not added to Cands.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10914, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Cand->Specialization && |
10914 | (0) . __assert_fail ("Cand->Specialization && \"Non-matching built-in candidates are not added to Cands.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 10914, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Non-matching built-in candidates are not added to Cands."); |
10915 | Cand->NoteDeductionFailure(S, ForTakingAddress); |
10916 | } |
10917 | |
10918 | if (I != E) |
10919 | S.Diag(Loc, diag::note_ovl_too_many_candidates) << int(E - I); |
10920 | } |
10921 | |
10922 | |
10923 | |
10924 | |
10925 | |
10926 | |
10927 | |
10928 | QualType Sema::(QualType PossiblyAFunctionType) { |
10929 | QualType Ret = PossiblyAFunctionType; |
10930 | if (const PointerType *ToTypePtr = |
10931 | PossiblyAFunctionType->getAs<PointerType>()) |
10932 | Ret = ToTypePtr->getPointeeType(); |
10933 | else if (const ReferenceType *ToTypeRef = |
10934 | PossiblyAFunctionType->getAs<ReferenceType>()) |
10935 | Ret = ToTypeRef->getPointeeType(); |
10936 | else if (const MemberPointerType *MemTypePtr = |
10937 | PossiblyAFunctionType->getAs<MemberPointerType>()) |
10938 | Ret = MemTypePtr->getPointeeType(); |
10939 | Ret = |
10940 | Context.getCanonicalType(Ret).getUnqualifiedType(); |
10941 | return Ret; |
10942 | } |
10943 | |
10944 | static bool completeFunctionType(Sema &S, FunctionDecl *FD, SourceLocation Loc, |
10945 | bool Complain = true) { |
10946 | if (S.getLangOpts().CPlusPlus14 && FD->getReturnType()->isUndeducedType() && |
10947 | S.DeduceReturnType(FD, Loc, Complain)) |
10948 | return true; |
10949 | |
10950 | auto *FPT = FD->getType()->castAs<FunctionProtoType>(); |
10951 | if (S.getLangOpts().CPlusPlus17 && |
10952 | isUnresolvedExceptionSpec(FPT->getExceptionSpecType()) && |
10953 | !S.ResolveExceptionSpec(Loc, FPT)) |
10954 | return true; |
10955 | |
10956 | return false; |
10957 | } |
10958 | |
10959 | namespace { |
10960 | |
10961 | |
10962 | class AddressOfFunctionResolver { |
10963 | Sema& S; |
10964 | Expr* SourceExpr; |
10965 | const QualType& TargetType; |
10966 | QualType TargetFunctionType; |
10967 | |
10968 | bool Complain; |
10969 | |
10970 | ASTContext& Context; |
10971 | |
10972 | bool TargetTypeIsNonStaticMemberFunction; |
10973 | bool FoundNonTemplateFunction; |
10974 | bool StaticMemberFunctionFromBoundPointer; |
10975 | bool HasComplained; |
10976 | |
10977 | OverloadExpr::FindResult OvlExprInfo; |
10978 | OverloadExpr *OvlExpr; |
10979 | TemplateArgumentListInfo OvlExplicitTemplateArgs; |
10980 | SmallVector<std::pair<DeclAccessPair, FunctionDecl*>, 4> Matches; |
10981 | TemplateSpecCandidateSet FailedCandidates; |
10982 | |
10983 | public: |
10984 | AddressOfFunctionResolver(Sema &S, Expr *SourceExpr, |
10985 | const QualType &TargetType, bool Complain) |
10986 | : S(S), SourceExpr(SourceExpr), TargetType(TargetType), |
10987 | Complain(Complain), Context(S.getASTContext()), |
10988 | TargetTypeIsNonStaticMemberFunction( |
10989 | !!TargetType->getAs<MemberPointerType>()), |
10990 | FoundNonTemplateFunction(false), |
10991 | StaticMemberFunctionFromBoundPointer(false), |
10992 | HasComplained(false), |
10993 | OvlExprInfo(OverloadExpr::find(SourceExpr)), |
10994 | OvlExpr(OvlExprInfo.Expression), |
10995 | FailedCandidates(OvlExpr->getNameLoc(), ) { |
10996 | ExtractUnqualifiedFunctionTypeFromTargetType(); |
10997 | |
10998 | if (TargetFunctionType->isFunctionType()) { |
10999 | if (UnresolvedMemberExpr *UME = dyn_cast<UnresolvedMemberExpr>(OvlExpr)) |
11000 | if (!UME->isImplicitAccess() && |
11001 | !S.ResolveSingleFunctionTemplateSpecialization(UME)) |
11002 | StaticMemberFunctionFromBoundPointer = true; |
11003 | } else if (OvlExpr->hasExplicitTemplateArgs()) { |
11004 | DeclAccessPair dap; |
11005 | if (FunctionDecl *Fn = S.ResolveSingleFunctionTemplateSpecialization( |
11006 | OvlExpr, false, &dap)) { |
11007 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Fn)) |
11008 | if (!Method->isStatic()) { |
11009 | |
11010 | |
11011 | |
11012 | TargetTypeIsNonStaticMemberFunction = true; |
11013 | |
11014 | |
11015 | |
11016 | if (!OvlExprInfo.HasFormOfMemberPointer) |
11017 | return; |
11018 | } |
11019 | |
11020 | Matches.push_back(std::make_pair(dap, Fn)); |
11021 | } |
11022 | return; |
11023 | } |
11024 | |
11025 | if (OvlExpr->hasExplicitTemplateArgs()) |
11026 | OvlExpr->copyTemplateArgumentsInto(OvlExplicitTemplateArgs); |
11027 | |
11028 | if (FindAllFunctionsThatMatchTargetTypeExactly()) { |
11029 | |
11030 | |
11031 | if (Matches.size() > 1 && !eliminiateSuboptimalOverloadCandidates()) { |
11032 | if (FoundNonTemplateFunction) |
11033 | EliminateAllTemplateMatches(); |
11034 | else |
11035 | EliminateAllExceptMostSpecializedTemplate(); |
11036 | } |
11037 | } |
11038 | |
11039 | if (S.getLangOpts().CUDA && Matches.size() > 1) |
11040 | EliminateSuboptimalCudaMatches(); |
11041 | } |
11042 | |
11043 | bool hasComplained() const { return HasComplained; } |
11044 | |
11045 | private: |
11046 | bool candidateHasExactlyCorrectType(const FunctionDecl *FD) { |
11047 | QualType Discard; |
11048 | return Context.hasSameUnqualifiedType(TargetFunctionType, FD->getType()) || |
11049 | S.IsFunctionConversion(FD->getType(), TargetFunctionType, Discard); |
11050 | } |
11051 | |
11052 | |
11053 | |
11054 | bool isBetterCandidate(const FunctionDecl *A, const FunctionDecl *B) { |
11055 | |
11056 | |
11057 | |
11058 | return candidateHasExactlyCorrectType(A) && |
11059 | (!candidateHasExactlyCorrectType(B) || |
11060 | compareEnableIfAttrs(S, A, B) == Comparison::Better); |
11061 | } |
11062 | |
11063 | |
11064 | |
11065 | bool eliminiateSuboptimalOverloadCandidates() { |
11066 | |
11067 | |
11068 | auto Best = Matches.begin(); |
11069 | for (auto I = Matches.begin()+1, E = Matches.end(); I != E; ++I) |
11070 | if (isBetterCandidate(I->second, Best->second)) |
11071 | Best = I; |
11072 | |
11073 | const FunctionDecl *BestFn = Best->second; |
11074 | auto IsBestOrInferiorToBest = [this, BestFn]( |
11075 | const std::pair<DeclAccessPair, FunctionDecl *> &Pair) { |
11076 | return BestFn == Pair.second || isBetterCandidate(BestFn, Pair.second); |
11077 | }; |
11078 | |
11079 | |
11080 | |
11081 | if (!llvm::all_of(Matches, IsBestOrInferiorToBest)) |
11082 | return false; |
11083 | Matches[0] = *Best; |
11084 | Matches.resize(1); |
11085 | return true; |
11086 | } |
11087 | |
11088 | bool isTargetTypeAFunction() const { |
11089 | return TargetFunctionType->isFunctionType(); |
11090 | } |
11091 | |
11092 | |
11093 | |
11094 | |
11095 | |
11096 | |
11097 | void inline () { |
11098 | TargetFunctionType = S.ExtractUnqualifiedFunctionType(TargetType); |
11099 | } |
11100 | |
11101 | |
11102 | bool AddMatchingTemplateFunction(FunctionTemplateDecl* FunctionTemplate, |
11103 | const DeclAccessPair& CurAccessFunPair) { |
11104 | if (CXXMethodDecl *Method |
11105 | = dyn_cast<CXXMethodDecl>(FunctionTemplate->getTemplatedDecl())) { |
11106 | |
11107 | |
11108 | if (Method->isStatic() == TargetTypeIsNonStaticMemberFunction) |
11109 | return false; |
11110 | } |
11111 | else if (TargetTypeIsNonStaticMemberFunction) |
11112 | return false; |
11113 | |
11114 | |
11115 | |
11116 | |
11117 | |
11118 | |
11119 | |
11120 | FunctionDecl *Specialization = nullptr; |
11121 | TemplateDeductionInfo Info(FailedCandidates.getLocation()); |
11122 | if (Sema::TemplateDeductionResult Result |
11123 | = S.DeduceTemplateArguments(FunctionTemplate, |
11124 | &OvlExplicitTemplateArgs, |
11125 | TargetFunctionType, Specialization, |
11126 | Info, )) { |
11127 | |
11128 | FailedCandidates.addCandidate() |
11129 | .set(CurAccessFunPair, FunctionTemplate->getTemplatedDecl(), |
11130 | MakeDeductionFailureInfo(Context, Result, Info)); |
11131 | return false; |
11132 | } |
11133 | |
11134 | |
11135 | |
11136 | |
11137 | getType()), Context.getCanonicalType(TargetFunctionType))", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11139, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(S.isSameOrCompatibleFunctionType( |
11138 | getType()), Context.getCanonicalType(TargetFunctionType))", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11139, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> Context.getCanonicalType(Specialization->getType()), |
11139 | getType()), Context.getCanonicalType(TargetFunctionType))", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11139, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> Context.getCanonicalType(TargetFunctionType))); |
11140 | |
11141 | if (!S.checkAddressOfFunctionIsAvailable(Specialization)) |
11142 | return false; |
11143 | |
11144 | Matches.push_back(std::make_pair(CurAccessFunPair, Specialization)); |
11145 | return true; |
11146 | } |
11147 | |
11148 | bool AddMatchingNonTemplateFunction(NamedDecl* Fn, |
11149 | const DeclAccessPair& CurAccessFunPair) { |
11150 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Fn)) { |
11151 | |
11152 | |
11153 | if (Method->isStatic() == TargetTypeIsNonStaticMemberFunction) |
11154 | return false; |
11155 | } |
11156 | else if (TargetTypeIsNonStaticMemberFunction) |
11157 | return false; |
11158 | |
11159 | if (FunctionDecl *FunDecl = dyn_cast<FunctionDecl>(Fn)) { |
11160 | if (S.getLangOpts().CUDA) |
11161 | if (FunctionDecl *Caller = dyn_cast<FunctionDecl>(S.CurContext)) |
11162 | if (!Caller->isImplicit() && !S.IsAllowedCUDACall(Caller, FunDecl)) |
11163 | return false; |
11164 | if (FunDecl->isMultiVersion()) { |
11165 | const auto *TA = FunDecl->getAttr<TargetAttr>(); |
11166 | if (TA && !TA->isDefaultVersion()) |
11167 | return false; |
11168 | } |
11169 | |
11170 | |
11171 | |
11172 | if (completeFunctionType(S, FunDecl, SourceExpr->getBeginLoc(), |
11173 | Complain)) { |
11174 | HasComplained |= Complain; |
11175 | return false; |
11176 | } |
11177 | |
11178 | if (!S.checkAddressOfFunctionIsAvailable(FunDecl)) |
11179 | return false; |
11180 | |
11181 | |
11182 | if (!S.getLangOpts().CPlusPlus || |
11183 | candidateHasExactlyCorrectType(FunDecl)) { |
11184 | Matches.push_back(std::make_pair( |
11185 | CurAccessFunPair, cast<FunctionDecl>(FunDecl->getCanonicalDecl()))); |
11186 | FoundNonTemplateFunction = true; |
11187 | return true; |
11188 | } |
11189 | } |
11190 | |
11191 | return false; |
11192 | } |
11193 | |
11194 | bool FindAllFunctionsThatMatchTargetTypeExactly() { |
11195 | bool Ret = false; |
11196 | |
11197 | |
11198 | |
11199 | if (IsInvalidFormOfPointerToMemberFunction()) |
11200 | return false; |
11201 | |
11202 | for (UnresolvedSetIterator I = OvlExpr->decls_begin(), |
11203 | E = OvlExpr->decls_end(); |
11204 | I != E; ++I) { |
11205 | |
11206 | NamedDecl *Fn = (*I)->getUnderlyingDecl(); |
11207 | |
11208 | |
11209 | |
11210 | |
11211 | |
11212 | |
11213 | |
11214 | if (FunctionTemplateDecl *FunctionTemplate |
11215 | = dyn_cast<FunctionTemplateDecl>(Fn)) { |
11216 | if (AddMatchingTemplateFunction(FunctionTemplate, I.getPair())) |
11217 | Ret = true; |
11218 | } |
11219 | |
11220 | else if (!OvlExpr->hasExplicitTemplateArgs() && |
11221 | AddMatchingNonTemplateFunction(Fn, I.getPair())) |
11222 | Ret = true; |
11223 | } |
11224 | assert(Ret || Matches.empty()); |
11225 | return Ret; |
11226 | } |
11227 | |
11228 | void EliminateAllExceptMostSpecializedTemplate() { |
11229 | |
11230 | |
11231 | |
11232 | |
11233 | |
11234 | |
11235 | |
11236 | |
11237 | |
11238 | |
11239 | |
11240 | UnresolvedSet<4> MatchesCopy; |
11241 | for (unsigned I = 0, E = Matches.size(); I != E; ++I) |
11242 | MatchesCopy.addDecl(Matches[I].second, Matches[I].first.getAccess()); |
11243 | |
11244 | |
11245 | |
11246 | UnresolvedSetIterator Result = S.getMostSpecialized( |
11247 | MatchesCopy.begin(), MatchesCopy.end(), FailedCandidates, |
11248 | SourceExpr->getBeginLoc(), S.PDiag(), |
11249 | S.PDiag(diag::err_addr_ovl_ambiguous) |
11250 | << Matches[0].second->getDeclName(), |
11251 | S.PDiag(diag::note_ovl_candidate) |
11252 | << (unsigned)oc_function << (unsigned)ocs_described_template, |
11253 | Complain, TargetFunctionType); |
11254 | |
11255 | if (Result != MatchesCopy.end()) { |
11256 | |
11257 | Matches[0].first = Matches[Result - MatchesCopy.begin()].first; |
11258 | Matches[0].second = cast<FunctionDecl>(*Result); |
11259 | Matches.resize(1); |
11260 | } else |
11261 | HasComplained |= Complain; |
11262 | } |
11263 | |
11264 | void EliminateAllTemplateMatches() { |
11265 | |
11266 | |
11267 | for (unsigned I = 0, N = Matches.size(); I != N; ) { |
11268 | if (Matches[I].second->getPrimaryTemplate() == nullptr) |
11269 | ++I; |
11270 | else { |
11271 | Matches[I] = Matches[--N]; |
11272 | Matches.resize(N); |
11273 | } |
11274 | } |
11275 | } |
11276 | |
11277 | void EliminateSuboptimalCudaMatches() { |
11278 | S.EraseUnwantedCUDAMatches(dyn_cast<FunctionDecl>(S.CurContext), Matches); |
11279 | } |
11280 | |
11281 | public: |
11282 | void ComplainNoMatchesFound() const { |
11283 | assert(Matches.empty()); |
11284 | S.Diag(OvlExpr->getBeginLoc(), diag::err_addr_ovl_no_viable) |
11285 | << OvlExpr->getName() << TargetFunctionType |
11286 | << OvlExpr->getSourceRange(); |
11287 | if (FailedCandidates.empty()) |
11288 | S.NoteAllOverloadCandidates(OvlExpr, TargetFunctionType, |
11289 | ); |
11290 | else { |
11291 | |
11292 | |
11293 | |
11294 | for (UnresolvedSetIterator I = OvlExpr->decls_begin(), |
11295 | IEnd = OvlExpr->decls_end(); |
11296 | I != IEnd; ++I) |
11297 | if (FunctionDecl *Fun = |
11298 | dyn_cast<FunctionDecl>((*I)->getUnderlyingDecl())) |
11299 | if (!functionHasPassObjectSizeParams(Fun)) |
11300 | S.NoteOverloadCandidate(*I, Fun, TargetFunctionType, |
11301 | ); |
11302 | FailedCandidates.NoteCandidates(S, OvlExpr->getBeginLoc()); |
11303 | } |
11304 | } |
11305 | |
11306 | bool IsInvalidFormOfPointerToMemberFunction() const { |
11307 | return TargetTypeIsNonStaticMemberFunction && |
11308 | !OvlExprInfo.HasFormOfMemberPointer; |
11309 | } |
11310 | |
11311 | void ComplainIsInvalidFormOfPointerToMemberFunction() const { |
11312 | |
11313 | |
11314 | |
11315 | S.Diag(OvlExpr->getNameLoc(), diag::err_addr_ovl_no_qualifier) |
11316 | << TargetType << OvlExpr->getSourceRange(); |
11317 | } |
11318 | |
11319 | bool IsStaticMemberFunctionFromBoundPointer() const { |
11320 | return StaticMemberFunctionFromBoundPointer; |
11321 | } |
11322 | |
11323 | void ComplainIsStaticMemberFunctionFromBoundPointer() const { |
11324 | S.Diag(OvlExpr->getBeginLoc(), |
11325 | diag::err_invalid_form_pointer_member_function) |
11326 | << OvlExpr->getSourceRange(); |
11327 | } |
11328 | |
11329 | void ComplainOfInvalidConversion() const { |
11330 | S.Diag(OvlExpr->getBeginLoc(), diag::err_addr_ovl_not_func_ptrref) |
11331 | << OvlExpr->getName() << TargetType; |
11332 | } |
11333 | |
11334 | void ComplainMultipleMatchesFound() const { |
11335 | 1", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11335, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Matches.size() > 1); |
11336 | S.Diag(OvlExpr->getBeginLoc(), diag::err_addr_ovl_ambiguous) |
11337 | << OvlExpr->getName() << OvlExpr->getSourceRange(); |
11338 | S.NoteAllOverloadCandidates(OvlExpr, TargetFunctionType, |
11339 | ); |
11340 | } |
11341 | |
11342 | bool hadMultipleCandidates() const { return (OvlExpr->getNumDecls() > 1); } |
11343 | |
11344 | int getNumMatches() const { return Matches.size(); } |
11345 | |
11346 | FunctionDecl* getMatchingFunctionDecl() const { |
11347 | if (Matches.size() != 1) return nullptr; |
11348 | return Matches[0].second; |
11349 | } |
11350 | |
11351 | const DeclAccessPair* getMatchingFunctionAccessPair() const { |
11352 | if (Matches.size() != 1) return nullptr; |
11353 | return &Matches[0].first; |
11354 | } |
11355 | }; |
11356 | } |
11357 | |
11358 | |
11359 | |
11360 | |
11361 | |
11362 | |
11363 | |
11364 | |
11365 | |
11366 | |
11367 | |
11368 | |
11369 | |
11370 | |
11371 | |
11372 | |
11373 | FunctionDecl * |
11374 | Sema::ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, |
11375 | QualType TargetType, |
11376 | bool Complain, |
11377 | DeclAccessPair &FoundResult, |
11378 | bool *pHadMultipleCandidates) { |
11379 | getType() == Context.OverloadTy", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11379, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(AddressOfExpr->getType() == Context.OverloadTy); |
11380 | |
11381 | AddressOfFunctionResolver Resolver(*this, AddressOfExpr, TargetType, |
11382 | Complain); |
11383 | int NumMatches = Resolver.getNumMatches(); |
11384 | FunctionDecl *Fn = nullptr; |
11385 | bool ShouldComplain = Complain && !Resolver.hasComplained(); |
11386 | if (NumMatches == 0 && ShouldComplain) { |
11387 | if (Resolver.IsInvalidFormOfPointerToMemberFunction()) |
11388 | Resolver.ComplainIsInvalidFormOfPointerToMemberFunction(); |
11389 | else |
11390 | Resolver.ComplainNoMatchesFound(); |
11391 | } |
11392 | else if (NumMatches > 1 && ShouldComplain) |
11393 | Resolver.ComplainMultipleMatchesFound(); |
11394 | else if (NumMatches == 1) { |
11395 | Fn = Resolver.getMatchingFunctionDecl(); |
11396 | assert(Fn); |
11397 | if (auto *FPT = Fn->getType()->getAs<FunctionProtoType>()) |
11398 | ResolveExceptionSpec(AddressOfExpr->getExprLoc(), FPT); |
11399 | FoundResult = *Resolver.getMatchingFunctionAccessPair(); |
11400 | if (Complain) { |
11401 | if (Resolver.IsStaticMemberFunctionFromBoundPointer()) |
11402 | Resolver.ComplainIsStaticMemberFunctionFromBoundPointer(); |
11403 | else |
11404 | CheckAddressOfMemberAccess(AddressOfExpr, FoundResult); |
11405 | } |
11406 | } |
11407 | |
11408 | if (pHadMultipleCandidates) |
11409 | *pHadMultipleCandidates = Resolver.hadMultipleCandidates(); |
11410 | return Fn; |
11411 | } |
11412 | |
11413 | |
11414 | |
11415 | |
11416 | |
11417 | |
11418 | |
11419 | FunctionDecl * |
11420 | Sema::resolveAddressOfOnlyViableOverloadCandidate(Expr *E, |
11421 | DeclAccessPair &Pair) { |
11422 | OverloadExpr::FindResult R = OverloadExpr::find(E); |
11423 | OverloadExpr *Ovl = R.Expression; |
11424 | FunctionDecl *Result = nullptr; |
11425 | DeclAccessPair DAP; |
11426 | |
11427 | |
11428 | |
11429 | for (auto I = Ovl->decls_begin(), E = Ovl->decls_end(); I != E; ++I) { |
11430 | auto *FD = dyn_cast<FunctionDecl>(I->getUnderlyingDecl()); |
11431 | if (!FD) |
11432 | return nullptr; |
11433 | |
11434 | if (!checkAddressOfFunctionIsAvailable(FD)) |
11435 | continue; |
11436 | |
11437 | |
11438 | if (Result) |
11439 | return nullptr; |
11440 | DAP = I.getPair(); |
11441 | Result = FD; |
11442 | } |
11443 | |
11444 | if (Result) |
11445 | Pair = DAP; |
11446 | return Result; |
11447 | } |
11448 | |
11449 | |
11450 | |
11451 | |
11452 | |
11453 | |
11454 | |
11455 | |
11456 | bool Sema::resolveAndFixAddressOfOnlyViableOverloadCandidate( |
11457 | ExprResult &SrcExpr, bool DoFunctionPointerConverion) { |
11458 | Expr *E = SrcExpr.get(); |
11459 | (0) . __assert_fail ("E->getType() == Context.OverloadTy && \"SrcExpr must be an overload\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11459, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(E->getType() == Context.OverloadTy && "SrcExpr must be an overload"); |
11460 | |
11461 | DeclAccessPair DAP; |
11462 | FunctionDecl *Found = resolveAddressOfOnlyViableOverloadCandidate(E, DAP); |
11463 | if (!Found || Found->isCPUDispatchMultiVersion() || |
11464 | Found->isCPUSpecificMultiVersion()) |
11465 | return false; |
11466 | |
11467 | |
11468 | |
11469 | |
11470 | DiagnoseUseOfDecl(Found, E->getExprLoc()); |
11471 | CheckAddressOfMemberAccess(E, DAP); |
11472 | Expr *Fixed = FixOverloadedFunctionReference(E, DAP, Found); |
11473 | if (DoFunctionPointerConverion && Fixed->getType()->isFunctionType()) |
11474 | SrcExpr = DefaultFunctionArrayConversion(Fixed, ); |
11475 | else |
11476 | SrcExpr = Fixed; |
11477 | return true; |
11478 | } |
11479 | |
11480 | |
11481 | |
11482 | |
11483 | |
11484 | |
11485 | |
11486 | |
11487 | |
11488 | |
11489 | |
11490 | FunctionDecl * |
11491 | Sema::ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, |
11492 | bool Complain, |
11493 | DeclAccessPair *FoundResult) { |
11494 | |
11495 | |
11496 | |
11497 | |
11498 | |
11499 | |
11500 | |
11501 | |
11502 | if (!ovl->hasExplicitTemplateArgs()) |
11503 | return nullptr; |
11504 | |
11505 | TemplateArgumentListInfo ExplicitTemplateArgs; |
11506 | ovl->copyTemplateArgumentsInto(ExplicitTemplateArgs); |
11507 | TemplateSpecCandidateSet FailedCandidates(ovl->getNameLoc()); |
11508 | |
11509 | |
11510 | |
11511 | FunctionDecl *Matched = nullptr; |
11512 | for (UnresolvedSetIterator I = ovl->decls_begin(), |
11513 | E = ovl->decls_end(); I != E; ++I) { |
11514 | |
11515 | |
11516 | |
11517 | |
11518 | |
11519 | |
11520 | FunctionTemplateDecl *FunctionTemplate |
11521 | = cast<FunctionTemplateDecl>((*I)->getUnderlyingDecl()); |
11522 | |
11523 | |
11524 | |
11525 | |
11526 | |
11527 | |
11528 | |
11529 | FunctionDecl *Specialization = nullptr; |
11530 | TemplateDeductionInfo Info(FailedCandidates.getLocation()); |
11531 | if (TemplateDeductionResult Result |
11532 | = DeduceTemplateArguments(FunctionTemplate, &ExplicitTemplateArgs, |
11533 | Specialization, Info, |
11534 | )) { |
11535 | |
11536 | |
11537 | FailedCandidates.addCandidate() |
11538 | .set(I.getPair(), FunctionTemplate->getTemplatedDecl(), |
11539 | MakeDeductionFailureInfo(Context, Result, Info)); |
11540 | continue; |
11541 | } |
11542 | |
11543 | (0) . __assert_fail ("Specialization && \"no specialization and no error?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11543, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Specialization && "no specialization and no error?"); |
11544 | |
11545 | |
11546 | if (Matched) { |
11547 | if (Complain) { |
11548 | Diag(ovl->getExprLoc(), diag::err_addr_ovl_ambiguous) |
11549 | << ovl->getName(); |
11550 | NoteAllOverloadCandidates(ovl); |
11551 | } |
11552 | return nullptr; |
11553 | } |
11554 | |
11555 | Matched = Specialization; |
11556 | if (FoundResult) *FoundResult = I.getPair(); |
11557 | } |
11558 | |
11559 | if (Matched && |
11560 | completeFunctionType(*this, Matched, ovl->getExprLoc(), Complain)) |
11561 | return nullptr; |
11562 | |
11563 | return Matched; |
11564 | } |
11565 | |
11566 | |
11567 | |
11568 | |
11569 | |
11570 | |
11571 | |
11572 | |
11573 | |
11574 | bool Sema::ResolveAndFixSingleFunctionTemplateSpecialization( |
11575 | ExprResult &SrcExpr, bool doFunctionPointerConverion, |
11576 | bool complain, SourceRange OpRangeForComplaining, |
11577 | QualType DestTypeForComplaining, |
11578 | unsigned DiagIDForComplaining) { |
11579 | getType() == Context.OverloadTy", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11579, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(SrcExpr.get()->getType() == Context.OverloadTy); |
11580 | |
11581 | OverloadExpr::FindResult ovl = OverloadExpr::find(SrcExpr.get()); |
11582 | |
11583 | DeclAccessPair found; |
11584 | ExprResult SingleFunctionExpression; |
11585 | if (FunctionDecl *fn = ResolveSingleFunctionTemplateSpecialization( |
11586 | ovl.Expression, false, &found)) { |
11587 | if (DiagnoseUseOfDecl(fn, SrcExpr.get()->getBeginLoc())) { |
11588 | SrcExpr = ExprError(); |
11589 | return true; |
11590 | } |
11591 | |
11592 | |
11593 | |
11594 | |
11595 | |
11596 | if (!ovl.HasFormOfMemberPointer && |
11597 | isa<CXXMethodDecl>(fn) && |
11598 | cast<CXXMethodDecl>(fn)->isInstance()) { |
11599 | if (!complain) return false; |
11600 | |
11601 | Diag(ovl.Expression->getExprLoc(), |
11602 | diag::err_bound_member_function) |
11603 | << 0 << ovl.Expression->getSourceRange(); |
11604 | |
11605 | |
11606 | |
11607 | |
11608 | |
11609 | |
11610 | SrcExpr = ExprError(); |
11611 | return true; |
11612 | } |
11613 | |
11614 | |
11615 | SingleFunctionExpression = |
11616 | FixOverloadedFunctionReference(SrcExpr.get(), found, fn); |
11617 | |
11618 | |
11619 | if (doFunctionPointerConverion) { |
11620 | SingleFunctionExpression = |
11621 | DefaultFunctionArrayLvalueConversion(SingleFunctionExpression.get()); |
11622 | if (SingleFunctionExpression.isInvalid()) { |
11623 | SrcExpr = ExprError(); |
11624 | return true; |
11625 | } |
11626 | } |
11627 | } |
11628 | |
11629 | if (!SingleFunctionExpression.isUsable()) { |
11630 | if (complain) { |
11631 | Diag(OpRangeForComplaining.getBegin(), DiagIDForComplaining) |
11632 | << ovl.Expression->getName() |
11633 | << DestTypeForComplaining |
11634 | << OpRangeForComplaining |
11635 | << ovl.Expression->getQualifierLoc().getSourceRange(); |
11636 | NoteAllOverloadCandidates(SrcExpr.get()); |
11637 | |
11638 | SrcExpr = ExprError(); |
11639 | return true; |
11640 | } |
11641 | |
11642 | return false; |
11643 | } |
11644 | |
11645 | SrcExpr = SingleFunctionExpression; |
11646 | return true; |
11647 | } |
11648 | |
11649 | |
11650 | static void AddOverloadedCallCandidate(Sema &S, |
11651 | DeclAccessPair FoundDecl, |
11652 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
11653 | ArrayRef<Expr *> Args, |
11654 | OverloadCandidateSet &CandidateSet, |
11655 | bool PartialOverloading, |
11656 | bool KnownValid) { |
11657 | NamedDecl *Callee = FoundDecl.getDecl(); |
11658 | if (isa<UsingShadowDecl>(Callee)) |
11659 | Callee = cast<UsingShadowDecl>(Callee)->getTargetDecl(); |
11660 | |
11661 | if (FunctionDecl *Func = dyn_cast<FunctionDecl>(Callee)) { |
11662 | if (ExplicitTemplateArgs) { |
11663 | (0) . __assert_fail ("!KnownValid && \"Explicit template arguments?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11663, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!KnownValid && "Explicit template arguments?"); |
11664 | return; |
11665 | } |
11666 | |
11667 | if (!dyn_cast<FunctionProtoType>(Func->getType()->getAs<FunctionType>())) |
11668 | return; |
11669 | |
11670 | S.AddOverloadCandidate(Func, FoundDecl, Args, CandidateSet, |
11671 | , |
11672 | PartialOverloading); |
11673 | return; |
11674 | } |
11675 | |
11676 | if (FunctionTemplateDecl *FuncTemplate |
11677 | = dyn_cast<FunctionTemplateDecl>(Callee)) { |
11678 | S.AddTemplateOverloadCandidate(FuncTemplate, FoundDecl, |
11679 | ExplicitTemplateArgs, Args, CandidateSet, |
11680 | , |
11681 | PartialOverloading); |
11682 | return; |
11683 | } |
11684 | |
11685 | (0) . __assert_fail ("!KnownValid && \"unhandled case in overloaded call candidate\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11685, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!KnownValid && "unhandled case in overloaded call candidate"); |
11686 | } |
11687 | |
11688 | |
11689 | |
11690 | void Sema::AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, |
11691 | ArrayRef<Expr *> Args, |
11692 | OverloadCandidateSet &CandidateSet, |
11693 | bool PartialOverloading) { |
11694 | |
11695 | #ifndef NDEBUG |
11696 | |
11697 | |
11698 | |
11699 | |
11700 | |
11701 | |
11702 | |
11703 | |
11704 | |
11705 | |
11706 | |
11707 | |
11708 | |
11709 | |
11710 | |
11711 | |
11712 | |
11713 | if (ULE->requiresADL()) { |
11714 | for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(), |
11715 | E = ULE->decls_end(); I != E; ++I) { |
11716 | getDeclContext()->isRecord()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11716, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!(*I)->getDeclContext()->isRecord()); |
11717 | (*I) || !(*I)->getDeclContext()->isFunctionOrMethod()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11718, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<UsingShadowDecl>(*I) || |
11718 | (*I) || !(*I)->getDeclContext()->isFunctionOrMethod()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11718, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> !(*I)->getDeclContext()->isFunctionOrMethod()); |
11719 | getUnderlyingDecl()->isFunctionOrFunctionTemplate()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11719, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((*I)->getUnderlyingDecl()->isFunctionOrFunctionTemplate()); |
11720 | } |
11721 | } |
11722 | #endif |
11723 | |
11724 | |
11725 | TemplateArgumentListInfo TABuffer; |
11726 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr; |
11727 | if (ULE->hasExplicitTemplateArgs()) { |
11728 | ULE->copyTemplateArgumentsInto(TABuffer); |
11729 | ExplicitTemplateArgs = &TABuffer; |
11730 | } |
11731 | |
11732 | for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(), |
11733 | E = ULE->decls_end(); I != E; ++I) |
11734 | AddOverloadedCallCandidate(*this, I.getPair(), ExplicitTemplateArgs, Args, |
11735 | CandidateSet, PartialOverloading, |
11736 | true); |
11737 | |
11738 | if (ULE->requiresADL()) |
11739 | AddArgumentDependentLookupCandidates(ULE->getName(), ULE->getExprLoc(), |
11740 | Args, ExplicitTemplateArgs, |
11741 | CandidateSet, PartialOverloading); |
11742 | } |
11743 | |
11744 | |
11745 | |
11746 | static bool canBeDeclaredInNamespace(const DeclarationName &Name) { |
11747 | switch (Name.getCXXOverloadedOperator()) { |
11748 | case OO_New: case OO_Array_New: |
11749 | case OO_Delete: case OO_Array_Delete: |
11750 | return false; |
11751 | |
11752 | default: |
11753 | return true; |
11754 | } |
11755 | } |
11756 | |
11757 | |
11758 | |
11759 | |
11760 | |
11761 | |
11762 | |
11763 | static bool |
11764 | DiagnoseTwoPhaseLookup(Sema &SemaRef, SourceLocation FnLoc, |
11765 | const CXXScopeSpec &SS, LookupResult &R, |
11766 | OverloadCandidateSet::CandidateSetKind CSK, |
11767 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
11768 | ArrayRef<Expr *> Args, |
11769 | bool *DoDiagnoseEmptyLookup = nullptr) { |
11770 | if (!SemaRef.inTemplateInstantiation() || !SS.isEmpty()) |
11771 | return false; |
11772 | |
11773 | for (DeclContext *DC = SemaRef.CurContext; DC; DC = DC->getParent()) { |
11774 | if (DC->isTransparentContext()) |
11775 | continue; |
11776 | |
11777 | SemaRef.LookupQualifiedName(R, DC); |
11778 | |
11779 | if (!R.empty()) { |
11780 | R.suppressDiagnostics(); |
11781 | |
11782 | if (isa<CXXRecordDecl>(DC)) { |
11783 | |
11784 | |
11785 | R.clear(); |
11786 | if (DoDiagnoseEmptyLookup) |
11787 | *DoDiagnoseEmptyLookup = true; |
11788 | return false; |
11789 | } |
11790 | |
11791 | OverloadCandidateSet Candidates(FnLoc, CSK); |
11792 | for (LookupResult::iterator I = R.begin(), E = R.end(); I != E; ++I) |
11793 | AddOverloadedCallCandidate(SemaRef, I.getPair(), |
11794 | ExplicitTemplateArgs, Args, |
11795 | Candidates, false, false); |
11796 | |
11797 | OverloadCandidateSet::iterator Best; |
11798 | if (Candidates.BestViableFunction(SemaRef, FnLoc, Best) != OR_Success) { |
11799 | |
11800 | |
11801 | R.clear(); |
11802 | return false; |
11803 | } |
11804 | |
11805 | |
11806 | |
11807 | Sema::AssociatedNamespaceSet AssociatedNamespaces; |
11808 | Sema::AssociatedClassSet AssociatedClasses; |
11809 | SemaRef.FindAssociatedClassesAndNamespaces(FnLoc, Args, |
11810 | AssociatedNamespaces, |
11811 | AssociatedClasses); |
11812 | Sema::AssociatedNamespaceSet SuggestedNamespaces; |
11813 | if (canBeDeclaredInNamespace(R.getLookupName())) { |
11814 | DeclContext *Std = SemaRef.getStdNamespace(); |
11815 | for (Sema::AssociatedNamespaceSet::iterator |
11816 | it = AssociatedNamespaces.begin(), |
11817 | end = AssociatedNamespaces.end(); it != end; ++it) { |
11818 | |
11819 | if (Std && Std->Encloses(*it)) |
11820 | continue; |
11821 | |
11822 | |
11823 | |
11824 | NamespaceDecl *NS = dyn_cast<NamespaceDecl>(*it); |
11825 | if (NS && |
11826 | NS->getQualifiedNameAsString().find("__") != std::string::npos) |
11827 | continue; |
11828 | |
11829 | SuggestedNamespaces.insert(*it); |
11830 | } |
11831 | } |
11832 | |
11833 | SemaRef.Diag(R.getNameLoc(), diag::err_not_found_by_two_phase_lookup) |
11834 | << R.getLookupName(); |
11835 | if (SuggestedNamespaces.empty()) { |
11836 | SemaRef.Diag(Best->Function->getLocation(), |
11837 | diag::note_not_found_by_two_phase_lookup) |
11838 | << R.getLookupName() << 0; |
11839 | } else if (SuggestedNamespaces.size() == 1) { |
11840 | SemaRef.Diag(Best->Function->getLocation(), |
11841 | diag::note_not_found_by_two_phase_lookup) |
11842 | << R.getLookupName() << 1 << *SuggestedNamespaces.begin(); |
11843 | } else { |
11844 | |
11845 | |
11846 | |
11847 | SemaRef.Diag(Best->Function->getLocation(), |
11848 | diag::note_not_found_by_two_phase_lookup) |
11849 | << R.getLookupName() << 2; |
11850 | } |
11851 | |
11852 | |
11853 | return true; |
11854 | } |
11855 | |
11856 | R.clear(); |
11857 | } |
11858 | |
11859 | return false; |
11860 | } |
11861 | |
11862 | |
11863 | |
11864 | |
11865 | |
11866 | |
11867 | static bool |
11868 | DiagnoseTwoPhaseOperatorLookup(Sema &SemaRef, OverloadedOperatorKind Op, |
11869 | SourceLocation OpLoc, |
11870 | ArrayRef<Expr *> Args) { |
11871 | DeclarationName OpName = |
11872 | SemaRef.Context.DeclarationNames.getCXXOperatorName(Op); |
11873 | LookupResult R(SemaRef, OpName, OpLoc, Sema::LookupOperatorName); |
11874 | return DiagnoseTwoPhaseLookup(SemaRef, OpLoc, CXXScopeSpec(), R, |
11875 | OverloadCandidateSet::CSK_Operator, |
11876 | , Args); |
11877 | } |
11878 | |
11879 | namespace { |
11880 | class BuildRecoveryCallExprRAII { |
11881 | Sema &SemaRef; |
11882 | public: |
11883 | BuildRecoveryCallExprRAII(Sema &S) : SemaRef(S) { |
11884 | assert(SemaRef.IsBuildingRecoveryCallExpr == false); |
11885 | SemaRef.IsBuildingRecoveryCallExpr = true; |
11886 | } |
11887 | |
11888 | ~BuildRecoveryCallExprRAII() { |
11889 | SemaRef.IsBuildingRecoveryCallExpr = false; |
11890 | } |
11891 | }; |
11892 | |
11893 | } |
11894 | |
11895 | |
11896 | |
11897 | |
11898 | static ExprResult |
11899 | BuildRecoveryCallExpr(Sema &SemaRef, Scope *S, Expr *Fn, |
11900 | UnresolvedLookupExpr *ULE, |
11901 | SourceLocation LParenLoc, |
11902 | MutableArrayRef<Expr *> Args, |
11903 | SourceLocation RParenLoc, |
11904 | bool EmptyLookup, bool AllowTypoCorrection) { |
11905 | |
11906 | |
11907 | |
11908 | |
11909 | |
11910 | |
11911 | if (SemaRef.IsBuildingRecoveryCallExpr) |
11912 | return ExprError(); |
11913 | BuildRecoveryCallExprRAII RCE(SemaRef); |
11914 | |
11915 | CXXScopeSpec SS; |
11916 | SS.Adopt(ULE->getQualifierLoc()); |
11917 | SourceLocation TemplateKWLoc = ULE->getTemplateKeywordLoc(); |
11918 | |
11919 | TemplateArgumentListInfo TABuffer; |
11920 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr; |
11921 | if (ULE->hasExplicitTemplateArgs()) { |
11922 | ULE->copyTemplateArgumentsInto(TABuffer); |
11923 | ExplicitTemplateArgs = &TABuffer; |
11924 | } |
11925 | |
11926 | LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(), |
11927 | Sema::LookupOrdinaryName); |
11928 | bool DoDiagnoseEmptyLookup = EmptyLookup; |
11929 | if (!DiagnoseTwoPhaseLookup( |
11930 | SemaRef, Fn->getExprLoc(), SS, R, OverloadCandidateSet::CSK_Normal, |
11931 | ExplicitTemplateArgs, Args, &DoDiagnoseEmptyLookup)) { |
11932 | NoTypoCorrectionCCC NoTypoValidator{}; |
11933 | FunctionCallFilterCCC FunctionCallValidator(SemaRef, Args.size(), |
11934 | ExplicitTemplateArgs != nullptr, |
11935 | dyn_cast<MemberExpr>(Fn)); |
11936 | CorrectionCandidateCallback &Validator = |
11937 | AllowTypoCorrection |
11938 | ? static_cast<CorrectionCandidateCallback &>(FunctionCallValidator) |
11939 | : static_cast<CorrectionCandidateCallback &>(NoTypoValidator); |
11940 | if (!DoDiagnoseEmptyLookup || |
11941 | SemaRef.DiagnoseEmptyLookup(S, SS, R, Validator, ExplicitTemplateArgs, |
11942 | Args)) |
11943 | return ExprError(); |
11944 | } |
11945 | |
11946 | (0) . __assert_fail ("!R.empty() && \"lookup results empty despite recovery\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11946, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!R.empty() && "lookup results empty despite recovery"); |
11947 | |
11948 | |
11949 | if (R.isAmbiguous()) { |
11950 | R.suppressDiagnostics(); |
11951 | return ExprError(); |
11952 | } |
11953 | |
11954 | |
11955 | |
11956 | ExprResult NewFn = ExprError(); |
11957 | if ((*R.begin())->isCXXClassMember()) |
11958 | NewFn = SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R, |
11959 | ExplicitTemplateArgs, S); |
11960 | else if (ExplicitTemplateArgs || TemplateKWLoc.isValid()) |
11961 | NewFn = SemaRef.BuildTemplateIdExpr(SS, TemplateKWLoc, R, false, |
11962 | ExplicitTemplateArgs); |
11963 | else |
11964 | NewFn = SemaRef.BuildDeclarationNameExpr(SS, R, false); |
11965 | |
11966 | if (NewFn.isInvalid()) |
11967 | return ExprError(); |
11968 | |
11969 | |
11970 | |
11971 | |
11972 | return SemaRef.ActOnCallExpr( nullptr, NewFn.get(), LParenLoc, |
11973 | MultiExprArg(Args.data(), Args.size()), |
11974 | RParenLoc); |
11975 | } |
11976 | |
11977 | |
11978 | |
11979 | |
11980 | bool Sema::buildOverloadedCallSet(Scope *S, Expr *Fn, |
11981 | UnresolvedLookupExpr *ULE, |
11982 | MultiExprArg Args, |
11983 | SourceLocation RParenLoc, |
11984 | OverloadCandidateSet *CandidateSet, |
11985 | ExprResult *Result) { |
11986 | #ifndef NDEBUG |
11987 | if (ULE->requiresADL()) { |
11988 | |
11989 | (0) . __assert_fail ("!ULE->getQualifier() && \"qualified name with ADL\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 11989, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!ULE->getQualifier() && "qualified name with ADL"); |
11990 | |
11991 | |
11992 | |
11993 | FunctionDecl *F; |
11994 | if (ULE->decls_begin() + 1 == ULE->decls_end() && |
11995 | (F = dyn_cast<FunctionDecl>(*ULE->decls_begin())) && |
11996 | F->getBuiltinID() && F->isImplicit()) |
11997 | llvm_unreachable("performing ADL for builtin"); |
11998 | |
11999 | |
12000 | (0) . __assert_fail ("getLangOpts().CPlusPlus && \"ADL enabled in C\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 12000, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(getLangOpts().CPlusPlus && "ADL enabled in C"); |
12001 | } |
12002 | #endif |
12003 | |
12004 | UnbridgedCastsSet UnbridgedCasts; |
12005 | if (checkArgPlaceholdersForOverload(*this, Args, UnbridgedCasts)) { |
12006 | *Result = ExprError(); |
12007 | return true; |
12008 | } |
12009 | |
12010 | |
12011 | |
12012 | AddOverloadedCallCandidates(ULE, Args, *CandidateSet); |
12013 | |
12014 | if (getLangOpts().MSVCCompat && |
12015 | CurContext->isDependentContext() && !isSFINAEContext() && |
12016 | (isa<FunctionDecl>(CurContext) || isa<CXXRecordDecl>(CurContext))) { |
12017 | |
12018 | OverloadCandidateSet::iterator Best; |
12019 | if (CandidateSet->empty() || |
12020 | CandidateSet->BestViableFunction(*this, Fn->getBeginLoc(), Best) == |
12021 | OR_No_Viable_Function) { |
12022 | |
12023 | |
12024 | |
12025 | |
12026 | CallExpr *CE = CallExpr::Create(Context, Fn, Args, Context.DependentTy, |
12027 | VK_RValue, RParenLoc); |
12028 | CE->setTypeDependent(true); |
12029 | CE->setValueDependent(true); |
12030 | CE->setInstantiationDependent(true); |
12031 | *Result = CE; |
12032 | return true; |
12033 | } |
12034 | } |
12035 | |
12036 | if (CandidateSet->empty()) |
12037 | return false; |
12038 | |
12039 | UnbridgedCasts.restore(); |
12040 | return false; |
12041 | } |
12042 | |
12043 | |
12044 | |
12045 | |
12046 | static ExprResult FinishOverloadedCallExpr(Sema &SemaRef, Scope *S, Expr *Fn, |
12047 | UnresolvedLookupExpr *ULE, |
12048 | SourceLocation LParenLoc, |
12049 | MultiExprArg Args, |
12050 | SourceLocation RParenLoc, |
12051 | Expr *ExecConfig, |
12052 | OverloadCandidateSet *CandidateSet, |
12053 | OverloadCandidateSet::iterator *Best, |
12054 | OverloadingResult OverloadResult, |
12055 | bool AllowTypoCorrection) { |
12056 | if (CandidateSet->empty()) |
12057 | return BuildRecoveryCallExpr(SemaRef, S, Fn, ULE, LParenLoc, Args, |
12058 | RParenLoc, , |
12059 | AllowTypoCorrection); |
12060 | |
12061 | switch (OverloadResult) { |
12062 | case OR_Success: { |
12063 | FunctionDecl *FDecl = (*Best)->Function; |
12064 | SemaRef.CheckUnresolvedLookupAccess(ULE, (*Best)->FoundDecl); |
12065 | if (SemaRef.DiagnoseUseOfDecl(FDecl, ULE->getNameLoc())) |
12066 | return ExprError(); |
12067 | Fn = SemaRef.FixOverloadedFunctionReference(Fn, (*Best)->FoundDecl, FDecl); |
12068 | return SemaRef.BuildResolvedCallExpr(Fn, FDecl, LParenLoc, Args, RParenLoc, |
12069 | ExecConfig, , |
12070 | (*Best)->IsADLCandidate); |
12071 | } |
12072 | |
12073 | case OR_No_Viable_Function: { |
12074 | |
12075 | |
12076 | ExprResult Recovery = BuildRecoveryCallExpr(SemaRef, S, Fn, ULE, LParenLoc, |
12077 | Args, RParenLoc, |
12078 | , |
12079 | AllowTypoCorrection); |
12080 | if (!Recovery.isInvalid()) |
12081 | return Recovery; |
12082 | |
12083 | |
12084 | |
12085 | |
12086 | for (const Expr *Arg : Args) { |
12087 | if (!Arg->getType()->isFunctionType()) |
12088 | continue; |
12089 | if (auto *DRE = dyn_cast<DeclRefExpr>(Arg->IgnoreParenImpCasts())) { |
12090 | auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()); |
12091 | if (FD && |
12092 | !SemaRef.checkAddressOfFunctionIsAvailable(FD, , |
12093 | Arg->getExprLoc())) |
12094 | return ExprError(); |
12095 | } |
12096 | } |
12097 | |
12098 | SemaRef.Diag(Fn->getBeginLoc(), diag::err_ovl_no_viable_function_in_call) |
12099 | << ULE->getName() << Fn->getSourceRange(); |
12100 | CandidateSet->NoteCandidates(SemaRef, OCD_AllCandidates, Args); |
12101 | break; |
12102 | } |
12103 | |
12104 | case OR_Ambiguous: |
12105 | SemaRef.Diag(Fn->getBeginLoc(), diag::err_ovl_ambiguous_call) |
12106 | << ULE->getName() << Fn->getSourceRange(); |
12107 | CandidateSet->NoteCandidates(SemaRef, OCD_ViableCandidates, Args); |
12108 | break; |
12109 | |
12110 | case OR_Deleted: { |
12111 | SemaRef.Diag(Fn->getBeginLoc(), diag::err_ovl_deleted_call) |
12112 | << ULE->getName() << Fn->getSourceRange(); |
12113 | CandidateSet->NoteCandidates(SemaRef, OCD_AllCandidates, Args); |
12114 | |
12115 | |
12116 | |
12117 | FunctionDecl *FDecl = (*Best)->Function; |
12118 | Fn = SemaRef.FixOverloadedFunctionReference(Fn, (*Best)->FoundDecl, FDecl); |
12119 | return SemaRef.BuildResolvedCallExpr(Fn, FDecl, LParenLoc, Args, RParenLoc, |
12120 | ExecConfig, , |
12121 | (*Best)->IsADLCandidate); |
12122 | } |
12123 | } |
12124 | |
12125 | |
12126 | return ExprError(); |
12127 | } |
12128 | |
12129 | static void markUnaddressableCandidatesUnviable(Sema &S, |
12130 | OverloadCandidateSet &CS) { |
12131 | for (auto I = CS.begin(), E = CS.end(); I != E; ++I) { |
12132 | if (I->Viable && |
12133 | !S.checkAddressOfFunctionIsAvailable(I->Function, )) { |
12134 | I->Viable = false; |
12135 | I->FailureKind = ovl_fail_addr_not_available; |
12136 | } |
12137 | } |
12138 | } |
12139 | |
12140 | |
12141 | |
12142 | |
12143 | |
12144 | |
12145 | |
12146 | ExprResult Sema::BuildOverloadedCallExpr(Scope *S, Expr *Fn, |
12147 | UnresolvedLookupExpr *ULE, |
12148 | SourceLocation LParenLoc, |
12149 | MultiExprArg Args, |
12150 | SourceLocation RParenLoc, |
12151 | Expr *ExecConfig, |
12152 | bool AllowTypoCorrection, |
12153 | bool CalleesAddressIsTaken) { |
12154 | OverloadCandidateSet CandidateSet(Fn->getExprLoc(), |
12155 | OverloadCandidateSet::CSK_Normal); |
12156 | ExprResult result; |
12157 | |
12158 | if (buildOverloadedCallSet(S, Fn, ULE, Args, LParenLoc, &CandidateSet, |
12159 | &result)) |
12160 | return result; |
12161 | |
12162 | |
12163 | |
12164 | if (CalleesAddressIsTaken) |
12165 | markUnaddressableCandidatesUnviable(*this, CandidateSet); |
12166 | |
12167 | OverloadCandidateSet::iterator Best; |
12168 | OverloadingResult OverloadResult = |
12169 | CandidateSet.BestViableFunction(*this, Fn->getBeginLoc(), Best); |
12170 | |
12171 | return FinishOverloadedCallExpr(*this, S, Fn, ULE, LParenLoc, Args, |
12172 | RParenLoc, ExecConfig, &CandidateSet, |
12173 | &Best, OverloadResult, |
12174 | AllowTypoCorrection); |
12175 | } |
12176 | |
12177 | static bool IsOverloaded(const UnresolvedSetImpl &Functions) { |
12178 | return Functions.size() > 1 || |
12179 | (Functions.size() == 1 && isa<FunctionTemplateDecl>(*Functions.begin())); |
12180 | } |
12181 | |
12182 | |
12183 | |
12184 | |
12185 | |
12186 | |
12187 | |
12188 | |
12189 | |
12190 | |
12191 | |
12192 | |
12193 | |
12194 | |
12195 | |
12196 | |
12197 | ExprResult |
12198 | Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, |
12199 | const UnresolvedSetImpl &Fns, |
12200 | Expr *Input, bool PerformADL) { |
12201 | OverloadedOperatorKind Op = UnaryOperator::getOverloadedOperator(Opc); |
12202 | (0) . __assert_fail ("Op != OO_None && \"Invalid opcode for overloaded unary operator\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 12202, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Op != OO_None && "Invalid opcode for overloaded unary operator"); |
12203 | DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(Op); |
12204 | |
12205 | DeclarationNameInfo OpNameInfo(OpName, OpLoc); |
12206 | |
12207 | if (checkPlaceholderForOverload(*this, Input)) |
12208 | return ExprError(); |
12209 | |
12210 | Expr *Args[2] = { Input, nullptr }; |
12211 | unsigned NumArgs = 1; |
12212 | |
12213 | |
12214 | |
12215 | |
12216 | if (Opc == UO_PostInc || Opc == UO_PostDec) { |
12217 | llvm::APSInt Zero(Context.getTypeSize(Context.IntTy), false); |
12218 | Args[1] = IntegerLiteral::Create(Context, Zero, Context.IntTy, |
12219 | SourceLocation()); |
12220 | NumArgs = 2; |
12221 | } |
12222 | |
12223 | ArrayRef<Expr *> ArgsArray(Args, NumArgs); |
12224 | |
12225 | if (Input->isTypeDependent()) { |
12226 | if (Fns.empty()) |
12227 | return new (Context) UnaryOperator(Input, Opc, Context.DependentTy, |
12228 | VK_RValue, OK_Ordinary, OpLoc, false); |
12229 | |
12230 | CXXRecordDecl *NamingClass = nullptr; |
12231 | UnresolvedLookupExpr *Fn = UnresolvedLookupExpr::Create( |
12232 | Context, NamingClass, NestedNameSpecifierLoc(), OpNameInfo, |
12233 | true, IsOverloaded(Fns), Fns.begin(), Fns.end()); |
12234 | return CXXOperatorCallExpr::Create(Context, Op, Fn, ArgsArray, |
12235 | Context.DependentTy, VK_RValue, OpLoc, |
12236 | FPOptions()); |
12237 | } |
12238 | |
12239 | |
12240 | OverloadCandidateSet CandidateSet(OpLoc, OverloadCandidateSet::CSK_Operator); |
12241 | |
12242 | |
12243 | AddFunctionCandidates(Fns, ArgsArray, CandidateSet); |
12244 | |
12245 | |
12246 | AddMemberOperatorCandidates(Op, OpLoc, ArgsArray, CandidateSet); |
12247 | |
12248 | |
12249 | if (PerformADL) { |
12250 | AddArgumentDependentLookupCandidates(OpName, OpLoc, ArgsArray, |
12251 | , |
12252 | CandidateSet); |
12253 | } |
12254 | |
12255 | |
12256 | AddBuiltinOperatorCandidates(Op, OpLoc, ArgsArray, CandidateSet); |
12257 | |
12258 | bool HadMultipleCandidates = (CandidateSet.size() > 1); |
12259 | |
12260 | |
12261 | OverloadCandidateSet::iterator Best; |
12262 | switch (CandidateSet.BestViableFunction(*this, OpLoc, Best)) { |
12263 | case OR_Success: { |
12264 | |
12265 | FunctionDecl *FnDecl = Best->Function; |
12266 | |
12267 | if (FnDecl) { |
12268 | Expr *Base = nullptr; |
12269 | |
12270 | |
12271 | |
12272 | |
12273 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FnDecl)) { |
12274 | CheckMemberOperatorAccess(OpLoc, Args[0], nullptr, Best->FoundDecl); |
12275 | |
12276 | ExprResult InputRes = |
12277 | PerformObjectArgumentInitialization(Input, , |
12278 | Best->FoundDecl, Method); |
12279 | if (InputRes.isInvalid()) |
12280 | return ExprError(); |
12281 | Base = Input = InputRes.get(); |
12282 | } else { |
12283 | |
12284 | ExprResult InputInit |
12285 | = PerformCopyInitialization(InitializedEntity::InitializeParameter( |
12286 | Context, |
12287 | FnDecl->getParamDecl(0)), |
12288 | SourceLocation(), |
12289 | Input); |
12290 | if (InputInit.isInvalid()) |
12291 | return ExprError(); |
12292 | Input = InputInit.get(); |
12293 | } |
12294 | |
12295 | |
12296 | ExprResult FnExpr = CreateFunctionRefExpr(*this, FnDecl, Best->FoundDecl, |
12297 | Base, HadMultipleCandidates, |
12298 | OpLoc); |
12299 | if (FnExpr.isInvalid()) |
12300 | return ExprError(); |
12301 | |
12302 | |
12303 | QualType ResultTy = FnDecl->getReturnType(); |
12304 | ExprValueKind VK = Expr::getValueKindForType(ResultTy); |
12305 | ResultTy = ResultTy.getNonLValueExprType(Context); |
12306 | |
12307 | Args[0] = Input; |
12308 | CallExpr *TheCall = CXXOperatorCallExpr::Create( |
12309 | Context, Op, FnExpr.get(), ArgsArray, ResultTy, VK, OpLoc, |
12310 | FPOptions(), Best->IsADLCandidate); |
12311 | |
12312 | if (CheckCallReturnType(FnDecl->getReturnType(), OpLoc, TheCall, FnDecl)) |
12313 | return ExprError(); |
12314 | |
12315 | if (CheckFunctionCall(FnDecl, TheCall, |
12316 | FnDecl->getType()->castAs<FunctionProtoType>())) |
12317 | return ExprError(); |
12318 | |
12319 | return MaybeBindToTemporary(TheCall); |
12320 | } else { |
12321 | |
12322 | |
12323 | |
12324 | ExprResult InputRes = PerformImplicitConversion( |
12325 | Input, Best->BuiltinParamTypes[0], Best->Conversions[0], AA_Passing, |
12326 | CCK_ForBuiltinOverloadedOp); |
12327 | if (InputRes.isInvalid()) |
12328 | return ExprError(); |
12329 | Input = InputRes.get(); |
12330 | break; |
12331 | } |
12332 | } |
12333 | |
12334 | case OR_No_Viable_Function: |
12335 | |
12336 | |
12337 | |
12338 | if (DiagnoseTwoPhaseOperatorLookup(*this, Op, OpLoc, ArgsArray)) |
12339 | |
12340 | return ExprError(); |
12341 | |
12342 | |
12343 | |
12344 | break; |
12345 | |
12346 | case OR_Ambiguous: |
12347 | Diag(OpLoc, diag::err_ovl_ambiguous_oper_unary) |
12348 | << UnaryOperator::getOpcodeStr(Opc) |
12349 | << Input->getType() |
12350 | << Input->getSourceRange(); |
12351 | CandidateSet.NoteCandidates(*this, OCD_ViableCandidates, ArgsArray, |
12352 | UnaryOperator::getOpcodeStr(Opc), OpLoc); |
12353 | return ExprError(); |
12354 | |
12355 | case OR_Deleted: |
12356 | Diag(OpLoc, diag::err_ovl_deleted_oper) |
12357 | << UnaryOperator::getOpcodeStr(Opc) << Input->getSourceRange(); |
12358 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, ArgsArray, |
12359 | UnaryOperator::getOpcodeStr(Opc), OpLoc); |
12360 | return ExprError(); |
12361 | } |
12362 | |
12363 | |
12364 | |
12365 | |
12366 | return CreateBuiltinUnaryOp(OpLoc, Opc, Input); |
12367 | } |
12368 | |
12369 | |
12370 | |
12371 | |
12372 | |
12373 | |
12374 | |
12375 | |
12376 | |
12377 | |
12378 | |
12379 | |
12380 | |
12381 | |
12382 | |
12383 | |
12384 | |
12385 | ExprResult |
12386 | Sema::CreateOverloadedBinOp(SourceLocation OpLoc, |
12387 | BinaryOperatorKind Opc, |
12388 | const UnresolvedSetImpl &Fns, |
12389 | Expr *LHS, Expr *RHS, bool PerformADL) { |
12390 | Expr *Args[2] = { LHS, RHS }; |
12391 | LHS=RHS=nullptr; |
12392 | |
12393 | OverloadedOperatorKind Op = BinaryOperator::getOverloadedOperator(Opc); |
12394 | DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(Op); |
12395 | |
12396 | |
12397 | |
12398 | if (Args[0]->isTypeDependent() || Args[1]->isTypeDependent()) { |
12399 | if (Fns.empty()) { |
12400 | |
12401 | |
12402 | if (Opc <= BO_Assign || Opc > BO_OrAssign) |
12403 | return new (Context) BinaryOperator( |
12404 | Args[0], Args[1], Opc, Context.DependentTy, VK_RValue, OK_Ordinary, |
12405 | OpLoc, FPFeatures); |
12406 | |
12407 | return new (Context) CompoundAssignOperator( |
12408 | Args[0], Args[1], Opc, Context.DependentTy, VK_LValue, OK_Ordinary, |
12409 | Context.DependentTy, Context.DependentTy, OpLoc, |
12410 | FPFeatures); |
12411 | } |
12412 | |
12413 | |
12414 | CXXRecordDecl *NamingClass = nullptr; |
12415 | |
12416 | DeclarationNameInfo OpNameInfo(OpName, OpLoc); |
12417 | UnresolvedLookupExpr *Fn = UnresolvedLookupExpr::Create( |
12418 | Context, NamingClass, NestedNameSpecifierLoc(), OpNameInfo, |
12419 | PerformADL, IsOverloaded(Fns), Fns.begin(), Fns.end()); |
12420 | return CXXOperatorCallExpr::Create(Context, Op, Fn, Args, |
12421 | Context.DependentTy, VK_RValue, OpLoc, |
12422 | FPFeatures); |
12423 | } |
12424 | |
12425 | |
12426 | if (checkPlaceholderForOverload(*this, Args[1])) |
12427 | return ExprError(); |
12428 | |
12429 | |
12430 | |
12431 | getObjectKind() != OK_ObjCProperty", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 12431, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Args[0]->getObjectKind() != OK_ObjCProperty); |
12432 | if (checkPlaceholderForOverload(*this, Args[0])) |
12433 | return ExprError(); |
12434 | |
12435 | |
12436 | |
12437 | |
12438 | |
12439 | |
12440 | |
12441 | if (Opc == BO_Assign && !Args[0]->getType()->isOverloadableType()) |
12442 | return CreateBuiltinBinOp(OpLoc, Opc, Args[0], Args[1]); |
12443 | |
12444 | |
12445 | |
12446 | if (Opc == BO_PtrMemD) |
12447 | return CreateBuiltinBinOp(OpLoc, Opc, Args[0], Args[1]); |
12448 | |
12449 | |
12450 | OverloadCandidateSet CandidateSet(OpLoc, OverloadCandidateSet::CSK_Operator); |
12451 | |
12452 | |
12453 | AddFunctionCandidates(Fns, Args, CandidateSet); |
12454 | |
12455 | |
12456 | AddMemberOperatorCandidates(Op, OpLoc, Args, CandidateSet); |
12457 | |
12458 | |
12459 | |
12460 | |
12461 | if (Opc != BO_Assign && PerformADL) |
12462 | AddArgumentDependentLookupCandidates(OpName, OpLoc, Args, |
12463 | nullptr, |
12464 | CandidateSet); |
12465 | |
12466 | |
12467 | AddBuiltinOperatorCandidates(Op, OpLoc, Args, CandidateSet); |
12468 | |
12469 | bool HadMultipleCandidates = (CandidateSet.size() > 1); |
12470 | |
12471 | |
12472 | OverloadCandidateSet::iterator Best; |
12473 | switch (CandidateSet.BestViableFunction(*this, OpLoc, Best)) { |
12474 | case OR_Success: { |
12475 | |
12476 | FunctionDecl *FnDecl = Best->Function; |
12477 | |
12478 | if (FnDecl) { |
12479 | Expr *Base = nullptr; |
12480 | |
12481 | |
12482 | |
12483 | |
12484 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FnDecl)) { |
12485 | |
12486 | CheckMemberOperatorAccess(OpLoc, Args[0], Args[1], Best->FoundDecl); |
12487 | |
12488 | ExprResult Arg1 = |
12489 | PerformCopyInitialization( |
12490 | InitializedEntity::InitializeParameter(Context, |
12491 | FnDecl->getParamDecl(0)), |
12492 | SourceLocation(), Args[1]); |
12493 | if (Arg1.isInvalid()) |
12494 | return ExprError(); |
12495 | |
12496 | ExprResult Arg0 = |
12497 | PerformObjectArgumentInitialization(Args[0], , |
12498 | Best->FoundDecl, Method); |
12499 | if (Arg0.isInvalid()) |
12500 | return ExprError(); |
12501 | Base = Args[0] = Arg0.getAs<Expr>(); |
12502 | Args[1] = RHS = Arg1.getAs<Expr>(); |
12503 | } else { |
12504 | |
12505 | ExprResult Arg0 = PerformCopyInitialization( |
12506 | InitializedEntity::InitializeParameter(Context, |
12507 | FnDecl->getParamDecl(0)), |
12508 | SourceLocation(), Args[0]); |
12509 | if (Arg0.isInvalid()) |
12510 | return ExprError(); |
12511 | |
12512 | ExprResult Arg1 = |
12513 | PerformCopyInitialization( |
12514 | InitializedEntity::InitializeParameter(Context, |
12515 | FnDecl->getParamDecl(1)), |
12516 | SourceLocation(), Args[1]); |
12517 | if (Arg1.isInvalid()) |
12518 | return ExprError(); |
12519 | Args[0] = LHS = Arg0.getAs<Expr>(); |
12520 | Args[1] = RHS = Arg1.getAs<Expr>(); |
12521 | } |
12522 | |
12523 | |
12524 | ExprResult FnExpr = CreateFunctionRefExpr(*this, FnDecl, |
12525 | Best->FoundDecl, Base, |
12526 | HadMultipleCandidates, OpLoc); |
12527 | if (FnExpr.isInvalid()) |
12528 | return ExprError(); |
12529 | |
12530 | |
12531 | QualType ResultTy = FnDecl->getReturnType(); |
12532 | ExprValueKind VK = Expr::getValueKindForType(ResultTy); |
12533 | ResultTy = ResultTy.getNonLValueExprType(Context); |
12534 | |
12535 | CXXOperatorCallExpr *TheCall = CXXOperatorCallExpr::Create( |
12536 | Context, Op, FnExpr.get(), Args, ResultTy, VK, OpLoc, FPFeatures, |
12537 | Best->IsADLCandidate); |
12538 | |
12539 | if (CheckCallReturnType(FnDecl->getReturnType(), OpLoc, TheCall, |
12540 | FnDecl)) |
12541 | return ExprError(); |
12542 | |
12543 | ArrayRef<const Expr *> ArgsArray(Args, 2); |
12544 | const Expr *ImplicitThis = nullptr; |
12545 | |
12546 | if (isa<CXXMethodDecl>(FnDecl)) { |
12547 | ImplicitThis = ArgsArray[0]; |
12548 | ArgsArray = ArgsArray.slice(1); |
12549 | } |
12550 | |
12551 | |
12552 | if (Op == OO_Equal) |
12553 | DiagnoseSelfMove(Args[0], Args[1], OpLoc); |
12554 | |
12555 | checkCall(FnDecl, nullptr, ImplicitThis, ArgsArray, |
12556 | isa<CXXMethodDecl>(FnDecl), OpLoc, TheCall->getSourceRange(), |
12557 | VariadicDoesNotApply); |
12558 | |
12559 | return MaybeBindToTemporary(TheCall); |
12560 | } else { |
12561 | |
12562 | |
12563 | |
12564 | ExprResult ArgsRes0 = PerformImplicitConversion( |
12565 | Args[0], Best->BuiltinParamTypes[0], Best->Conversions[0], |
12566 | AA_Passing, CCK_ForBuiltinOverloadedOp); |
12567 | if (ArgsRes0.isInvalid()) |
12568 | return ExprError(); |
12569 | Args[0] = ArgsRes0.get(); |
12570 | |
12571 | ExprResult ArgsRes1 = PerformImplicitConversion( |
12572 | Args[1], Best->BuiltinParamTypes[1], Best->Conversions[1], |
12573 | AA_Passing, CCK_ForBuiltinOverloadedOp); |
12574 | if (ArgsRes1.isInvalid()) |
12575 | return ExprError(); |
12576 | Args[1] = ArgsRes1.get(); |
12577 | break; |
12578 | } |
12579 | } |
12580 | |
12581 | case OR_No_Viable_Function: { |
12582 | |
12583 | |
12584 | |
12585 | |
12586 | if (Opc == BO_Comma) |
12587 | break; |
12588 | |
12589 | |
12590 | |
12591 | |
12592 | ExprResult Result = ExprError(); |
12593 | if (Args[0]->getType()->isRecordType() && |
12594 | Opc >= BO_Assign && Opc <= BO_OrAssign) { |
12595 | Diag(OpLoc, diag::err_ovl_no_viable_oper) |
12596 | << BinaryOperator::getOpcodeStr(Opc) |
12597 | << Args[0]->getSourceRange() << Args[1]->getSourceRange(); |
12598 | if (Args[0]->getType()->isIncompleteType()) { |
12599 | Diag(OpLoc, diag::note_assign_lhs_incomplete) |
12600 | << Args[0]->getType() |
12601 | << Args[0]->getSourceRange() << Args[1]->getSourceRange(); |
12602 | } |
12603 | } else { |
12604 | |
12605 | |
12606 | |
12607 | if (DiagnoseTwoPhaseOperatorLookup(*this, Op, OpLoc, Args)) |
12608 | |
12609 | return ExprError(); |
12610 | |
12611 | |
12612 | |
12613 | Result = CreateBuiltinBinOp(OpLoc, Opc, Args[0], Args[1]); |
12614 | } |
12615 | (0) . __assert_fail ("Result.isInvalid() && \"C++ binary operator overloading is missing candidates!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 12616, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Result.isInvalid() && |
12616 | (0) . __assert_fail ("Result.isInvalid() && \"C++ binary operator overloading is missing candidates!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 12616, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "C++ binary operator overloading is missing candidates!"); |
12617 | if (Result.isInvalid()) |
12618 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args, |
12619 | BinaryOperator::getOpcodeStr(Opc), OpLoc); |
12620 | return Result; |
12621 | } |
12622 | |
12623 | case OR_Ambiguous: |
12624 | Diag(OpLoc, diag::err_ovl_ambiguous_oper_binary) |
12625 | << BinaryOperator::getOpcodeStr(Opc) |
12626 | << Args[0]->getType() << Args[1]->getType() |
12627 | << Args[0]->getSourceRange() << Args[1]->getSourceRange(); |
12628 | CandidateSet.NoteCandidates(*this, OCD_ViableCandidates, Args, |
12629 | BinaryOperator::getOpcodeStr(Opc), OpLoc); |
12630 | return ExprError(); |
12631 | |
12632 | case OR_Deleted: |
12633 | if (isImplicitlyDeleted(Best->Function)) { |
12634 | CXXMethodDecl *Method = cast<CXXMethodDecl>(Best->Function); |
12635 | Diag(OpLoc, diag::err_ovl_deleted_special_oper) |
12636 | << Context.getRecordType(Method->getParent()) |
12637 | << getSpecialMember(Method); |
12638 | |
12639 | |
12640 | |
12641 | NoteDeletedFunction(Method); |
12642 | return ExprError(); |
12643 | } else { |
12644 | Diag(OpLoc, diag::err_ovl_deleted_oper) |
12645 | << BinaryOperator::getOpcodeStr(Opc) << Args[0]->getSourceRange() |
12646 | << Args[1]->getSourceRange(); |
12647 | } |
12648 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args, |
12649 | BinaryOperator::getOpcodeStr(Opc), OpLoc); |
12650 | return ExprError(); |
12651 | } |
12652 | |
12653 | |
12654 | return CreateBuiltinBinOp(OpLoc, Opc, Args[0], Args[1]); |
12655 | } |
12656 | |
12657 | ExprResult |
12658 | Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, |
12659 | SourceLocation RLoc, |
12660 | Expr *Base, Expr *Idx) { |
12661 | Expr *Args[2] = { Base, Idx }; |
12662 | DeclarationName OpName = |
12663 | Context.DeclarationNames.getCXXOperatorName(OO_Subscript); |
12664 | |
12665 | |
12666 | |
12667 | if (Args[0]->isTypeDependent() || Args[1]->isTypeDependent()) { |
12668 | |
12669 | CXXRecordDecl *NamingClass = nullptr; |
12670 | |
12671 | DeclarationNameInfo OpNameInfo(OpName, LLoc); |
12672 | OpNameInfo.setCXXOperatorNameRange(SourceRange(LLoc, RLoc)); |
12673 | UnresolvedLookupExpr *Fn |
12674 | = UnresolvedLookupExpr::Create(Context, NamingClass, |
12675 | NestedNameSpecifierLoc(), OpNameInfo, |
12676 | true, false, |
12677 | UnresolvedSetIterator(), |
12678 | UnresolvedSetIterator()); |
12679 | |
12680 | |
12681 | return CXXOperatorCallExpr::Create(Context, OO_Subscript, Fn, Args, |
12682 | Context.DependentTy, VK_RValue, RLoc, |
12683 | FPOptions()); |
12684 | } |
12685 | |
12686 | |
12687 | if (checkPlaceholderForOverload(*this, Args[0])) |
12688 | return ExprError(); |
12689 | if (checkPlaceholderForOverload(*this, Args[1])) |
12690 | return ExprError(); |
12691 | |
12692 | |
12693 | OverloadCandidateSet CandidateSet(LLoc, OverloadCandidateSet::CSK_Operator); |
12694 | |
12695 | |
12696 | |
12697 | |
12698 | AddMemberOperatorCandidates(OO_Subscript, LLoc, Args, CandidateSet); |
12699 | |
12700 | |
12701 | AddBuiltinOperatorCandidates(OO_Subscript, LLoc, Args, CandidateSet); |
12702 | |
12703 | bool HadMultipleCandidates = (CandidateSet.size() > 1); |
12704 | |
12705 | |
12706 | OverloadCandidateSet::iterator Best; |
12707 | switch (CandidateSet.BestViableFunction(*this, LLoc, Best)) { |
12708 | case OR_Success: { |
12709 | |
12710 | FunctionDecl *FnDecl = Best->Function; |
12711 | |
12712 | if (FnDecl) { |
12713 | |
12714 | |
12715 | |
12716 | CheckMemberOperatorAccess(LLoc, Args[0], Args[1], Best->FoundDecl); |
12717 | |
12718 | |
12719 | CXXMethodDecl *Method = cast<CXXMethodDecl>(FnDecl); |
12720 | ExprResult Arg0 = |
12721 | PerformObjectArgumentInitialization(Args[0], , |
12722 | Best->FoundDecl, Method); |
12723 | if (Arg0.isInvalid()) |
12724 | return ExprError(); |
12725 | Args[0] = Arg0.get(); |
12726 | |
12727 | |
12728 | ExprResult InputInit |
12729 | = PerformCopyInitialization(InitializedEntity::InitializeParameter( |
12730 | Context, |
12731 | FnDecl->getParamDecl(0)), |
12732 | SourceLocation(), |
12733 | Args[1]); |
12734 | if (InputInit.isInvalid()) |
12735 | return ExprError(); |
12736 | |
12737 | Args[1] = InputInit.getAs<Expr>(); |
12738 | |
12739 | |
12740 | DeclarationNameInfo OpLocInfo(OpName, LLoc); |
12741 | OpLocInfo.setCXXOperatorNameRange(SourceRange(LLoc, RLoc)); |
12742 | ExprResult FnExpr = CreateFunctionRefExpr(*this, FnDecl, |
12743 | Best->FoundDecl, |
12744 | Base, |
12745 | HadMultipleCandidates, |
12746 | OpLocInfo.getLoc(), |
12747 | OpLocInfo.getInfo()); |
12748 | if (FnExpr.isInvalid()) |
12749 | return ExprError(); |
12750 | |
12751 | |
12752 | QualType ResultTy = FnDecl->getReturnType(); |
12753 | ExprValueKind VK = Expr::getValueKindForType(ResultTy); |
12754 | ResultTy = ResultTy.getNonLValueExprType(Context); |
12755 | |
12756 | CXXOperatorCallExpr *TheCall = |
12757 | CXXOperatorCallExpr::Create(Context, OO_Subscript, FnExpr.get(), |
12758 | Args, ResultTy, VK, RLoc, FPOptions()); |
12759 | |
12760 | if (CheckCallReturnType(FnDecl->getReturnType(), LLoc, TheCall, FnDecl)) |
12761 | return ExprError(); |
12762 | |
12763 | if (CheckFunctionCall(Method, TheCall, |
12764 | Method->getType()->castAs<FunctionProtoType>())) |
12765 | return ExprError(); |
12766 | |
12767 | return MaybeBindToTemporary(TheCall); |
12768 | } else { |
12769 | |
12770 | |
12771 | |
12772 | ExprResult ArgsRes0 = PerformImplicitConversion( |
12773 | Args[0], Best->BuiltinParamTypes[0], Best->Conversions[0], |
12774 | AA_Passing, CCK_ForBuiltinOverloadedOp); |
12775 | if (ArgsRes0.isInvalid()) |
12776 | return ExprError(); |
12777 | Args[0] = ArgsRes0.get(); |
12778 | |
12779 | ExprResult ArgsRes1 = PerformImplicitConversion( |
12780 | Args[1], Best->BuiltinParamTypes[1], Best->Conversions[1], |
12781 | AA_Passing, CCK_ForBuiltinOverloadedOp); |
12782 | if (ArgsRes1.isInvalid()) |
12783 | return ExprError(); |
12784 | Args[1] = ArgsRes1.get(); |
12785 | |
12786 | break; |
12787 | } |
12788 | } |
12789 | |
12790 | case OR_No_Viable_Function: { |
12791 | if (CandidateSet.empty()) |
12792 | Diag(LLoc, diag::err_ovl_no_oper) |
12793 | << Args[0]->getType() << 0 |
12794 | << Args[0]->getSourceRange() << Args[1]->getSourceRange(); |
12795 | else |
12796 | Diag(LLoc, diag::err_ovl_no_viable_subscript) |
12797 | << Args[0]->getType() |
12798 | << Args[0]->getSourceRange() << Args[1]->getSourceRange(); |
12799 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args, |
12800 | "[]", LLoc); |
12801 | return ExprError(); |
12802 | } |
12803 | |
12804 | case OR_Ambiguous: |
12805 | Diag(LLoc, diag::err_ovl_ambiguous_oper_binary) |
12806 | << "[]" |
12807 | << Args[0]->getType() << Args[1]->getType() |
12808 | << Args[0]->getSourceRange() << Args[1]->getSourceRange(); |
12809 | CandidateSet.NoteCandidates(*this, OCD_ViableCandidates, Args, |
12810 | "[]", LLoc); |
12811 | return ExprError(); |
12812 | |
12813 | case OR_Deleted: |
12814 | Diag(LLoc, diag::err_ovl_deleted_oper) |
12815 | << "[]" << Args[0]->getSourceRange() << Args[1]->getSourceRange(); |
12816 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args, "[]", LLoc); |
12817 | return ExprError(); |
12818 | } |
12819 | |
12820 | |
12821 | return CreateBuiltinArraySubscriptExpr(Args[0], LLoc, Args[1], RLoc); |
12822 | } |
12823 | |
12824 | |
12825 | |
12826 | |
12827 | |
12828 | |
12829 | |
12830 | |
12831 | ExprResult |
12832 | Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, |
12833 | SourceLocation LParenLoc, |
12834 | MultiExprArg Args, |
12835 | SourceLocation RParenLoc) { |
12836 | getType() == Context.BoundMemberTy || MemExprE->getType() == Context.OverloadTy", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 12837, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(MemExprE->getType() == Context.BoundMemberTy || |
12837 | getType() == Context.BoundMemberTy || MemExprE->getType() == Context.OverloadTy", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 12837, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> MemExprE->getType() == Context.OverloadTy); |
12838 | |
12839 | |
12840 | |
12841 | Expr *NakedMemExpr = MemExprE->IgnoreParens(); |
12842 | |
12843 | |
12844 | if (BinaryOperator *op = dyn_cast<BinaryOperator>(NakedMemExpr)) { |
12845 | getType() == Context.BoundMemberTy", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 12845, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(op->getType() == Context.BoundMemberTy); |
12846 | getOpcode() == BO_PtrMemD || op->getOpcode() == BO_PtrMemI", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 12846, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(op->getOpcode() == BO_PtrMemD || op->getOpcode() == BO_PtrMemI); |
12847 | |
12848 | QualType fnType = |
12849 | op->getRHS()->getType()->castAs<MemberPointerType>()->getPointeeType(); |
12850 | |
12851 | const FunctionProtoType *proto = fnType->castAs<FunctionProtoType>(); |
12852 | QualType resultType = proto->getCallResultType(Context); |
12853 | ExprValueKind valueKind = Expr::getValueKindForType(proto->getReturnType()); |
12854 | |
12855 | |
12856 | |
12857 | Qualifiers funcQuals = proto->getMethodQuals(); |
12858 | |
12859 | QualType objectType = op->getLHS()->getType(); |
12860 | if (op->getOpcode() == BO_PtrMemI) |
12861 | objectType = objectType->castAs<PointerType>()->getPointeeType(); |
12862 | Qualifiers objectQuals = objectType.getQualifiers(); |
12863 | |
12864 | Qualifiers difference = objectQuals - funcQuals; |
12865 | difference.removeObjCGCAttr(); |
12866 | difference.removeAddressSpace(); |
12867 | if (difference) { |
12868 | std::string qualsString = difference.getAsString(); |
12869 | Diag(LParenLoc, diag::err_pointer_to_member_call_drops_quals) |
12870 | << fnType.getUnqualifiedType() |
12871 | << qualsString |
12872 | << (qualsString.find(' ') == std::string::npos ? 1 : 2); |
12873 | } |
12874 | |
12875 | CXXMemberCallExpr *call = |
12876 | CXXMemberCallExpr::Create(Context, MemExprE, Args, resultType, |
12877 | valueKind, RParenLoc, proto->getNumParams()); |
12878 | |
12879 | if (CheckCallReturnType(proto->getReturnType(), op->getRHS()->getBeginLoc(), |
12880 | call, nullptr)) |
12881 | return ExprError(); |
12882 | |
12883 | if (ConvertArgumentsForCall(call, op, nullptr, proto, Args, RParenLoc)) |
12884 | return ExprError(); |
12885 | |
12886 | if (CheckOtherCall(call, proto)) |
12887 | return ExprError(); |
12888 | |
12889 | return MaybeBindToTemporary(call); |
12890 | } |
12891 | |
12892 | if (isa<CXXPseudoDestructorExpr>(NakedMemExpr)) |
12893 | return CallExpr::Create(Context, MemExprE, Args, Context.VoidTy, VK_RValue, |
12894 | RParenLoc); |
12895 | |
12896 | UnbridgedCastsSet UnbridgedCasts; |
12897 | if (checkArgPlaceholdersForOverload(*this, Args, UnbridgedCasts)) |
12898 | return ExprError(); |
12899 | |
12900 | MemberExpr *MemExpr; |
12901 | CXXMethodDecl *Method = nullptr; |
12902 | DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_public); |
12903 | NestedNameSpecifier *Qualifier = nullptr; |
12904 | if (isa<MemberExpr>(NakedMemExpr)) { |
12905 | MemExpr = cast<MemberExpr>(NakedMemExpr); |
12906 | Method = cast<CXXMethodDecl>(MemExpr->getMemberDecl()); |
12907 | FoundDecl = MemExpr->getFoundDecl(); |
12908 | Qualifier = MemExpr->getQualifier(); |
12909 | UnbridgedCasts.restore(); |
12910 | } else { |
12911 | UnresolvedMemberExpr *UnresExpr = cast<UnresolvedMemberExpr>(NakedMemExpr); |
12912 | Qualifier = UnresExpr->getQualifier(); |
12913 | |
12914 | QualType ObjectType = UnresExpr->getBaseType(); |
12915 | Expr::Classification ObjectClassification |
12916 | = UnresExpr->isArrow()? Expr::Classification::makeSimpleLValue() |
12917 | : UnresExpr->getBase()->Classify(Context); |
12918 | |
12919 | |
12920 | OverloadCandidateSet CandidateSet(UnresExpr->getMemberLoc(), |
12921 | OverloadCandidateSet::CSK_Normal); |
12922 | |
12923 | |
12924 | TemplateArgumentListInfo TemplateArgsBuffer, *TemplateArgs = nullptr; |
12925 | if (UnresExpr->hasExplicitTemplateArgs()) { |
12926 | UnresExpr->copyTemplateArgumentsInto(TemplateArgsBuffer); |
12927 | TemplateArgs = &TemplateArgsBuffer; |
12928 | } |
12929 | |
12930 | for (UnresolvedMemberExpr::decls_iterator I = UnresExpr->decls_begin(), |
12931 | E = UnresExpr->decls_end(); I != E; ++I) { |
12932 | |
12933 | NamedDecl *Func = *I; |
12934 | CXXRecordDecl *ActingDC = cast<CXXRecordDecl>(Func->getDeclContext()); |
12935 | if (isa<UsingShadowDecl>(Func)) |
12936 | Func = cast<UsingShadowDecl>(Func)->getTargetDecl(); |
12937 | |
12938 | |
12939 | |
12940 | if (getLangOpts().MicrosoftExt && isa<CXXConstructorDecl>(Func)) { |
12941 | AddOverloadCandidate(cast<CXXConstructorDecl>(Func), I.getPair(), |
12942 | Args, CandidateSet); |
12943 | } else if ((Method = dyn_cast<CXXMethodDecl>(Func))) { |
12944 | |
12945 | |
12946 | if (TemplateArgs) |
12947 | continue; |
12948 | |
12949 | AddMethodCandidate(Method, I.getPair(), ActingDC, ObjectType, |
12950 | ObjectClassification, Args, CandidateSet, |
12951 | ); |
12952 | } else { |
12953 | AddMethodTemplateCandidate( |
12954 | cast<FunctionTemplateDecl>(Func), I.getPair(), ActingDC, |
12955 | TemplateArgs, ObjectType, ObjectClassification, Args, CandidateSet, |
12956 | ); |
12957 | } |
12958 | } |
12959 | |
12960 | DeclarationName DeclName = UnresExpr->getMemberName(); |
12961 | |
12962 | UnbridgedCasts.restore(); |
12963 | |
12964 | OverloadCandidateSet::iterator Best; |
12965 | switch (CandidateSet.BestViableFunction(*this, UnresExpr->getBeginLoc(), |
12966 | Best)) { |
12967 | case OR_Success: |
12968 | Method = cast<CXXMethodDecl>(Best->Function); |
12969 | FoundDecl = Best->FoundDecl; |
12970 | CheckUnresolvedMemberAccess(UnresExpr, Best->FoundDecl); |
12971 | if (DiagnoseUseOfDecl(Best->FoundDecl, UnresExpr->getNameLoc())) |
12972 | return ExprError(); |
12973 | |
12974 | |
12975 | |
12976 | |
12977 | |
12978 | |
12979 | if (Method != FoundDecl.getDecl() && |
12980 | DiagnoseUseOfDecl(Method, UnresExpr->getNameLoc())) |
12981 | return ExprError(); |
12982 | break; |
12983 | |
12984 | case OR_No_Viable_Function: |
12985 | Diag(UnresExpr->getMemberLoc(), |
12986 | diag::err_ovl_no_viable_member_function_in_call) |
12987 | << DeclName << MemExprE->getSourceRange(); |
12988 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args); |
12989 | |
12990 | return ExprError(); |
12991 | |
12992 | case OR_Ambiguous: |
12993 | Diag(UnresExpr->getMemberLoc(), diag::err_ovl_ambiguous_member_call) |
12994 | << DeclName << MemExprE->getSourceRange(); |
12995 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args); |
12996 | |
12997 | return ExprError(); |
12998 | |
12999 | case OR_Deleted: |
13000 | Diag(UnresExpr->getMemberLoc(), diag::err_ovl_deleted_member_call) |
13001 | << DeclName << MemExprE->getSourceRange(); |
13002 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args); |
13003 | |
13004 | return ExprError(); |
13005 | } |
13006 | |
13007 | MemExprE = FixOverloadedFunctionReference(MemExprE, FoundDecl, Method); |
13008 | |
13009 | |
13010 | |
13011 | if (Method->isStatic()) { |
13012 | return BuildResolvedCallExpr(MemExprE, Method, LParenLoc, Args, |
13013 | RParenLoc); |
13014 | } |
13015 | |
13016 | MemExpr = cast<MemberExpr>(MemExprE->IgnoreParens()); |
13017 | } |
13018 | |
13019 | QualType ResultType = Method->getReturnType(); |
13020 | ExprValueKind VK = Expr::getValueKindForType(ResultType); |
13021 | ResultType = ResultType.getNonLValueExprType(Context); |
13022 | |
13023 | (0) . __assert_fail ("Method && \"Member call to something that isn't a method?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13023, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Method && "Member call to something that isn't a method?"); |
13024 | const auto *Proto = Method->getType()->getAs<FunctionProtoType>(); |
13025 | CXXMemberCallExpr *TheCall = |
13026 | CXXMemberCallExpr::Create(Context, MemExprE, Args, ResultType, VK, |
13027 | RParenLoc, Proto->getNumParams()); |
13028 | |
13029 | |
13030 | if (CheckCallReturnType(Method->getReturnType(), MemExpr->getMemberLoc(), |
13031 | TheCall, Method)) |
13032 | return ExprError(); |
13033 | |
13034 | |
13035 | |
13036 | |
13037 | if (!Method->isStatic()) { |
13038 | ExprResult ObjectArg = |
13039 | PerformObjectArgumentInitialization(MemExpr->getBase(), Qualifier, |
13040 | FoundDecl, Method); |
13041 | if (ObjectArg.isInvalid()) |
13042 | return ExprError(); |
13043 | MemExpr->setBase(ObjectArg.get()); |
13044 | } |
13045 | |
13046 | |
13047 | if (ConvertArgumentsForCall(TheCall, MemExpr, Method, Proto, Args, |
13048 | RParenLoc)) |
13049 | return ExprError(); |
13050 | |
13051 | DiagnoseSentinelCalls(Method, LParenLoc, Args); |
13052 | |
13053 | if (CheckFunctionCall(Method, TheCall, Proto)) |
13054 | return ExprError(); |
13055 | |
13056 | |
13057 | |
13058 | |
13059 | if (auto *MemE = dyn_cast<MemberExpr>(NakedMemExpr)) { |
13060 | if (const EnableIfAttr *Attr = CheckEnableIf(Method, Args, true)) { |
13061 | Diag(MemE->getMemberLoc(), |
13062 | diag::err_ovl_no_viable_member_function_in_call) |
13063 | << Method << Method->getSourceRange(); |
13064 | Diag(Method->getLocation(), |
13065 | diag::note_ovl_candidate_disabled_by_function_cond_attr) |
13066 | << Attr->getCond()->getSourceRange() << Attr->getMessage(); |
13067 | return ExprError(); |
13068 | } |
13069 | } |
13070 | |
13071 | if ((isa<CXXConstructorDecl>(CurContext) || |
13072 | isa<CXXDestructorDecl>(CurContext)) && |
13073 | TheCall->getMethodDecl()->isPure()) { |
13074 | const CXXMethodDecl *MD = TheCall->getMethodDecl(); |
13075 | |
13076 | if (isa<CXXThisExpr>(MemExpr->getBase()->IgnoreParenCasts()) && |
13077 | MemExpr->performsVirtualDispatch(getLangOpts())) { |
13078 | Diag(MemExpr->getBeginLoc(), |
13079 | diag::warn_call_to_pure_virtual_member_function_from_ctor_dtor) |
13080 | << MD->getDeclName() << isa<CXXDestructorDecl>(CurContext) |
13081 | << MD->getParent()->getDeclName(); |
13082 | |
13083 | Diag(MD->getBeginLoc(), diag::note_previous_decl) << MD->getDeclName(); |
13084 | if (getLangOpts().AppleKext) |
13085 | Diag(MemExpr->getBeginLoc(), diag::note_pure_qualified_call_kext) |
13086 | << MD->getParent()->getDeclName() << MD->getDeclName(); |
13087 | } |
13088 | } |
13089 | |
13090 | if (CXXDestructorDecl *DD = |
13091 | dyn_cast<CXXDestructorDecl>(TheCall->getMethodDecl())) { |
13092 | |
13093 | bool CallCanBeVirtual = !MemExpr->hasQualifier() || getLangOpts().AppleKext; |
13094 | CheckVirtualDtorCall(DD, MemExpr->getBeginLoc(), , |
13095 | CallCanBeVirtual, , |
13096 | MemExpr->getMemberLoc()); |
13097 | } |
13098 | |
13099 | return MaybeBindToTemporary(TheCall); |
13100 | } |
13101 | |
13102 | |
13103 | |
13104 | |
13105 | |
13106 | ExprResult |
13107 | Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj, |
13108 | SourceLocation LParenLoc, |
13109 | MultiExprArg Args, |
13110 | SourceLocation RParenLoc) { |
13111 | if (checkPlaceholderForOverload(*this, Obj)) |
13112 | return ExprError(); |
13113 | ExprResult Object = Obj; |
13114 | |
13115 | UnbridgedCastsSet UnbridgedCasts; |
13116 | if (checkArgPlaceholdersForOverload(*this, Args, UnbridgedCasts)) |
13117 | return ExprError(); |
13118 | |
13119 | (0) . __assert_fail ("Object.get()->getType()->isRecordType() && \"Requires object type argument\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13120, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Object.get()->getType()->isRecordType() && |
13120 | (0) . __assert_fail ("Object.get()->getType()->isRecordType() && \"Requires object type argument\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13120, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Requires object type argument"); |
13121 | const RecordType *Record = Object.get()->getType()->getAs<RecordType>(); |
13122 | |
13123 | |
13124 | |
13125 | |
13126 | |
13127 | |
13128 | |
13129 | |
13130 | OverloadCandidateSet CandidateSet(LParenLoc, |
13131 | OverloadCandidateSet::CSK_Operator); |
13132 | DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(OO_Call); |
13133 | |
13134 | if (RequireCompleteType(LParenLoc, Object.get()->getType(), |
13135 | diag::err_incomplete_object_call, Object.get())) |
13136 | return true; |
13137 | |
13138 | LookupResult R(*this, OpName, LParenLoc, LookupOrdinaryName); |
13139 | LookupQualifiedName(R, Record->getDecl()); |
13140 | R.suppressDiagnostics(); |
13141 | |
13142 | for (LookupResult::iterator Oper = R.begin(), OperEnd = R.end(); |
13143 | Oper != OperEnd; ++Oper) { |
13144 | AddMethodCandidate(Oper.getPair(), Object.get()->getType(), |
13145 | Object.get()->Classify(Context), Args, CandidateSet, |
13146 | ); |
13147 | } |
13148 | |
13149 | |
13150 | |
13151 | |
13152 | |
13153 | |
13154 | |
13155 | |
13156 | |
13157 | |
13158 | |
13159 | |
13160 | |
13161 | |
13162 | |
13163 | |
13164 | |
13165 | |
13166 | const auto &Conversions = |
13167 | cast<CXXRecordDecl>(Record->getDecl())->getVisibleConversionFunctions(); |
13168 | for (auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) { |
13169 | NamedDecl *D = *I; |
13170 | CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(D->getDeclContext()); |
13171 | if (isa<UsingShadowDecl>(D)) |
13172 | D = cast<UsingShadowDecl>(D)->getTargetDecl(); |
13173 | |
13174 | |
13175 | |
13176 | if (isa<FunctionTemplateDecl>(D)) |
13177 | continue; |
13178 | |
13179 | CXXConversionDecl *Conv = cast<CXXConversionDecl>(D); |
13180 | if (!Conv->isExplicit()) { |
13181 | |
13182 | |
13183 | QualType ConvType = Conv->getConversionType().getNonReferenceType(); |
13184 | if (const PointerType *ConvPtrType = ConvType->getAs<PointerType>()) |
13185 | ConvType = ConvPtrType->getPointeeType(); |
13186 | |
13187 | if (const FunctionProtoType *Proto = ConvType->getAs<FunctionProtoType>()) |
13188 | { |
13189 | AddSurrogateCandidate(Conv, I.getPair(), ActingContext, Proto, |
13190 | Object.get(), Args, CandidateSet); |
13191 | } |
13192 | } |
13193 | } |
13194 | |
13195 | bool HadMultipleCandidates = (CandidateSet.size() > 1); |
13196 | |
13197 | |
13198 | OverloadCandidateSet::iterator Best; |
13199 | switch (CandidateSet.BestViableFunction(*this, Object.get()->getBeginLoc(), |
13200 | Best)) { |
13201 | case OR_Success: |
13202 | |
13203 | |
13204 | break; |
13205 | |
13206 | case OR_No_Viable_Function: |
13207 | if (CandidateSet.empty()) |
13208 | Diag(Object.get()->getBeginLoc(), diag::err_ovl_no_oper) |
13209 | << Object.get()->getType() << 1 |
13210 | << Object.get()->getSourceRange(); |
13211 | else |
13212 | Diag(Object.get()->getBeginLoc(), diag::err_ovl_no_viable_object_call) |
13213 | << Object.get()->getType() << Object.get()->getSourceRange(); |
13214 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args); |
13215 | break; |
13216 | |
13217 | case OR_Ambiguous: |
13218 | Diag(Object.get()->getBeginLoc(), diag::err_ovl_ambiguous_object_call) |
13219 | << Object.get()->getType() << Object.get()->getSourceRange(); |
13220 | CandidateSet.NoteCandidates(*this, OCD_ViableCandidates, Args); |
13221 | break; |
13222 | |
13223 | case OR_Deleted: |
13224 | Diag(Object.get()->getBeginLoc(), diag::err_ovl_deleted_object_call) |
13225 | << Object.get()->getType() << Object.get()->getSourceRange(); |
13226 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args); |
13227 | break; |
13228 | } |
13229 | |
13230 | if (Best == CandidateSet.end()) |
13231 | return true; |
13232 | |
13233 | UnbridgedCasts.restore(); |
13234 | |
13235 | if (Best->Function == nullptr) { |
13236 | |
13237 | |
13238 | CXXConversionDecl *Conv |
13239 | = cast<CXXConversionDecl>( |
13240 | Best->Conversions[0].UserDefined.ConversionFunction); |
13241 | |
13242 | CheckMemberOperatorAccess(LParenLoc, Object.get(), nullptr, |
13243 | Best->FoundDecl); |
13244 | if (DiagnoseUseOfDecl(Best->FoundDecl, LParenLoc)) |
13245 | return ExprError(); |
13246 | (0) . __assert_fail ("Conv == Best->FoundDecl.getDecl() && \"Found Decl & conversion-to-functionptr should be same, right?!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13247, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Conv == Best->FoundDecl.getDecl() && |
13247 | (0) . __assert_fail ("Conv == Best->FoundDecl.getDecl() && \"Found Decl & conversion-to-functionptr should be same, right?!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13247, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Found Decl & conversion-to-functionptr should be same, right?!"); |
13248 | |
13249 | |
13250 | |
13251 | |
13252 | |
13253 | |
13254 | ExprResult Call = BuildCXXMemberCallExpr(Object.get(), Best->FoundDecl, |
13255 | Conv, HadMultipleCandidates); |
13256 | if (Call.isInvalid()) |
13257 | return ExprError(); |
13258 | |
13259 | Call = ImplicitCastExpr::Create(Context, Call.get()->getType(), |
13260 | CK_UserDefinedConversion, Call.get(), |
13261 | nullptr, VK_RValue); |
13262 | |
13263 | return ActOnCallExpr(S, Call.get(), LParenLoc, Args, RParenLoc); |
13264 | } |
13265 | |
13266 | CheckMemberOperatorAccess(LParenLoc, Object.get(), nullptr, Best->FoundDecl); |
13267 | |
13268 | |
13269 | |
13270 | |
13271 | CXXMethodDecl *Method = cast<CXXMethodDecl>(Best->Function); |
13272 | |
13273 | |
13274 | if (Method->isInvalidDecl()) |
13275 | return ExprError(); |
13276 | |
13277 | const FunctionProtoType *Proto = |
13278 | Method->getType()->getAs<FunctionProtoType>(); |
13279 | |
13280 | unsigned NumParams = Proto->getNumParams(); |
13281 | |
13282 | DeclarationNameInfo OpLocInfo( |
13283 | Context.DeclarationNames.getCXXOperatorName(OO_Call), LParenLoc); |
13284 | OpLocInfo.setCXXOperatorNameRange(SourceRange(LParenLoc, RParenLoc)); |
13285 | ExprResult NewFn = CreateFunctionRefExpr(*this, Method, Best->FoundDecl, |
13286 | Obj, HadMultipleCandidates, |
13287 | OpLocInfo.getLoc(), |
13288 | OpLocInfo.getInfo()); |
13289 | if (NewFn.isInvalid()) |
13290 | return true; |
13291 | |
13292 | |
13293 | |
13294 | |
13295 | unsigned NumArgsSlots = 1 + std::max<unsigned>(Args.size(), NumParams); |
13296 | |
13297 | |
13298 | |
13299 | SmallVector<Expr *, 8> MethodArgs(NumArgsSlots); |
13300 | |
13301 | bool IsError = false; |
13302 | |
13303 | |
13304 | ExprResult ObjRes = |
13305 | PerformObjectArgumentInitialization(Object.get(), , |
13306 | Best->FoundDecl, Method); |
13307 | if (ObjRes.isInvalid()) |
13308 | IsError = true; |
13309 | else |
13310 | Object = ObjRes; |
13311 | MethodArgs[0] = Object.get(); |
13312 | |
13313 | |
13314 | for (unsigned i = 0; i != NumParams; i++) { |
13315 | Expr *Arg; |
13316 | if (i < Args.size()) { |
13317 | Arg = Args[i]; |
13318 | |
13319 | |
13320 | |
13321 | ExprResult InputInit |
13322 | = PerformCopyInitialization(InitializedEntity::InitializeParameter( |
13323 | Context, |
13324 | Method->getParamDecl(i)), |
13325 | SourceLocation(), Arg); |
13326 | |
13327 | IsError |= InputInit.isInvalid(); |
13328 | Arg = InputInit.getAs<Expr>(); |
13329 | } else { |
13330 | ExprResult DefArg |
13331 | = BuildCXXDefaultArgExpr(LParenLoc, Method, Method->getParamDecl(i)); |
13332 | if (DefArg.isInvalid()) { |
13333 | IsError = true; |
13334 | break; |
13335 | } |
13336 | |
13337 | Arg = DefArg.getAs<Expr>(); |
13338 | } |
13339 | |
13340 | MethodArgs[i + 1] = Arg; |
13341 | } |
13342 | |
13343 | |
13344 | if (Proto->isVariadic()) { |
13345 | |
13346 | for (unsigned i = NumParams, e = Args.size(); i < e; i++) { |
13347 | ExprResult Arg = DefaultVariadicArgumentPromotion(Args[i], VariadicMethod, |
13348 | nullptr); |
13349 | IsError |= Arg.isInvalid(); |
13350 | MethodArgs[i + 1] = Arg.get(); |
13351 | } |
13352 | } |
13353 | |
13354 | if (IsError) |
13355 | return true; |
13356 | |
13357 | DiagnoseSentinelCalls(Method, LParenLoc, Args); |
13358 | |
13359 | |
13360 | QualType ResultTy = Method->getReturnType(); |
13361 | ExprValueKind VK = Expr::getValueKindForType(ResultTy); |
13362 | ResultTy = ResultTy.getNonLValueExprType(Context); |
13363 | |
13364 | CXXOperatorCallExpr *TheCall = |
13365 | CXXOperatorCallExpr::Create(Context, OO_Call, NewFn.get(), MethodArgs, |
13366 | ResultTy, VK, RParenLoc, FPOptions()); |
13367 | |
13368 | if (CheckCallReturnType(Method->getReturnType(), LParenLoc, TheCall, Method)) |
13369 | return true; |
13370 | |
13371 | if (CheckFunctionCall(Method, TheCall, Proto)) |
13372 | return true; |
13373 | |
13374 | return MaybeBindToTemporary(TheCall); |
13375 | } |
13376 | |
13377 | |
13378 | |
13379 | |
13380 | ExprResult |
13381 | Sema::BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc, |
13382 | bool *NoArrowOperatorFound) { |
13383 | (0) . __assert_fail ("Base->getType()->isRecordType() && \"left-hand side must have class type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13384, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Base->getType()->isRecordType() && |
13384 | (0) . __assert_fail ("Base->getType()->isRecordType() && \"left-hand side must have class type\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13384, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "left-hand side must have class type"); |
13385 | |
13386 | if (checkPlaceholderForOverload(*this, Base)) |
13387 | return ExprError(); |
13388 | |
13389 | SourceLocation Loc = Base->getExprLoc(); |
13390 | |
13391 | |
13392 | |
13393 | |
13394 | |
13395 | |
13396 | |
13397 | DeclarationName OpName = |
13398 | Context.DeclarationNames.getCXXOperatorName(OO_Arrow); |
13399 | OverloadCandidateSet CandidateSet(Loc, OverloadCandidateSet::CSK_Operator); |
13400 | const RecordType *BaseRecord = Base->getType()->getAs<RecordType>(); |
13401 | |
13402 | if (RequireCompleteType(Loc, Base->getType(), |
13403 | diag::err_typecheck_incomplete_tag, Base)) |
13404 | return ExprError(); |
13405 | |
13406 | LookupResult R(*this, OpName, OpLoc, LookupOrdinaryName); |
13407 | LookupQualifiedName(R, BaseRecord->getDecl()); |
13408 | R.suppressDiagnostics(); |
13409 | |
13410 | for (LookupResult::iterator Oper = R.begin(), OperEnd = R.end(); |
13411 | Oper != OperEnd; ++Oper) { |
13412 | AddMethodCandidate(Oper.getPair(), Base->getType(), Base->Classify(Context), |
13413 | None, CandidateSet, ); |
13414 | } |
13415 | |
13416 | bool HadMultipleCandidates = (CandidateSet.size() > 1); |
13417 | |
13418 | |
13419 | OverloadCandidateSet::iterator Best; |
13420 | switch (CandidateSet.BestViableFunction(*this, OpLoc, Best)) { |
13421 | case OR_Success: |
13422 | |
13423 | break; |
13424 | |
13425 | case OR_No_Viable_Function: |
13426 | if (CandidateSet.empty()) { |
13427 | QualType BaseType = Base->getType(); |
13428 | if (NoArrowOperatorFound) { |
13429 | |
13430 | |
13431 | *NoArrowOperatorFound = true; |
13432 | return ExprError(); |
13433 | } |
13434 | Diag(OpLoc, diag::err_typecheck_member_reference_arrow) |
13435 | << BaseType << Base->getSourceRange(); |
13436 | if (BaseType->isRecordType() && !BaseType->isPointerType()) { |
13437 | Diag(OpLoc, diag::note_typecheck_member_reference_suggestion) |
13438 | << FixItHint::CreateReplacement(OpLoc, "."); |
13439 | } |
13440 | } else |
13441 | Diag(OpLoc, diag::err_ovl_no_viable_oper) |
13442 | << "operator->" << Base->getSourceRange(); |
13443 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Base); |
13444 | return ExprError(); |
13445 | |
13446 | case OR_Ambiguous: |
13447 | Diag(OpLoc, diag::err_ovl_ambiguous_oper_unary) |
13448 | << "->" << Base->getType() << Base->getSourceRange(); |
13449 | CandidateSet.NoteCandidates(*this, OCD_ViableCandidates, Base); |
13450 | return ExprError(); |
13451 | |
13452 | case OR_Deleted: |
13453 | Diag(OpLoc, diag::err_ovl_deleted_oper) << "->" << Base->getSourceRange(); |
13454 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Base); |
13455 | return ExprError(); |
13456 | } |
13457 | |
13458 | CheckMemberOperatorAccess(OpLoc, Base, nullptr, Best->FoundDecl); |
13459 | |
13460 | |
13461 | CXXMethodDecl *Method = cast<CXXMethodDecl>(Best->Function); |
13462 | ExprResult BaseResult = |
13463 | PerformObjectArgumentInitialization(Base, , |
13464 | Best->FoundDecl, Method); |
13465 | if (BaseResult.isInvalid()) |
13466 | return ExprError(); |
13467 | Base = BaseResult.get(); |
13468 | |
13469 | |
13470 | ExprResult FnExpr = CreateFunctionRefExpr(*this, Method, Best->FoundDecl, |
13471 | Base, HadMultipleCandidates, OpLoc); |
13472 | if (FnExpr.isInvalid()) |
13473 | return ExprError(); |
13474 | |
13475 | QualType ResultTy = Method->getReturnType(); |
13476 | ExprValueKind VK = Expr::getValueKindForType(ResultTy); |
13477 | ResultTy = ResultTy.getNonLValueExprType(Context); |
13478 | CXXOperatorCallExpr *TheCall = CXXOperatorCallExpr::Create( |
13479 | Context, OO_Arrow, FnExpr.get(), Base, ResultTy, VK, OpLoc, FPOptions()); |
13480 | |
13481 | if (CheckCallReturnType(Method->getReturnType(), OpLoc, TheCall, Method)) |
13482 | return ExprError(); |
13483 | |
13484 | if (CheckFunctionCall(Method, TheCall, |
13485 | Method->getType()->castAs<FunctionProtoType>())) |
13486 | return ExprError(); |
13487 | |
13488 | return MaybeBindToTemporary(TheCall); |
13489 | } |
13490 | |
13491 | |
13492 | |
13493 | ExprResult Sema::BuildLiteralOperatorCall(LookupResult &R, |
13494 | DeclarationNameInfo &SuffixInfo, |
13495 | ArrayRef<Expr*> Args, |
13496 | SourceLocation LitEndLoc, |
13497 | TemplateArgumentListInfo *TemplateArgs) { |
13498 | SourceLocation UDSuffixLoc = SuffixInfo.getCXXLiteralOperatorNameLoc(); |
13499 | |
13500 | OverloadCandidateSet CandidateSet(UDSuffixLoc, |
13501 | OverloadCandidateSet::CSK_Normal); |
13502 | AddFunctionCandidates(R.asUnresolvedSet(), Args, CandidateSet, TemplateArgs, |
13503 | ); |
13504 | |
13505 | bool HadMultipleCandidates = (CandidateSet.size() > 1); |
13506 | |
13507 | |
13508 | |
13509 | OverloadCandidateSet::iterator Best; |
13510 | switch (CandidateSet.BestViableFunction(*this, UDSuffixLoc, Best)) { |
13511 | case OR_Success: |
13512 | case OR_Deleted: |
13513 | break; |
13514 | |
13515 | case OR_No_Viable_Function: |
13516 | Diag(UDSuffixLoc, diag::err_ovl_no_viable_function_in_call) |
13517 | << R.getLookupName(); |
13518 | CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args); |
13519 | return ExprError(); |
13520 | |
13521 | case OR_Ambiguous: |
13522 | Diag(R.getNameLoc(), diag::err_ovl_ambiguous_call) << R.getLookupName(); |
13523 | CandidateSet.NoteCandidates(*this, OCD_ViableCandidates, Args); |
13524 | return ExprError(); |
13525 | } |
13526 | |
13527 | FunctionDecl *FD = Best->Function; |
13528 | ExprResult Fn = CreateFunctionRefExpr(*this, FD, Best->FoundDecl, |
13529 | nullptr, HadMultipleCandidates, |
13530 | SuffixInfo.getLoc(), |
13531 | SuffixInfo.getInfo()); |
13532 | if (Fn.isInvalid()) |
13533 | return true; |
13534 | |
13535 | |
13536 | |
13537 | Expr *ConvArgs[2]; |
13538 | for (unsigned ArgIdx = 0, N = Args.size(); ArgIdx != N; ++ArgIdx) { |
13539 | ExprResult InputInit = PerformCopyInitialization( |
13540 | InitializedEntity::InitializeParameter(Context, FD->getParamDecl(ArgIdx)), |
13541 | SourceLocation(), Args[ArgIdx]); |
13542 | if (InputInit.isInvalid()) |
13543 | return true; |
13544 | ConvArgs[ArgIdx] = InputInit.get(); |
13545 | } |
13546 | |
13547 | QualType ResultTy = FD->getReturnType(); |
13548 | ExprValueKind VK = Expr::getValueKindForType(ResultTy); |
13549 | ResultTy = ResultTy.getNonLValueExprType(Context); |
13550 | |
13551 | UserDefinedLiteral *UDL = UserDefinedLiteral::Create( |
13552 | Context, Fn.get(), llvm::makeArrayRef(ConvArgs, Args.size()), ResultTy, |
13553 | VK, LitEndLoc, UDSuffixLoc); |
13554 | |
13555 | if (CheckCallReturnType(FD->getReturnType(), UDSuffixLoc, UDL, FD)) |
13556 | return ExprError(); |
13557 | |
13558 | if (CheckFunctionCall(FD, UDL, nullptr)) |
13559 | return ExprError(); |
13560 | |
13561 | return MaybeBindToTemporary(UDL); |
13562 | } |
13563 | |
13564 | |
13565 | |
13566 | |
13567 | |
13568 | |
13569 | |
13570 | |
13571 | Sema::ForRangeStatus |
13572 | Sema::BuildForRangeBeginEndCall(SourceLocation Loc, |
13573 | SourceLocation RangeLoc, |
13574 | const DeclarationNameInfo &NameInfo, |
13575 | LookupResult &MemberLookup, |
13576 | OverloadCandidateSet *CandidateSet, |
13577 | Expr *Range, ExprResult *CallExpr) { |
13578 | Scope *S = nullptr; |
13579 | |
13580 | CandidateSet->clear(OverloadCandidateSet::CSK_Normal); |
13581 | if (!MemberLookup.empty()) { |
13582 | ExprResult MemberRef = |
13583 | BuildMemberReferenceExpr(Range, Range->getType(), Loc, |
13584 | , CXXScopeSpec(), |
13585 | (), |
13586 | , |
13587 | MemberLookup, |
13588 | , S); |
13589 | if (MemberRef.isInvalid()) { |
13590 | *CallExpr = ExprError(); |
13591 | return FRS_DiagnosticIssued; |
13592 | } |
13593 | *CallExpr = ActOnCallExpr(S, MemberRef.get(), Loc, None, Loc, nullptr); |
13594 | if (CallExpr->isInvalid()) { |
13595 | *CallExpr = ExprError(); |
13596 | return FRS_DiagnosticIssued; |
13597 | } |
13598 | } else { |
13599 | UnresolvedSet<0> FoundNames; |
13600 | UnresolvedLookupExpr *Fn = |
13601 | UnresolvedLookupExpr::Create(Context, , |
13602 | NestedNameSpecifierLoc(), NameInfo, |
13603 | , , |
13604 | FoundNames.begin(), FoundNames.end()); |
13605 | |
13606 | bool CandidateSetError = buildOverloadedCallSet(S, Fn, Fn, Range, Loc, |
13607 | CandidateSet, CallExpr); |
13608 | if (CandidateSet->empty() || CandidateSetError) { |
13609 | *CallExpr = ExprError(); |
13610 | return FRS_NoViableFunction; |
13611 | } |
13612 | OverloadCandidateSet::iterator Best; |
13613 | OverloadingResult OverloadResult = |
13614 | CandidateSet->BestViableFunction(*this, Fn->getBeginLoc(), Best); |
13615 | |
13616 | if (OverloadResult == OR_No_Viable_Function) { |
13617 | *CallExpr = ExprError(); |
13618 | return FRS_NoViableFunction; |
13619 | } |
13620 | *CallExpr = FinishOverloadedCallExpr(*this, S, Fn, Fn, Loc, Range, |
13621 | Loc, nullptr, CandidateSet, &Best, |
13622 | OverloadResult, |
13623 | ); |
13624 | if (CallExpr->isInvalid() || OverloadResult != OR_Success) { |
13625 | *CallExpr = ExprError(); |
13626 | return FRS_DiagnosticIssued; |
13627 | } |
13628 | } |
13629 | return FRS_Success; |
13630 | } |
13631 | |
13632 | |
13633 | |
13634 | |
13635 | |
13636 | |
13637 | |
13638 | Expr *Sema::FixOverloadedFunctionReference(Expr *E, DeclAccessPair Found, |
13639 | FunctionDecl *Fn) { |
13640 | if (ParenExpr *PE = dyn_cast<ParenExpr>(E)) { |
13641 | Expr *SubExpr = FixOverloadedFunctionReference(PE->getSubExpr(), |
13642 | Found, Fn); |
13643 | if (SubExpr == PE->getSubExpr()) |
13644 | return PE; |
13645 | |
13646 | return new (Context) ParenExpr(PE->getLParen(), PE->getRParen(), SubExpr); |
13647 | } |
13648 | |
13649 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
13650 | Expr *SubExpr = FixOverloadedFunctionReference(ICE->getSubExpr(), |
13651 | Found, Fn); |
13652 | (0) . __assert_fail ("Context.hasSameType(ICE->getSubExpr()->getType(), SubExpr->getType()) && \"Implicit cast type cannot be determined from overload\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13654, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Context.hasSameType(ICE->getSubExpr()->getType(), |
13653 | (0) . __assert_fail ("Context.hasSameType(ICE->getSubExpr()->getType(), SubExpr->getType()) && \"Implicit cast type cannot be determined from overload\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13654, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> SubExpr->getType()) && |
13654 | (0) . __assert_fail ("Context.hasSameType(ICE->getSubExpr()->getType(), SubExpr->getType()) && \"Implicit cast type cannot be determined from overload\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13654, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Implicit cast type cannot be determined from overload"); |
13655 | (0) . __assert_fail ("ICE->path_empty() && \"fixing up hierarchy conversion?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13655, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ICE->path_empty() && "fixing up hierarchy conversion?"); |
13656 | if (SubExpr == ICE->getSubExpr()) |
13657 | return ICE; |
13658 | |
13659 | return ImplicitCastExpr::Create(Context, ICE->getType(), |
13660 | ICE->getCastKind(), |
13661 | SubExpr, nullptr, |
13662 | ICE->getValueKind()); |
13663 | } |
13664 | |
13665 | if (auto *GSE = dyn_cast<GenericSelectionExpr>(E)) { |
13666 | if (!GSE->isResultDependent()) { |
13667 | Expr *SubExpr = |
13668 | FixOverloadedFunctionReference(GSE->getResultExpr(), Found, Fn); |
13669 | if (SubExpr == GSE->getResultExpr()) |
13670 | return GSE; |
13671 | |
13672 | |
13673 | |
13674 | ArrayRef<Expr *> A = GSE->getAssocExprs(); |
13675 | SmallVector<Expr *, 4> AssocExprs(A.begin(), A.end()); |
13676 | unsigned ResultIdx = GSE->getResultIndex(); |
13677 | AssocExprs[ResultIdx] = SubExpr; |
13678 | |
13679 | return GenericSelectionExpr::Create( |
13680 | Context, GSE->getGenericLoc(), GSE->getControllingExpr(), |
13681 | GSE->getAssocTypeSourceInfos(), AssocExprs, GSE->getDefaultLoc(), |
13682 | GSE->getRParenLoc(), GSE->containsUnexpandedParameterPack(), |
13683 | ResultIdx); |
13684 | } |
13685 | |
13686 | |
13687 | return GSE; |
13688 | } |
13689 | |
13690 | if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(E)) { |
13691 | (0) . __assert_fail ("UnOp->getOpcode() == UO_AddrOf && \"Can only take the address of an overloaded function\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13692, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(UnOp->getOpcode() == UO_AddrOf && |
13692 | (0) . __assert_fail ("UnOp->getOpcode() == UO_AddrOf && \"Can only take the address of an overloaded function\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13692, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Can only take the address of an overloaded function"); |
13693 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Fn)) { |
13694 | if (Method->isStatic()) { |
13695 | |
13696 | |
13697 | } else { |
13698 | |
13699 | |
13700 | |
13701 | Expr *SubExpr = FixOverloadedFunctionReference(UnOp->getSubExpr(), |
13702 | Found, Fn); |
13703 | if (SubExpr == UnOp->getSubExpr()) |
13704 | return UnOp; |
13705 | |
13706 | (0) . __assert_fail ("isa(SubExpr) && \"fixed to something other than a decl ref\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13707, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<DeclRefExpr>(SubExpr) |
13707 | (0) . __assert_fail ("isa(SubExpr) && \"fixed to something other than a decl ref\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13707, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> && "fixed to something other than a decl ref"); |
13708 | (0) . __assert_fail ("cast(SubExpr)->getQualifier() && \"fixed to a member ref with no nested name qualifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13709, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(cast<DeclRefExpr>(SubExpr)->getQualifier() |
13709 | (0) . __assert_fail ("cast(SubExpr)->getQualifier() && \"fixed to a member ref with no nested name qualifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaOverload.cpp", 13709, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> && "fixed to a member ref with no nested name qualifier"); |
13710 | |
13711 | |
13712 | |
13713 | |
13714 | QualType ClassType |
13715 | = Context.getTypeDeclType(cast<RecordDecl>(Method->getDeclContext())); |
13716 | QualType MemPtrType |
13717 | = Context.getMemberPointerType(Fn->getType(), ClassType.getTypePtr()); |
13718 | |
13719 | if (Context.getTargetInfo().getCXXABI().isMicrosoft()) |
13720 | (void)isCompleteType(UnOp->getOperatorLoc(), MemPtrType); |
13721 | |
13722 | return new (Context) UnaryOperator(SubExpr, UO_AddrOf, MemPtrType, |
13723 | VK_RValue, OK_Ordinary, |
13724 | UnOp->getOperatorLoc(), false); |
13725 | } |
13726 | } |
13727 | Expr *SubExpr = FixOverloadedFunctionReference(UnOp->getSubExpr(), |
13728 | Found, Fn); |
13729 | if (SubExpr == UnOp->getSubExpr()) |
13730 | return UnOp; |
13731 | |
13732 | return new (Context) UnaryOperator(SubExpr, UO_AddrOf, |
13733 | Context.getPointerType(SubExpr->getType()), |
13734 | VK_RValue, OK_Ordinary, |
13735 | UnOp->getOperatorLoc(), false); |
13736 | } |
13737 | |
13738 | |
13739 | |
13740 | |
13741 | |
13742 | if (auto *FPT = Fn->getType()->getAs<FunctionProtoType>()) |
13743 | ResolveExceptionSpec(E->getExprLoc(), FPT); |
13744 | |
13745 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E)) { |
13746 | |
13747 | TemplateArgumentListInfo TemplateArgsBuffer, *TemplateArgs = nullptr; |
13748 | if (ULE->hasExplicitTemplateArgs()) { |
13749 | ULE->copyTemplateArgumentsInto(TemplateArgsBuffer); |
13750 | TemplateArgs = &TemplateArgsBuffer; |
13751 | } |
13752 | |
13753 | DeclRefExpr *DRE = DeclRefExpr::Create(Context, |
13754 | ULE->getQualifierLoc(), |
13755 | ULE->getTemplateKeywordLoc(), |
13756 | Fn, |
13757 | false, |
13758 | ULE->getNameLoc(), |
13759 | Fn->getType(), |
13760 | VK_LValue, |
13761 | Found.getDecl(), |
13762 | TemplateArgs); |
13763 | MarkDeclRefReferenced(DRE); |
13764 | DRE->setHadMultipleCandidates(ULE->getNumDecls() > 1); |
13765 | return DRE; |
13766 | } |
13767 | |
13768 | if (UnresolvedMemberExpr *MemExpr = dyn_cast<UnresolvedMemberExpr>(E)) { |
13769 | |
13770 | TemplateArgumentListInfo TemplateArgsBuffer, *TemplateArgs = nullptr; |
13771 | if (MemExpr->hasExplicitTemplateArgs()) { |
13772 | MemExpr->copyTemplateArgumentsInto(TemplateArgsBuffer); |
13773 | TemplateArgs = &TemplateArgsBuffer; |
13774 | } |
13775 | |
13776 | Expr *Base; |
13777 | |
13778 | |
13779 | |
13780 | if (MemExpr->isImplicitAccess()) { |
13781 | if (cast<CXXMethodDecl>(Fn)->isStatic()) { |
13782 | DeclRefExpr *DRE = DeclRefExpr::Create(Context, |
13783 | MemExpr->getQualifierLoc(), |
13784 | MemExpr->getTemplateKeywordLoc(), |
13785 | Fn, |
13786 | false, |
13787 | MemExpr->getMemberLoc(), |
13788 | Fn->getType(), |
13789 | VK_LValue, |
13790 | Found.getDecl(), |
13791 | TemplateArgs); |
13792 | MarkDeclRefReferenced(DRE); |
13793 | DRE->setHadMultipleCandidates(MemExpr->getNumDecls() > 1); |
13794 | return DRE; |
13795 | } else { |
13796 | SourceLocation Loc = MemExpr->getMemberLoc(); |
13797 | if (MemExpr->getQualifier()) |
13798 | Loc = MemExpr->getQualifierLoc().getBeginLoc(); |
13799 | CheckCXXThisCapture(Loc); |
13800 | Base = new (Context) CXXThisExpr(Loc, |
13801 | MemExpr->getBaseType(), |
13802 | ); |
13803 | } |
13804 | } else |
13805 | Base = MemExpr->getBase(); |
13806 | |
13807 | ExprValueKind valueKind; |
13808 | QualType type; |
13809 | if (cast<CXXMethodDecl>(Fn)->isStatic()) { |
13810 | valueKind = VK_LValue; |
13811 | type = Fn->getType(); |
13812 | } else { |
13813 | valueKind = VK_RValue; |
13814 | type = Context.BoundMemberTy; |
13815 | } |
13816 | |
13817 | MemberExpr *ME = MemberExpr::Create( |
13818 | Context, Base, MemExpr->isArrow(), MemExpr->getOperatorLoc(), |
13819 | MemExpr->getQualifierLoc(), MemExpr->getTemplateKeywordLoc(), Fn, Found, |
13820 | MemExpr->getMemberNameInfo(), TemplateArgs, type, valueKind, |
13821 | OK_Ordinary); |
13822 | ME->setHadMultipleCandidates(true); |
13823 | MarkMemberReferenced(ME); |
13824 | return ME; |
13825 | } |
13826 | |
13827 | llvm_unreachable("Invalid reference to overloaded function"); |
13828 | } |
13829 | |
13830 | ExprResult Sema::FixOverloadedFunctionReference(ExprResult E, |
13831 | DeclAccessPair Found, |
13832 | FunctionDecl *Fn) { |
13833 | return FixOverloadedFunctionReference(E.get(), Found, Fn); |
13834 | } |
13835 | |