clang 8.0.0

Overload.h
Go to the documentation of this file.
1 //===- Overload.h - C++ Overloading -----------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the data structures and types used in C++
11 // overload resolution.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_SEMA_OVERLOAD_H
16 #define LLVM_CLANG_SEMA_OVERLOAD_H
17
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/DeclAccessPair.h"
20 #include "clang/AST/DeclBase.h"
21 #include "clang/AST/DeclCXX.h"
22 #include "clang/AST/DeclTemplate.h"
23 #include "clang/AST/Expr.h"
24 #include "clang/AST/Type.h"
25 #include "clang/Basic/LLVM.h"
26 #include "clang/Basic/SourceLocation.h"
27 #include "clang/Sema/SemaFixItUtils.h"
28 #include "clang/Sema/TemplateDeduction.h"
29 #include "llvm/ADT/ArrayRef.h"
30 #include "llvm/ADT/None.h"
31 #include "llvm/ADT/STLExtras.h"
32 #include "llvm/ADT/SmallPtrSet.h"
33 #include "llvm/ADT/SmallVector.h"
34 #include "llvm/ADT/StringRef.h"
35 #include "llvm/Support/AlignOf.h"
36 #include "llvm/Support/Allocator.h"
37 #include "llvm/Support/Casting.h"
38 #include "llvm/Support/ErrorHandling.h"
39 #include <cassert>
40 #include <cstddef>
41 #include <cstdint>
42 #include <utility>
43
44 namespace clang {
45
46 class APValue;
47 class ASTContext;
48 class Sema;
49
50 /// OverloadingResult - Capture the result of performing overload
51 /// resolution.
52 enum OverloadingResult {
53 /// Overload resolution succeeded.
54 OR_Success,
55
56 /// No viable function found.
57 OR_No_Viable_Function,
58
59 /// Ambiguous candidates found.
60 OR_Ambiguous,
61
62 /// Succeeded, but refers to a deleted function.
63 OR_Deleted
64 };
65
66 enum OverloadCandidateDisplayKind {
67 /// Requests that all candidates be shown. Viable candidates will
68 /// be printed first.
69 OCD_AllCandidates,
70
71 /// Requests that only viable candidates be shown.
72 OCD_ViableCandidates
73 };
74
75 /// ImplicitConversionKind - The kind of implicit conversion used to
76 /// convert an argument to a parameter's type. The enumerator values
77 /// match with the table titled 'Conversions' in [over.ics.scs] and are listed
78 /// such that better conversion kinds have smaller values.
79 enum ImplicitConversionKind {
80 /// Identity conversion (no conversion)
81 ICK_Identity = 0,
82
83 /// Lvalue-to-rvalue conversion (C++ [conv.lval])
84 ICK_Lvalue_To_Rvalue,
85
86 /// Array-to-pointer conversion (C++ [conv.array])
87 ICK_Array_To_Pointer,
88
89 /// Function-to-pointer (C++ [conv.array])
90 ICK_Function_To_Pointer,
91
92 /// Function pointer conversion (C++17 [conv.fctptr])
93 ICK_Function_Conversion,
94
95 /// Qualification conversions (C++ [conv.qual])
96 ICK_Qualification,
97
98 /// Integral promotions (C++ [conv.prom])
99 ICK_Integral_Promotion,
100
101 /// Floating point promotions (C++ [conv.fpprom])
102 ICK_Floating_Promotion,
103
104 /// Complex promotions (Clang extension)
105 ICK_Complex_Promotion,
106
107 /// Integral conversions (C++ [conv.integral])
108 ICK_Integral_Conversion,
109
110 /// Floating point conversions (C++ [conv.double]
111 ICK_Floating_Conversion,
112
113 /// Complex conversions (C99 6.3.1.6)
114 ICK_Complex_Conversion,
115
116 /// Floating-integral conversions (C++ [conv.fpint])
117 ICK_Floating_Integral,
118
119 /// Pointer conversions (C++ [conv.ptr])
120 ICK_Pointer_Conversion,
121
122 /// Pointer-to-member conversions (C++ [conv.mem])
123 ICK_Pointer_Member,
124
125 /// Boolean conversions (C++ [conv.bool])
126 ICK_Boolean_Conversion,
127
128 /// Conversions between compatible types in C99
129 ICK_Compatible_Conversion,
130
131 /// Derived-to-base (C++ [over.best.ics])
132 ICK_Derived_To_Base,
133
134 /// Vector conversions
135 ICK_Vector_Conversion,
136
137 /// A vector splat from an arithmetic type
138 ICK_Vector_Splat,
139
140 /// Complex-real conversions (C99 6.3.1.7)
141 ICK_Complex_Real,
142
143 /// Block Pointer conversions
144 ICK_Block_Pointer_Conversion,
145
146 /// Transparent Union Conversions
147 ICK_TransparentUnionConversion,
148
149 /// Objective-C ARC writeback conversion
150 ICK_Writeback_Conversion,
151
152 /// Zero constant to event (OpenCL1.2 6.12.10)
153 ICK_Zero_Event_Conversion,
154
155 /// Zero constant to queue
156 ICK_Zero_Queue_Conversion,
157
158 /// Conversions allowed in C, but not C++
159 ICK_C_Only_Conversion,
160
161 /// C-only conversion between pointers with incompatible types
162 ICK_Incompatible_Pointer_Conversion,
163
164 /// The number of conversion kinds
165 ICK_Num_Conversion_Kinds,
166 };
167
168 /// ImplicitConversionRank - The rank of an implicit conversion
169 /// kind. The enumerator values match with Table 9 of (C++
170 /// 13.3.3.1.1) and are listed such that better conversion ranks
171 /// have smaller values.
172 enum ImplicitConversionRank {
173 /// Exact Match
174 ICR_Exact_Match = 0,
175
176 /// Promotion
177 ICR_Promotion,
178
179 /// Conversion
180 ICR_Conversion,
181
182 /// OpenCL Scalar Widening
183 ICR_OCL_Scalar_Widening,
184
185 /// Complex <-> Real conversion
186 ICR_Complex_Real_Conversion,
187
188 /// ObjC ARC writeback conversion
189 ICR_Writeback_Conversion,
190
191 /// Conversion only allowed in the C standard (e.g. void* to char*).
192 ICR_C_Conversion,
193
194 /// Conversion not allowed by the C standard, but that we accept as an
195 /// extension anyway.
196 ICR_C_Conversion_Extension
197 };
198
199 ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind);
200
201 /// NarrowingKind - The kind of narrowing conversion being performed by a
202 /// standard conversion sequence according to C++11 [dcl.init.list]p7.
203 enum NarrowingKind {
204 /// Not a narrowing conversion.
205 NK_Not_Narrowing,
206
207 /// A narrowing conversion by virtue of the source and destination types.
208 NK_Type_Narrowing,
209
210 /// A narrowing conversion, because a constant expression got narrowed.
211 NK_Constant_Narrowing,
212
213 /// A narrowing conversion, because a non-constant-expression variable might
214 /// have got narrowed.
215 NK_Variable_Narrowing,
216
217 /// Cannot tell whether this is a narrowing conversion because the
218 /// expression is value-dependent.
219 NK_Dependent_Narrowing,
220 };
221
222 /// StandardConversionSequence - represents a standard conversion
223 /// sequence (C++ 13.3.3.1.1). A standard conversion sequence
224 /// contains between zero and three conversions. If a particular
225 /// conversion is not needed, it will be set to the identity conversion
226 /// (ICK_Identity). Note that the three conversions are
227 /// specified as separate members (rather than in an array) so that
228 /// we can keep the size of a standard conversion sequence to a
229 /// single word.
230 class StandardConversionSequence {
231 public:
232 /// First -- The first conversion can be an lvalue-to-rvalue
233 /// conversion, array-to-pointer conversion, or
234 /// function-to-pointer conversion.
235 ImplicitConversionKind First : 8;
236
237 /// Second - The second conversion can be an integral promotion,
238 /// floating point promotion, integral conversion, floating point
239 /// conversion, floating-integral conversion, pointer conversion,
240 /// pointer-to-member conversion, or boolean conversion.
241 ImplicitConversionKind Second : 8;
242
243 /// Third - The third conversion can be a qualification conversion
244 /// or a function conversion.
245 ImplicitConversionKind Third : 8;
246
247 /// Whether this is the deprecated conversion of a
248 /// string literal to a pointer to non-const character data
249 /// (C++ 4.2p2).
250 unsigned DeprecatedStringLiteralToCharPtr : 1;
251
252 /// Whether the qualification conversion involves a change in the
253 /// Objective-C lifetime (for automatic reference counting).
254 unsigned QualificationIncludesObjCLifetime : 1;
255
256 /// IncompatibleObjC - Whether this is an Objective-C conversion
257 /// that we should warn about (if we actually use it).
258 unsigned IncompatibleObjC : 1;
259
260 /// ReferenceBinding - True when this is a reference binding
261 /// (C++ [over.ics.ref]).
262 unsigned ReferenceBinding : 1;
263
264 /// DirectBinding - True when this is a reference binding that is a
265 /// direct binding (C++ [dcl.init.ref]).
266 unsigned DirectBinding : 1;
267
268 /// Whether this is an lvalue reference binding (otherwise, it's
269 /// an rvalue reference binding).
270 unsigned IsLvalueReference : 1;
271
272 /// Whether we're binding to a function lvalue.
273 unsigned BindsToFunctionLvalue : 1;
274
275 /// Whether we're binding to an rvalue.
276 unsigned BindsToRvalue : 1;
277
278 /// Whether this binds an implicit object argument to a
279 /// non-static member function without a ref-qualifier.
280 unsigned BindsImplicitObjectArgumentWithoutRefQualifier : 1;
281
282 /// Whether this binds a reference to an object with a different
283 /// Objective-C lifetime qualifier.
284 unsigned ObjCLifetimeConversionBinding : 1;
285
286 /// FromType - The type that this conversion is converting
287 /// from. This is an opaque pointer that can be translated into a
288 /// QualType.
289 void *FromTypePtr;
290
291 /// ToType - The types that this conversion is converting to in
292 /// each step. This is an opaque pointer that can be translated
293 /// into a QualType.
294 void *ToTypePtrs[3];
295
296 /// CopyConstructor - The copy constructor that is used to perform
297 /// this conversion, when the conversion is actually just the
298 /// initialization of an object via copy constructor. Such
299 /// conversions are either identity conversions or derived-to-base
300 /// conversions.
301 CXXConstructorDecl *CopyConstructor;
302 DeclAccessPair FoundCopyConstructor;
303
304 void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
305
306 void setToType(unsigned Idx, QualType T) {
307 assert(Idx < 3 && "To type index is out of range");
308 ToTypePtrs[Idx] = T.getAsOpaquePtr();
309 }
310
311 void setAllToTypes(QualType T) {
312 ToTypePtrs[0] = T.getAsOpaquePtr();
313 ToTypePtrs[1] = ToTypePtrs[0];
314 ToTypePtrs[2] = ToTypePtrs[0];
315 }
316
317 QualType getFromType() const {
318 return QualType::getFromOpaquePtr(FromTypePtr);
319 }
320
321 QualType getToType(unsigned Idx) const {
322 assert(Idx < 3 && "To type index is out of range");
323 return QualType::getFromOpaquePtr(ToTypePtrs[Idx]);
324 }
325
326 void setAsIdentityConversion();
327
328 bool isIdentityConversion() const {
329 return Second == ICK_Identity && Third == ICK_Identity;
330 }
331
332 ImplicitConversionRank getRank() const;
333 NarrowingKind
334 getNarrowingKind(ASTContext &Context, const Expr *Converted,
335 APValue &ConstantValue, QualType &ConstantType,
336 bool IgnoreFloatToIntegralConversion = false) const;
337 bool isPointerConversionToBool() const;
338 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
339 void dump() const;
340 };
341
342 /// UserDefinedConversionSequence - Represents a user-defined
343 /// conversion sequence (C++ 13.3.3.1.2).
344 struct UserDefinedConversionSequence {
345 /// Represents the standard conversion that occurs before
346 /// the actual user-defined conversion.
347 ///
348 /// C++11 13.3.3.1.2p1:
349 /// If the user-defined conversion is specified by a constructor
350 /// (12.3.1), the initial standard conversion sequence converts
351 /// the source type to the type required by the argument of the
352 /// constructor. If the user-defined conversion is specified by
353 /// a conversion function (12.3.2), the initial standard
354 /// conversion sequence converts the source type to the implicit
355 /// object parameter of the conversion function.
356 StandardConversionSequence Before;
357
358 /// EllipsisConversion - When this is true, it means user-defined
359 /// conversion sequence starts with a ... (ellipsis) conversion, instead of
360 /// a standard conversion. In this case, 'Before' field must be ignored.
361 // FIXME. I much rather put this as the first field. But there seems to be
362 // a gcc code gen. bug which causes a crash in a test. Putting it here seems
363 // to work around the crash.
364 bool EllipsisConversion : 1;
365
366 /// HadMultipleCandidates - When this is true, it means that the
367 /// conversion function was resolved from an overloaded set having
368 /// size greater than 1.
369 bool HadMultipleCandidates : 1;
370
371 /// After - Represents the standard conversion that occurs after
372 /// the actual user-defined conversion.
373 StandardConversionSequence After;
374
375 /// ConversionFunction - The function that will perform the
376 /// user-defined conversion. Null if the conversion is an
377 /// aggregate initialization from an initializer list.
378 FunctionDecl* ConversionFunction;
379
380 /// The declaration that we found via name lookup, which might be
381 /// the same as \c ConversionFunction or it might be a using declaration
382 /// that refers to \c ConversionFunction.
383 DeclAccessPair FoundConversionFunction;
384
385 void dump() const;
386 };
387
388 /// Represents an ambiguous user-defined conversion sequence.
389 struct AmbiguousConversionSequence {
390 using ConversionSet =
391 SmallVector<std::pair<NamedDecl *, FunctionDecl *>, 4>;
392
393 void *FromTypePtr;
394 void *ToTypePtr;
395 char Buffer[sizeof(ConversionSet)];
396
397 QualType getFromType() const {
398 return QualType::getFromOpaquePtr(FromTypePtr);
399 }
400
401 QualType getToType() const {
402 return QualType::getFromOpaquePtr(ToTypePtr);
403 }
404
405 void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
406 void setToType(QualType T) { ToTypePtr = T.getAsOpaquePtr(); }
407
408 ConversionSet &conversions() {
409 return *reinterpret_cast<ConversionSet*>(Buffer);
410 }
411
412 const ConversionSet &conversions() const {
413 return *reinterpret_cast<const ConversionSet*>(Buffer);
414 }
415
416 void addConversion(NamedDecl *Found, FunctionDecl *D) {
417 conversions().push_back(std::make_pair(Found, D));
418 }
419
420 using iterator = ConversionSet::iterator;
421
422 iterator begin() { return conversions().begin(); }
423 iterator end() { return conversions().end(); }
424
425 using const_iterator = ConversionSet::const_iterator;
426
427 const_iterator begin() const { return conversions().begin(); }
428 const_iterator end() const { return conversions().end(); }
429
430 void construct();
431 void destruct();
432 void copyFrom(const AmbiguousConversionSequence &);
433 };
434
435 /// BadConversionSequence - Records information about an invalid
436 /// conversion sequence.
437 struct BadConversionSequence {
438 enum FailureKind {
439 no_conversion,
440 unrelated_class,
441 bad_qualifiers,
442 lvalue_ref_to_rvalue,
443 rvalue_ref_to_lvalue
444 };
445
446 // This can be null, e.g. for implicit object arguments.
447 Expr *FromExpr;
448
449 FailureKind Kind;
450
451 private:
452 // The type we're converting from (an opaque QualType).
453 void *FromTy;
454
455 // The type we're converting to (an opaque QualType).
456 void *ToTy;
457
458 public:
459 void init(FailureKind K, Expr *From, QualType To) {
460 init(K, From->getType(), To);
461 FromExpr = From;
462 }
463
464 void init(FailureKind K, QualType From, QualType To) {
465 Kind = K;
466 FromExpr = nullptr;
467 setFromType(From);
468 setToType(To);
469 }
470
471 QualType getFromType() const { return QualType::getFromOpaquePtr(FromTy); }
472 QualType getToType() const { return QualType::getFromOpaquePtr(ToTy); }
473
474 void setFromExpr(Expr *E) {
475 FromExpr = E;
476 setFromType(E->getType());
477 }
478
479 void setFromType(QualType T) { FromTy = T.getAsOpaquePtr(); }
480 void setToType(QualType T) { ToTy = T.getAsOpaquePtr(); }
481 };
482
483 /// ImplicitConversionSequence - Represents an implicit conversion
484 /// sequence, which may be a standard conversion sequence
485 /// (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2),
486 /// or an ellipsis conversion sequence (C++ 13.3.3.1.3).
487 class ImplicitConversionSequence {
488 public:
489 /// Kind - The kind of implicit conversion sequence. BadConversion
490 /// specifies that there is no conversion from the source type to
491 /// the target type. AmbiguousConversion represents the unique
492 /// ambiguous conversion (C++0x [over.best.ics]p10).
493 enum Kind {
494 StandardConversion = 0,
495 UserDefinedConversion,
496 AmbiguousConversion,
497 EllipsisConversion,
498 BadConversion
499 };
500
501 private:
502 enum {
503 Uninitialized = BadConversion + 1
504 };
505
506 /// ConversionKind - The kind of implicit conversion sequence.
507 unsigned ConversionKind : 30;
508
509 /// Whether the target is really a std::initializer_list, and the
510 /// sequence only represents the worst element conversion.
511 unsigned StdInitializerListElement : 1;
512
513 void setKind(Kind K) {
514 destruct();
515 ConversionKind = K;
516 }
517
518 void destruct() {
519 if (ConversionKind == AmbiguousConversion) Ambiguous.destruct();
520 }
521
522 public:
523 union {
524 /// When ConversionKind == StandardConversion, provides the
525 /// details of the standard conversion sequence.
526 StandardConversionSequence Standard;
527
528 /// When ConversionKind == UserDefinedConversion, provides the
529 /// details of the user-defined conversion sequence.
530 UserDefinedConversionSequence UserDefined;
531
532 /// When ConversionKind == AmbiguousConversion, provides the
533 /// details of the ambiguous conversion.
534 AmbiguousConversionSequence Ambiguous;
535
536 /// When ConversionKind == BadConversion, provides the details
537 /// of the bad conversion.
538 BadConversionSequence Bad;
539 };
540
541 ImplicitConversionSequence()
542 : ConversionKind(Uninitialized), StdInitializerListElement(false) {
543 Standard.setAsIdentityConversion();
544 }
545
546 ImplicitConversionSequence(const ImplicitConversionSequence &Other)
547 : ConversionKind(Other.ConversionKind),
548 StdInitializerListElement(Other.StdInitializerListElement) {
549 switch (ConversionKind) {
550 case Uninitialized: break;
551 case StandardConversion: Standard = Other.Standard; break;
552 case UserDefinedConversion: UserDefined = Other.UserDefined; break;
553 case AmbiguousConversion: Ambiguous.copyFrom(Other.Ambiguous); break;
554 case EllipsisConversion: break;
555 case BadConversion: Bad = Other.Bad; break;
556 }
557 }
558
559 ImplicitConversionSequence &
560 operator=(const ImplicitConversionSequence &Other) {
561 destruct();
562 new (this) ImplicitConversionSequence(Other);
563 return *this;
564 }
565
566 ~ImplicitConversionSequence() {
567 destruct();
568 }
569
570 Kind getKind() const {
571 assert(isInitialized() && "querying uninitialized conversion");
572 return Kind(ConversionKind);
573 }
574
575 /// Return a ranking of the implicit conversion sequence
576 /// kind, where smaller ranks represent better conversion
577 /// sequences.
578 ///
579 /// In particular, this routine gives user-defined conversion
580 /// sequences and ambiguous conversion sequences the same rank,
581 /// per C++ [over.best.ics]p10.
582 unsigned getKindRank() const {
583 switch (getKind()) {
584 case StandardConversion:
585 return 0;
586
587 case UserDefinedConversion:
588 case AmbiguousConversion:
589 return 1;
590
591 case EllipsisConversion:
592 return 2;
593
594 case BadConversion:
595 return 3;
596 }
597
598 llvm_unreachable("Invalid ImplicitConversionSequence::Kind!");
599 }
600
601 bool isBad() const { return getKind() == BadConversion; }
602 bool isStandard() const { return getKind() == StandardConversion; }
603 bool isEllipsis() const { return getKind() == EllipsisConversion; }
604 bool isAmbiguous() const { return getKind() == AmbiguousConversion; }
605 bool isUserDefined() const { return getKind() == UserDefinedConversion; }
606 bool isFailure() const { return isBad() || isAmbiguous(); }
607
608 /// Determines whether this conversion sequence has been
609 /// initialized. Most operations should never need to query
610 /// uninitialized conversions and should assert as above.
611 bool isInitialized() const { return ConversionKind != Uninitialized; }
612
613 /// Sets this sequence as a bad conversion for an explicit argument.
614 void setBad(BadConversionSequence::FailureKind Failure,
615 Expr *FromExpr, QualType ToType) {
616 setKind(BadConversion);
617 Bad.init(Failure, FromExpr, ToType);
618 }
619
620 /// Sets this sequence as a bad conversion for an implicit argument.
621 void setBad(BadConversionSequence::FailureKind Failure,
622 QualType FromType, QualType ToType) {
623 setKind(BadConversion);
624 Bad.init(Failure, FromType, ToType);
625 }
626
627 void setStandard() { setKind(StandardConversion); }
628 void setEllipsis() { setKind(EllipsisConversion); }
629 void setUserDefined() { setKind(UserDefinedConversion); }
630
631 void setAmbiguous() {
632 if (ConversionKind == AmbiguousConversion) return;
633 ConversionKind = AmbiguousConversion;
634 Ambiguous.construct();
635 }
636
637 void setAsIdentityConversion(QualType T) {
638 setStandard();
639 Standard.setAsIdentityConversion();
640 Standard.setFromType(T);
641 Standard.setAllToTypes(T);
642 }
643
644 /// Whether the target is really a std::initializer_list, and the
645 /// sequence only represents the worst element conversion.
646 bool isStdInitializerListElement() const {
647 return StdInitializerListElement;
648 }
649
650 void setStdInitializerListElement(bool V = true) {
651 StdInitializerListElement = V;
652 }
653
654 // The result of a comparison between implicit conversion
655 // sequences. Use Sema::CompareImplicitConversionSequences to
656 // actually perform the comparison.
657 enum CompareKind {
658 Better = -1,
659 Indistinguishable = 0,
660 Worse = 1
661 };
662
663 void DiagnoseAmbiguousConversion(Sema &S,
664 SourceLocation CaretLoc,
665 const PartialDiagnostic &PDiag) const;
666
667 void dump() const;
668 };
669
670 enum OverloadFailureKind {
671 ovl_fail_too_many_arguments,
672 ovl_fail_too_few_arguments,
673 ovl_fail_bad_conversion,
674 ovl_fail_bad_deduction,
675
676 /// This conversion candidate was not considered because it
677 /// duplicates the work of a trivial or derived-to-base
678 /// conversion.
679 ovl_fail_trivial_conversion,
680
681 /// This conversion candidate was not considered because it is
682 /// an illegal instantiation of a constructor temploid: it is
683 /// callable with one argument, we only have one argument, and
684 /// its first parameter type is exactly the type of the class.
685 ///
686 /// Defining such a constructor directly is illegal, and
687 /// template-argument deduction is supposed to ignore such
688 /// instantiations, but we can still get one with the right
689 /// kind of implicit instantiation.
690 ovl_fail_illegal_constructor,
691
692 /// This conversion candidate is not viable because its result
693 /// type is not implicitly convertible to the desired type.
694 ovl_fail_bad_final_conversion,
695
696 /// This conversion function template specialization candidate is not
697 /// viable because the final conversion was not an exact match.
698 ovl_fail_final_conversion_not_exact,
699
700 /// (CUDA) This candidate was not viable because the callee
701 /// was not accessible from the caller's target (i.e. host->device,
702 /// global->host, device->host).
703 ovl_fail_bad_target,
704
705 /// This candidate function was not viable because an enable_if
706 /// attribute disabled it.
707 ovl_fail_enable_if,
708
709 /// This candidate was not viable because its address could not be taken.
710 ovl_fail_addr_not_available,
711
712 /// This candidate was not viable because its OpenCL extension is disabled.
713 ovl_fail_ext_disabled,
714
715 /// This inherited constructor is not viable because it would slice the
716 /// argument.
717 ovl_fail_inhctor_slice,
718
719 /// This candidate was not viable because it is a non-default multiversioned
720 /// function.
721 ovl_non_default_multiversion_function,
722 };
723
724 /// A list of implicit conversion sequences for the arguments of an
725 /// OverloadCandidate.
726 using ConversionSequenceList =
727 llvm::MutableArrayRef<ImplicitConversionSequence>;
728
729 /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
730 struct OverloadCandidate {
731 /// Function - The actual function that this candidate
732 /// represents. When NULL, this is a built-in candidate
733 /// (C++ [over.oper]) or a surrogate for a conversion to a
734 /// function pointer or reference (C++ [over.call.object]).
735 FunctionDecl *Function;
736
737 /// FoundDecl - The original declaration that was looked up /
738 /// invented / otherwise found, together with its access.
739 /// Might be a UsingShadowDecl or a FunctionTemplateDecl.
740 DeclAccessPair FoundDecl;
741
742 /// BuiltinParamTypes - Provides the parameter types of a built-in overload
743 /// candidate. Only valid when Function is NULL.
744 QualType BuiltinParamTypes[3];
745
746 /// Surrogate - The conversion function for which this candidate
747 /// is a surrogate, but only if IsSurrogate is true.
748 CXXConversionDecl *Surrogate;
749
750 /// The conversion sequences used to convert the function arguments
751 /// to the function parameters.
752 ConversionSequenceList Conversions;
753
754 /// The FixIt hints which can be used to fix the Bad candidate.
755 ConversionFixItGenerator Fix;
756
757 /// Viable - True to indicate that this overload candidate is viable.
758 bool Viable : 1;
759
760 /// IsSurrogate - True to indicate that this candidate is a
761 /// surrogate for a conversion to a function pointer or reference
762 /// (C++ [over.call.object]).
763 bool IsSurrogate : 1;
764
765 /// IgnoreObjectArgument - True to indicate that the first
766 /// argument's conversion, which for this function represents the
767 /// implicit object argument, should be ignored. This will be true
768 /// when the candidate is a static member function (where the
769 /// implicit object argument is just a placeholder) or a
770 /// non-static member function when the call doesn't have an
771 /// object argument.
772 bool IgnoreObjectArgument : 1;
773
774 /// True if the candidate was found using ADL.
775 CallExpr::ADLCallKind IsADLCandidate : 1;
776
777 /// FailureKind - The reason why this candidate is not viable.
778 /// Actually an OverloadFailureKind.
779 unsigned char FailureKind;
780
781 /// The number of call arguments that were explicitly provided,
782 /// to be used while performing partial ordering of function templates.
783 unsigned ExplicitCallArguments;
784
785 union {
786 DeductionFailureInfo DeductionFailure;
787
788 /// FinalConversion - For a conversion function (where Function is
789 /// a CXXConversionDecl), the standard conversion that occurs
790 /// after the call to the overload candidate to convert the result
791 /// of calling the conversion function to the required type.
792 StandardConversionSequence FinalConversion;
793 };
794
795 /// hasAmbiguousConversion - Returns whether this overload
796 /// candidate requires an ambiguous conversion or not.
797 bool hasAmbiguousConversion() const {
798 for (auto &C : Conversions) {
799 if (!C.isInitialized()) return false;
800 if (C.isAmbiguous()) return true;
801 }
802 return false;
803 }
804
805 bool TryToFixBadConversion(unsigned Idx, Sema &S) {
806 bool CanFix = Fix.tryToFixConversion(
807 Conversions[Idx].Bad.FromExpr,
808 Conversions[Idx].Bad.getFromType(),
809 Conversions[Idx].Bad.getToType(), S);
810
811 // If at least one conversion fails, the candidate cannot be fixed.
812 if (!CanFix)
813 Fix.clear();
814
815 return CanFix;
816 }
817
818 unsigned getNumParams() const {
819 if (IsSurrogate) {
820 auto STy = Surrogate->getConversionType();
821 while (STy->isPointerType() || STy->isReferenceType())
822 STy = STy->getPointeeType();
823 return STy->getAs<FunctionProtoType>()->getNumParams();
824 }
825 if (Function)
826 return Function->getNumParams();
827 return ExplicitCallArguments;
828 }
829
830 private:
831 friend class OverloadCandidateSet;
832 OverloadCandidate() : IsADLCandidate(CallExpr::NotADL) {}
833 };
834
835 /// OverloadCandidateSet - A set of overload candidates, used in C++
836 /// overload resolution (C++ 13.3).
837 class OverloadCandidateSet {
838 public:
839 enum CandidateSetKind {
840 /// Normal lookup.
841 CSK_Normal,
842
843 /// C++ [over.match.oper]:
844 /// Lookup of operator function candidates in a call using operator
845 /// syntax. Candidates that have no parameters of class type will be
846 /// skipped unless there is a parameter of (reference to) enum type and
847 /// the corresponding argument is of the same enum type.
848 CSK_Operator,
849
850 /// C++ [over.match.copy]:
851 /// Copy-initialization of an object of class type by user-defined
852 /// conversion.
853 CSK_InitByUserDefinedConversion,
854
855 /// C++ [over.match.ctor], [over.match.list]
856 /// Initialization of an object of class type by constructor,
857 /// using either a parenthesized or braced list of arguments.
858 CSK_InitByConstructor,
859 };
860
861 private:
862 SmallVector<OverloadCandidate, 16> Candidates;
863 llvm::SmallPtrSet<Decl *, 16> Functions;
864
865 // Allocator for ConversionSequenceLists. We store the first few of these
866 // inline to avoid allocation for small sets.
867 llvm::BumpPtrAllocator SlabAllocator;
868
869 SourceLocation Loc;
870 CandidateSetKind Kind;
871
872 constexpr static unsigned NumInlineBytes =
873 24 * sizeof(ImplicitConversionSequence);
874 unsigned NumInlineBytesUsed = 0;
875 llvm::AlignedCharArray<alignof(void *), NumInlineBytes> InlineSpace;
876
877 /// If we have space, allocates from inline storage. Otherwise, allocates
878 /// from the slab allocator.
879 /// FIXME: It would probably be nice to have a SmallBumpPtrAllocator
880 /// instead.
881 /// FIXME: Now that this only allocates ImplicitConversionSequences, do we
882 /// want to un-generalize this?
883 template <typename T>
884 T *slabAllocate(unsigned N) {
885 // It's simpler if this doesn't need to consider alignment.
886 static_assert(alignof(T) == alignof(void *),
887 "Only works for pointer-aligned types.");
888 static_assert(std::is_trivial<T>::value ||
889 std::is_same<ImplicitConversionSequence, T>::value,
890 "Add destruction logic to OverloadCandidateSet::clear().");
891
892 unsigned NBytes = sizeof(T) * N;
893 if (NBytes > NumInlineBytes - NumInlineBytesUsed)
894 return SlabAllocator.Allocate<T>(N);
895 char *FreeSpaceStart = InlineSpace.buffer + NumInlineBytesUsed;
896 assert(uintptr_t(FreeSpaceStart) % alignof(void *) == 0 &&
897 "Misaligned storage!");
898
899 NumInlineBytesUsed += NBytes;
900 return reinterpret_cast<T *>(FreeSpaceStart);
901 }
902
903 void destroyCandidates();
904
905 public:
906 OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK)
907 : Loc(Loc), Kind(CSK) {}
908 OverloadCandidateSet(const OverloadCandidateSet &) = delete;
909 OverloadCandidateSet &operator=(const OverloadCandidateSet &) = delete;
910 ~OverloadCandidateSet() { destroyCandidates(); }
911
912 SourceLocation getLocation() const { return Loc; }
913 CandidateSetKind getKind() const { return Kind; }
914
915 /// Determine when this overload candidate will be new to the
916 /// overload set.
917 bool isNewCandidate(Decl *F) {
918 return Functions.insert(F->getCanonicalDecl()).second;
919 }
920
921 /// Clear out all of the candidates.
922 void clear(CandidateSetKind CSK);
923
924 using iterator = SmallVectorImpl<OverloadCandidate>::iterator;
925
926 iterator begin() { return Candidates.begin(); }
927 iterator end() { return Candidates.end(); }
928
929 size_t size() const { return Candidates.size(); }
930 bool empty() const { return Candidates.empty(); }
931
932 /// Allocate storage for conversion sequences for NumConversions
933 /// conversions.
934 ConversionSequenceList
935 allocateConversionSequences(unsigned NumConversions) {
936 ImplicitConversionSequence *Conversions =
937 slabAllocate<ImplicitConversionSequence>(NumConversions);
938
939 // Construct the new objects.
940 for (unsigned I = 0; I != NumConversions; ++I)
941 new (&Conversions[I]) ImplicitConversionSequence();
942
943 return ConversionSequenceList(Conversions, NumConversions);
944 }
945
946 /// Add a new candidate with NumConversions conversion sequence slots
947 /// to the overload set.
948 OverloadCandidate &addCandidate(unsigned NumConversions = 0,
949 ConversionSequenceList Conversions = None) {
950 assert((Conversions.empty() || Conversions.size() == NumConversions) &&
951 "preallocated conversion sequence has wrong length");
952
953 Candidates.push_back(OverloadCandidate());
954 OverloadCandidate &C = Candidates.back();
955 C.Conversions = Conversions.empty()
956 ? allocateConversionSequences(NumConversions)
957 : Conversions;
958 return C;
959 }
960
961 /// Find the best viable function on this overload set, if it exists.
962 OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc,
963 OverloadCandidateSet::iterator& Best);
964
965 void NoteCandidates(Sema &S,
966 OverloadCandidateDisplayKind OCD,
967 ArrayRef<Expr *> Args,
968 StringRef Opc = "",
969 SourceLocation Loc = SourceLocation(),
970 llvm::function_ref<bool(OverloadCandidate&)> Filter =
971 [](OverloadCandidate&) { return true; });
972 };
973
974 bool isBetterOverloadCandidate(Sema &S,
975 const OverloadCandidate &Cand1,
976 const OverloadCandidate &Cand2,
977 SourceLocation Loc,
978 OverloadCandidateSet::CandidateSetKind Kind);
979
980 struct ConstructorInfo {
981 DeclAccessPair FoundDecl;
982 CXXConstructorDecl *Constructor;
983 FunctionTemplateDecl *ConstructorTmpl;
984
985 explicit operator bool() const { return Constructor; }
986 };
987
988 // FIXME: Add an AddOverloadCandidate / AddTemplateOverloadCandidate overload
989 // that takes one of these.
990 inline ConstructorInfo getConstructorInfo(NamedDecl *ND) {
991 if (isa<UsingDecl>(ND))
992 return ConstructorInfo{};
993
994 // For constructors, the access check is performed against the underlying
995 // declaration, not the found declaration.
996 auto *D = ND->getUnderlyingDecl();
997 ConstructorInfo Info = {DeclAccessPair::make(ND, D->getAccess()), nullptr,
998 nullptr};
999 Info.ConstructorTmpl = dyn_cast<FunctionTemplateDecl>(D);
1000 if (Info.ConstructorTmpl)
1001 D = Info.ConstructorTmpl->getTemplatedDecl();
1002 Info.Constructor = dyn_cast<CXXConstructorDecl>(D);
1003 return Info;
1004 }
1005
1006 } // namespace clang
1007
1008 #endif // LLVM_CLANG_SEMA_OVERLOAD_H
clang::OverloadCandidate::ExplicitCallArguments
unsigned ExplicitCallArguments
The number of call arguments that were explicitly provided, to be used while performing partial order...
Definition: Overload.h:783
clang::UserDefinedConversionSequence::FoundConversionFunction
DeclAccessPair FoundConversionFunction
The declaration that we found via name lookup, which might be the same as ConversionFunction or it mi...
Definition: Overload.h:383
clang::ICK_Function_Conversion
Function pointer conversion (C++17 [conv.fctptr])
Definition: Overload.h:93
clang::StandardConversionSequence::DeprecatedStringLiteralToCharPtr
unsigned DeprecatedStringLiteralToCharPtr
Whether this is the deprecated conversion of a string literal to a pointer to non-const character dat...
Definition: Overload.h:250
clang::ovl_fail_bad_target
(CUDA) This candidate was not viable because the callee was not accessible from the caller&#39;s target (...
Definition: Overload.h:703
clang::BadConversionSequence::setFromType
void setFromType(QualType T)
Definition: Overload.h:479
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1738
clang::ImplicitConversionSequence::setStdInitializerListElement
void setStdInitializerListElement(bool V=true)
Definition: Overload.h:650
clang::UserDefinedConversionSequence::EllipsisConversion
bool EllipsisConversion
EllipsisConversion - When this is true, it means user-defined conversion sequence starts with a ...
Definition: Overload.h:364
clang::OverloadCandidateSet::end
iterator end()
Definition: Overload.h:927
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:638
clang::AmbiguousConversionSequence::setToType
void setToType(QualType T)
Definition: Overload.h:406
clang::ImplicitConversionKind
ImplicitConversionKind
ImplicitConversionKind - The kind of implicit conversion used to convert an argument to a parameter&#39;s...
Definition: Overload.h:79
clang::StandardConversionSequence::setFromType
void setFromType(QualType T)
Definition: Overload.h:304
clang::ICR_C_Conversion_Extension
Conversion not allowed by the C standard, but that we accept as an extension anyway.
Definition: Overload.h:196
clang::ConversionSequenceList
llvm::MutableArrayRef< ImplicitConversionSequence > ConversionSequenceList
A list of implicit conversion sequences for the arguments of an OverloadCandidate.
Definition: Overload.h:727
clang::AmbiguousConversionSequence::getToType
QualType getToType() const
Definition: Overload.h:401
clang::DeductionFailureInfo
A structure used to record information about a failed template argument deduction, for diagnosis.
Definition: TemplateDeduction.h:228
clang::OverloadCandidateSet::empty
bool empty() const
Definition: Overload.h:930
clang::NK_Dependent_Narrowing
Cannot tell whether this is a narrowing conversion because the expression is value-dependent.
Definition: Overload.h:219
clang::Type::getPointeeType
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:505
clang::ICK_Vector_Conversion
Vector conversions.
Definition: Overload.h:135
Type.h
C Language Family Type Representation.
clang::ConversionFixItGenerator::tryToFixConversion
bool tryToFixConversion(const Expr *FromExpr, const QualType FromQTy, const QualType ToQTy, Sema &S)
If possible, generates and stores a fix for the given conversion.
Definition: SemaFixItUtils.cpp:51
clang::AmbiguousConversionSequence::const_iterator
ConversionSet::const_iterator const_iterator
Definition: Overload.h:425
clang::ICK_Complex_Conversion
Complex conversions (C99 6.3.1.6)
Definition: Overload.h:114
clang::ImplicitConversionSequence::UserDefined
UserDefinedConversionSequence UserDefined
When ConversionKind == UserDefinedConversion, provides the details of the user-defined conversion seq...
Definition: Overload.h:530
clang::ImplicitConversionSequence::ImplicitConversionSequence
ImplicitConversionSequence()
Definition: Overload.h:541
clang::getConstructorInfo
ConstructorInfo getConstructorInfo(NamedDecl *ND)
Definition: Overload.h:990
clang::isBetterOverloadCandidate
bool isBetterOverloadCandidate(Sema &S, const OverloadCandidate &Cand1, const OverloadCandidate &Cand2, SourceLocation Loc, OverloadCandidateSet::CandidateSetKind Kind)
isBetterOverloadCandidate - Determines whether the first overload candidate is a better candidate tha...
Definition: SemaOverload.cpp:9098
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
clang::BadConversionSequence::no_conversion
Definition: Overload.h:439
clang::PartialDiagnostic
Definition: PartialDiagnostic.h:35
clang::OverloadCandidateSet::CSK_Normal
Normal lookup.
Definition: Overload.h:841
DeclTemplate.h
Defines the C++ template declaration subclasses.
clang::NK_Not_Narrowing
Not a narrowing conversion.
Definition: Overload.h:205
clang::ImplicitConversionRank
ImplicitConversionRank
ImplicitConversionRank - The rank of an implicit conversion kind.
Definition: Overload.h:172
clang::StandardConversionSequence::IncompatibleObjC
unsigned IncompatibleObjC
IncompatibleObjC - Whether this is an Objective-C conversion that we should warn about (if we actuall...
Definition: Overload.h:258
clang::CodeGen::clear
virtual void clear()
clang::OR_Ambiguous
Ambiguous candidates found.
Definition: Overload.h:60
clang::ICK_Compatible_Conversion
Conversions between compatible types in C99.
Definition: Overload.h:129
clang::ImplicitConversionSequence::EllipsisConversion
Definition: Overload.h:497
clang::OverloadCandidate::IgnoreObjectArgument
bool IgnoreObjectArgument
IgnoreObjectArgument - True to indicate that the first argument&#39;s conversion, which for this function...
Definition: Overload.h:772
clang::CXXConversionDecl::getConversionType
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Definition: DeclCXX.h:2800
clang::StandardConversionSequence::DirectBinding
unsigned DirectBinding
DirectBinding - True when this is a reference binding that is a direct binding (C++ [dcl...
Definition: Overload.h:266
clang::CXXConstructorDecl
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2484
clang::ICR_Exact_Match
Exact Match.
Definition: Overload.h:174
clang::OverloadCandidate::hasAmbiguousConversion
bool hasAmbiguousConversion() const
hasAmbiguousConversion - Returns whether this overload candidate requires an ambiguous conversion or ...
Definition: Overload.h:797
clang::StandardConversionSequence::getFromType
QualType getFromType() const
Definition: Overload.h:317
clang::ImplicitConversionSequence::isFailure
bool isFailure() const
Definition: Overload.h:606
clang::ImplicitConversionSequence::isUserDefined
bool isUserDefined() const
Definition: Overload.h:605
clang::AmbiguousConversionSequence::FromTypePtr
void * FromTypePtr
Definition: Overload.h:393
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6748
clang::OverloadCandidate::IsSurrogate
bool IsSurrogate
IsSurrogate - True to indicate that this candidate is a surrogate for a conversion to a function poin...
Definition: Overload.h:763
clang::NamedDecl::getUnderlyingDecl
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:432
clang::UserDefinedConversionSequence::HadMultipleCandidates
bool HadMultipleCandidates
HadMultipleCandidates - When this is true, it means that the conversion function was resolved from an...
Definition: Overload.h:369
clang::AmbiguousConversionSequence::begin
iterator begin()
Definition: Overload.h:422
clang::ICR_Conversion
Conversion.
Definition: Overload.h:180
clang::StandardConversionSequence::ToTypePtrs
void * ToTypePtrs[3]
ToType - The types that this conversion is converting to in each step.
Definition: Overload.h:294
clang::ImplicitConversionSequence::getKind
Kind getKind() const
Definition: Overload.h:570
clang::OverloadCandidateSet::addCandidate
OverloadCandidate & addCandidate(unsigned NumConversions=0, ConversionSequenceList Conversions=None)
Add a new candidate with NumConversions conversion sequence slots to the overload set...
Definition: Overload.h:948
clang::ConversionFixItGenerator::clear
void clear()
Definition: SemaFixItUtils.h:80
clang::ImplicitConversionSequence::ImplicitConversionSequence
ImplicitConversionSequence(const ImplicitConversionSequence &Other)
Definition: Overload.h:546
clang::AmbiguousConversionSequence::getFromType
QualType getFromType() const
Definition: Overload.h:397
clang::ICK_Boolean_Conversion
Boolean conversions (C++ [conv.bool])
Definition: Overload.h:126
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
clang::StandardConversionSequence::BindsToFunctionLvalue
unsigned BindsToFunctionLvalue
Whether we&#39;re binding to a function lvalue.
Definition: Overload.h:273
clang::OverloadCandidateSet::CSK_InitByUserDefinedConversion
C++ [over.match.copy]: Copy-initialization of an object of class type by user-defined conversion...
Definition: Overload.h:853
clang::ImplicitConversionSequence::Bad
BadConversionSequence Bad
When ConversionKind == BadConversion, provides the details of the bad conversion. ...
Definition: Overload.h:538
clang::ICK_Identity
Identity conversion (no conversion)
Definition: Overload.h:81
clang::OverloadCandidate::IsADLCandidate
CallExpr::ADLCallKind IsADLCandidate
True if the candidate was found using ADL.
Definition: Overload.h:775
clang::ImplicitConversionSequence::isStdInitializerListElement
bool isStdInitializerListElement() const
Whether the target is really a std::initializer_list, and the sequence only represents the worst elem...
Definition: Overload.h:646
clang::ImplicitConversionSequence::Kind
Kind
Kind - The kind of implicit conversion sequence.
Definition: Overload.h:493
clang::AmbiguousConversionSequence::conversions
ConversionSet & conversions()
Definition: Overload.h:408
clang::BadConversionSequence
BadConversionSequence - Records information about an invalid conversion sequence. ...
Definition: Overload.h:437
clang::ICK_Floating_Conversion
Floating point conversions (C++ [conv.double].
Definition: Overload.h:111
clang::ImplicitConversionSequence::setStandard
void setStandard()
Definition: Overload.h:627
clang::ovl_fail_bad_deduction
Definition: Overload.h:674
clang::OverloadCandidateSet::allocateConversionSequences
ConversionSequenceList allocateConversionSequences(unsigned NumConversions)
Allocate storage for conversion sequences for NumConversions conversions.
Definition: Overload.h:935
clang::AmbiguousConversionSequence::end
iterator end()
Definition: Overload.h:423
llvm::SmallVectorImpl
Definition: LLVM.h:37
clang::OverloadCandidateDisplayKind
OverloadCandidateDisplayKind
Definition: Overload.h:66
clang::ICK_Floating_Promotion
Floating point promotions (C++ [conv.fpprom])
Definition: Overload.h:102
clang::ImplicitConversionSequence::isInitialized
bool isInitialized() const
Determines whether this conversion sequence has been initialized.
Definition: Overload.h:611
clang::StandardConversionSequence::BindsToRvalue
unsigned BindsToRvalue
Whether we&#39;re binding to an rvalue.
Definition: Overload.h:276
clang::DeclAccessPair::make
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
Definition: DeclAccessPair.h:36
clang::OR_Deleted
Succeeded, but refers to a deleted function.
Definition: Overload.h:63
Uninitialized
Definition: UninitializedValues.cpp:104
clang::ImplicitConversionSequence::operator=
ImplicitConversionSequence & operator=(const ImplicitConversionSequence &Other)
Definition: Overload.h:560
LLVM.h
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
clang::StandardConversionSequence::QualificationIncludesObjCLifetime
unsigned QualificationIncludesObjCLifetime
Whether the qualification conversion involves a change in the Objective-C lifetime (for automatic ref...
Definition: Overload.h:254
clang::StandardConversionSequence::getToType
QualType getToType(unsigned Idx) const
Definition: Overload.h:321
clang::ovl_fail_enable_if
This candidate function was not viable because an enable_if attribute disabled it.
Definition: Overload.h:707
clang::StandardConversionSequence::Second
ImplicitConversionKind Second
Second - The second conversion can be an integral promotion, floating point promotion, integral conversion, floating point conversion, floating-integral conversion, pointer conversion, pointer-to-member conversion, or boolean conversion.
Definition: Overload.h:241
clang::NK_Constant_Narrowing
A narrowing conversion, because a constant expression got narrowed.
Definition: Overload.h:211
clang::StandardConversionSequence::IsLvalueReference
unsigned IsLvalueReference
Whether this is an lvalue reference binding (otherwise, it&#39;s an rvalue reference binding).
Definition: Overload.h:270
clang::NarrowingKind
NarrowingKind
NarrowingKind - The kind of narrowing conversion being performed by a standard conversion sequence ac...
Definition: Overload.h:203
clang::ICK_Qualification
Qualification conversions (C++ [conv.qual])
Definition: Overload.h:96
clang::AmbiguousConversionSequence::setFromType
void setFromType(QualType T)
Definition: Overload.h:405
clang::QualType::getAsOpaquePtr
void * getAsOpaquePtr() const
Definition: Type.h:683
clang::ICK_Num_Conversion_Kinds
The number of conversion kinds.
Definition: Overload.h:165
llvm::ArrayRef
Definition: LLVM.h:32
clang::StandardConversionSequence::Third
ImplicitConversionKind Third
Third - The third conversion can be a qualification conversion or a function conversion.
Definition: Overload.h:245
clang::ICR_Complex_Real_Conversion
Complex <-> Real conversion.
Definition: Overload.h:186
clang::OverloadCandidate::Viable
bool Viable
Viable - True to indicate that this overload candidate is viable.
Definition: Overload.h:758
clang::OverloadCandidate::Conversions
ConversionSequenceList Conversions
The conversion sequences used to convert the function arguments to the function parameters.
Definition: Overload.h:752
clang::ICK_Integral_Promotion
Integral promotions (C++ [conv.prom])
Definition: Overload.h:99
clang::ovl_fail_final_conversion_not_exact
This conversion function template specialization candidate is not viable because the final conversion...
Definition: Overload.h:698
clang::Decl::getCanonicalDecl
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:870
clang::ImplicitConversionSequence::setAsIdentityConversion
void setAsIdentityConversion(QualType T)
Definition: Overload.h:637
clang::ImplicitConversionSequence::isAmbiguous
bool isAmbiguous() const
Definition: Overload.h:604
clang::ICK_Incompatible_Pointer_Conversion
C-only conversion between pointers with incompatible types.
Definition: Overload.h:162
clang::ConstructorInfo
Definition: Overload.h:980
DeclAccessPair.h
clang::ConstructorInfo::FoundDecl
DeclAccessPair FoundDecl
Definition: Overload.h:981
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:278
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3687
clang::ICK_TransparentUnionConversion
Transparent Union Conversions.
Definition: Overload.h:147
clang::ovl_fail_trivial_conversion
This conversion candidate was not considered because it duplicates the work of a trivial or derived-t...
Definition: Overload.h:679
clang::OverloadCandidateSet::getKind
CandidateSetKind getKind() const
Definition: Overload.h:913
clang::OverloadCandidateSet::isNewCandidate
bool isNewCandidate(Decl *F)
Determine when this overload candidate will be new to the overload set.
Definition: Overload.h:917
clang::NK_Type_Narrowing
A narrowing conversion by virtue of the source and destination types.
Definition: Overload.h:208
clang::ICR_Promotion
Promotion.
Definition: Overload.h:177
clang::OverloadCandidate::FinalConversion
StandardConversionSequence FinalConversion
FinalConversion - For a conversion function (where Function is a CXXConversionDecl), the standard conversion that occurs after the call to the overload candidate to convert the result of calling the conversion function to the required type.
Definition: Overload.h:792
clang::ICR_Writeback_Conversion
ObjC ARC writeback conversion.
Definition: Overload.h:189
clang::ICR_OCL_Scalar_Widening
OpenCL Scalar Widening.
Definition: Overload.h:183
clang::Expr
This represents one expression.
Definition: Expr.h:106
clang::AmbiguousConversionSequence
Represents an ambiguous user-defined conversion sequence.
Definition: Overload.h:389
clang::ImplicitConversionSequence::isEllipsis
bool isEllipsis() const
Definition: Overload.h:603
llvm::MutableArrayRef< ImplicitConversionSequence >
clang::ovl_non_default_multiversion_function
This candidate was not viable because it is a non-default multiversioned function.
Definition: Overload.h:721
clang::ovl_fail_bad_conversion
Definition: Overload.h:673
clang::ImplicitConversionSequence::setEllipsis
void setEllipsis()
Definition: Overload.h:628
clang::ovl_fail_inhctor_slice
This inherited constructor is not viable because it would slice the argument.
Definition: Overload.h:717
clang::OverloadCandidateSet::getLocation
SourceLocation getLocation() const
Definition: Overload.h:912
clang::UserDefinedConversionSequence::After
StandardConversionSequence After
After - Represents the standard conversion that occurs after the actual user-defined conversion...
Definition: Overload.h:373
DeclBase.h
clang::ICK_Zero_Queue_Conversion
Zero constant to queue.
Definition: Overload.h:156
bool
#define bool
Definition: stdbool.h:31
clang::StandardConversionSequence::CopyConstructor
CXXConstructorDecl * CopyConstructor
CopyConstructor - The copy constructor that is used to perform this conversion, when the conversion i...
Definition: Overload.h:301
clang::OR_Success
Overload resolution succeeded.
Definition: Overload.h:54
clang::ImplicitConversionSequence::isBad
bool isBad() const
Definition: Overload.h:601
clang::BadConversionSequence::FailureKind
FailureKind
Definition: Overload.h:438
TemplateDeduction.h
clang::StandardConversionSequence::ReferenceBinding
unsigned ReferenceBinding
ReferenceBinding - True when this is a reference binding (C++ [over.ics.ref]).
Definition: Overload.h:262
clang::ICK_Floating_Integral
Floating-integral conversions (C++ [conv.fpint])
Definition: Overload.h:117
clang::BadConversionSequence::init
void init(FailureKind K, Expr *From, QualType To)
Definition: Overload.h:459
clang::ovl_fail_illegal_constructor
This conversion candidate was not considered because it is an illegal instantiation of a constructor ...
Definition: Overload.h:690
clang::OverloadCandidate::TryToFixBadConversion
bool TryToFixBadConversion(unsigned Idx, Sema &S)
Definition: Overload.h:805
clang::Expr::getType
QualType getType() const
Definition: Expr.h:128
clang::OverloadCandidate::Surrogate
CXXConversionDecl * Surrogate
Surrogate - The conversion function for which this candidate is a surrogate, but only if IsSurrogate ...
Definition: Overload.h:748
clang::UserDefinedConversionSequence
UserDefinedConversionSequence - Represents a user-defined conversion sequence (C++ 13...
Definition: Overload.h:344
clang::ovl_fail_addr_not_available
This candidate was not viable because its address could not be taken.
Definition: Overload.h:710
clang::AmbiguousConversionSequence::conversions
const ConversionSet & conversions() const
Definition: Overload.h:412
clang::ImplicitConversionSequence::Standard
StandardConversionSequence Standard
When ConversionKind == StandardConversion, provides the details of the standard conversion sequence...
Definition: Overload.h:526
clang::ImplicitConversionSequence::CompareKind
CompareKind
Definition: Overload.h:657
clang::CXXConversionDecl
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2768
uintptr_t
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Definition: opencl-c.h:90
clang::NK_Variable_Narrowing
A narrowing conversion, because a non-constant-expression variable might have got narrowed...
Definition: Overload.h:215
clang::BadConversionSequence::getFromType
QualType getFromType() const
Definition: Overload.h:471
clang::ICK_Lvalue_To_Rvalue
Lvalue-to-rvalue conversion (C++ [conv.lval])
Definition: Overload.h:84
clang::StandardConversionSequence::getNarrowingKind
NarrowingKind getNarrowingKind(ASTContext &Context, const Expr *Converted, APValue &ConstantValue, QualType &ConstantType, bool IgnoreFloatToIntegralConversion=false) const
Check if this standard conversion sequence represents a narrowing conversion, according to C++11 [dcl...
Definition: SemaOverload.cpp:294
clang::OverloadFailureKind
OverloadFailureKind
Definition: Overload.h:670
clang::StandardConversionSequence::ObjCLifetimeConversionBinding
unsigned ObjCLifetimeConversionBinding
Whether this binds a reference to an object with a different Objective-C lifetime qualifier...
Definition: Overload.h:284
clang::ImplicitConversionSequence::UserDefinedConversion
Definition: Overload.h:495
clang::ConstructorInfo::Constructor
CXXConstructorDecl * Constructor
Definition: Overload.h:982
clang::tooling::Filter
llvm::cl::opt< std::string > Filter
clang::ICK_Integral_Conversion
Integral conversions (C++ [conv.integral])
Definition: Overload.h:108
clang::OverloadCandidateSet::iterator
SmallVectorImpl< OverloadCandidate >::iterator iterator
Definition: Overload.h:924
clang::ICK_Complex_Promotion
Complex promotions (Clang extension)
Definition: Overload.h:105
false
#define false
Definition: stdbool.h:33
Kind
Kind
Definition: ChrootChecker.cpp:29
clang::ImplicitConversionSequence
ImplicitConversionSequence - Represents an implicit conversion sequence, which may be a standard conv...
Definition: Overload.h:487
clang::OverloadCandidateSet::~OverloadCandidateSet
~OverloadCandidateSet()
Definition: Overload.h:910
clang::StandardConversionSequence::isPointerConversionToVoidPointer
bool isPointerConversionToVoidPointer(ASTContext &Context) const
isPointerConversionToVoidPointer - Determines whether this conversion is a conversion of a pointer to...
Definition: SemaOverload.cpp:242
clang::OverloadCandidate
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
Definition: Overload.h:730
clang::FunctionTemplateDecl::getTemplatedDecl
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Definition: DeclTemplate.h:1024
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::OverloadCandidateSet::CSK_InitByConstructor
C++ [over.match.ctor], [over.match.list] Initialization of an object of class type by constructor...
Definition: Overload.h:858
clang::AmbiguousConversionSequence::iterator
ConversionSet::iterator iterator
Definition: Overload.h:420
clang::StandardConversionSequence::isIdentityConversion
bool isIdentityConversion() const
Definition: Overload.h:328
clang::ICK_Vector_Splat
A vector splat from an arithmetic type.
Definition: Overload.h:138
clang::ImplicitConversionSequence::AmbiguousConversion
Definition: Overload.h:496
clang::OverloadingResult
OverloadingResult
OverloadingResult - Capture the result of performing overload resolution.
Definition: Overload.h:52
clang::ICK_Writeback_Conversion
Objective-C ARC writeback conversion.
Definition: Overload.h:150
clang::BadConversionSequence::init
void init(FailureKind K, QualType From, QualType To)
Definition: Overload.h:464
llvm::SmallVector
Definition: LLVM.h:36
clang::StandardConversionSequence::setAsIdentityConversion
void setAsIdentityConversion()
StandardConversionSequence - Set the standard conversion sequence to the identity conversion...
Definition: SemaOverload.cpp:185
clang::ICK_Pointer_Conversion
Pointer conversions (C++ [conv.ptr])
Definition: Overload.h:120
clang::OverloadCandidateSet::CSK_Operator
C++ [over.match.oper]: Lookup of operator function candidates in a call using operator syntax...
Definition: Overload.h:848
clang::OCD_AllCandidates
Requests that all candidates be shown.
Definition: Overload.h:69
SemaFixItUtils.h
clang::ImplicitConversionSequence::isStandard
bool isStandard() const
Definition: Overload.h:602
clang::ICK_Derived_To_Base
Derived-to-base (C++ [over.best.ics])
Definition: Overload.h:132
clang::ICK_Complex_Real
Complex-real conversions (C99 6.3.1.7)
Definition: Overload.h:141
clang::OverloadCandidateSet
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13...
Definition: Overload.h:837
clang::ImplicitConversionSequence::setBad
void setBad(BadConversionSequence::FailureKind Failure, Expr *FromExpr, QualType ToType)
Sets this sequence as a bad conversion for an explicit argument.
Definition: Overload.h:614
clang::QualType::getFromOpaquePtr
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:685
clang::BadConversionSequence::setFromExpr
void setFromExpr(Expr *E)
Definition: Overload.h:474
clang::MultiVersionKind::None
clang::OverloadCandidate::getNumParams
unsigned getNumParams() const
Definition: Overload.h:818
clang::StandardConversionSequence::isPointerConversionToBool
bool isPointerConversionToBool() const
isPointerConversionToBool - Determines whether this conversion is a conversion of a pointer or pointe...
Definition: SemaOverload.cpp:219
clang::ImplicitConversionSequence::setAmbiguous
void setAmbiguous()
Definition: Overload.h:631
clang::DeclAccessPair
A POD class for pairing a NamedDecl* with an access specifier.
Definition: DeclAccessPair.h:30
clang::GetConversionRank
ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind)
GetConversionRank - Retrieve the implicit conversion rank corresponding to the given implicit convers...
Definition: SemaOverload.cpp:112
clang::StandardConversionSequence::FoundCopyConstructor
DeclAccessPair FoundCopyConstructor
Definition: Overload.h:302
Decl.h
clang::OverloadCandidateSet::OverloadCandidateSet
OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK)
Definition: Overload.h:906
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::ImplicitConversionSequence::~ImplicitConversionSequence
~ImplicitConversionSequence()
Definition: Overload.h:566
clang::Decl::getAccess
AccessSpecifier getAccess() const
Definition: DeclBase.h:462
clang::ICK_C_Only_Conversion
Conversions allowed in C, but not C++.
Definition: Overload.h:159
clang::ICK_Array_To_Pointer
Array-to-pointer conversion (C++ [conv.array])
Definition: Overload.h:87
clang::UserDefinedConversionSequence::Before
StandardConversionSequence Before
Represents the standard conversion that occurs before the actual user-defined conversion.
Definition: Overload.h:356
clang::OCD_ViableCandidates
Requests that only viable candidates be shown.
Definition: Overload.h:72
clang::OverloadCandidate::Function
FunctionDecl * Function
Function - The actual function that this candidate represents.
Definition: Overload.h:735
clang::ovl_fail_too_few_arguments
Definition: Overload.h:672
clang::BadConversionSequence::Kind
FailureKind Kind
Definition: Overload.h:449
clang::UserDefinedConversionSequence::ConversionFunction
FunctionDecl * ConversionFunction
ConversionFunction - The function that will perform the user-defined conversion.
Definition: Overload.h:378
clang::ovl_fail_too_many_arguments
Definition: Overload.h:671
clang::ICR_C_Conversion
Conversion only allowed in the C standard (e.g. void* to char*).
Definition: Overload.h:192
clang::AmbiguousConversionSequence::ToTypePtr
void * ToTypePtr
Definition: Overload.h:394
clang::BadConversionSequence::setToType
void setToType(QualType T)
Definition: Overload.h:480
clang::OverloadCandidateSet::CandidateSetKind
CandidateSetKind
Definition: Overload.h:839
clang::StandardConversionSequence::setAllToTypes
void setAllToTypes(QualType T)
Definition: Overload.h:311
clang::ImplicitConversionSequence::getKindRank
unsigned getKindRank() const
Return a ranking of the implicit conversion sequence kind, where smaller ranks represent better conve...
Definition: Overload.h:582
clang::BadConversionSequence::FromExpr
Expr * FromExpr
Definition: Overload.h:447
clang::ovl_fail_ext_disabled
This candidate was not viable because its OpenCL extension is disabled.
Definition: Overload.h:713
clang::ImplicitConversionSequence::setUserDefined
void setUserDefined()
Definition: Overload.h:629
clang::StandardConversionSequence::BindsImplicitObjectArgumentWithoutRefQualifier
unsigned BindsImplicitObjectArgumentWithoutRefQualifier
Whether this binds an implicit object argument to a non-static member function without a ref-qualifie...
Definition: Overload.h:280
clang::OverloadCandidate::FailureKind
unsigned char FailureKind
FailureKind - The reason why this candidate is not viable.
Definition: Overload.h:779
clang::ImplicitConversionSequence::setBad
void setBad(BadConversionSequence::FailureKind Failure, QualType FromType, QualType ToType)
Sets this sequence as a bad conversion for an implicit argument.
Definition: Overload.h:621
clang::OverloadCandidate::FoundDecl
DeclAccessPair FoundDecl
FoundDecl - The original declaration that was looked up / invented / otherwise found, together with its access.
Definition: Overload.h:740
clang::ICK_Block_Pointer_Conversion
Block Pointer conversions.
Definition: Overload.h:144
clang::APValue
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Definition: APValue.h:38
clang::OverloadCandidate::Fix
ConversionFixItGenerator Fix
The FixIt hints which can be used to fix the Bad candidate.
Definition: Overload.h:755
clang::ImplicitConversionSequence::Ambiguous
AmbiguousConversionSequence Ambiguous
When ConversionKind == AmbiguousConversion, provides the details of the ambiguous conversion...
Definition: Overload.h:534
clang::AmbiguousConversionSequence::addConversion
void addConversion(NamedDecl *Found, FunctionDecl *D)
Definition: Overload.h:416
DeclCXX.h
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
clang::ICK_Function_To_Pointer
Function-to-pointer (C++ [conv.array])
Definition: Overload.h:90
SourceLocation.h
Defines the clang::SourceLocation class and associated facilities.
clang::BadConversionSequence::getToType
QualType getToType() const
Definition: Overload.h:472
clang::ConstructorInfo::ConstructorTmpl
FunctionTemplateDecl * ConstructorTmpl
Definition: Overload.h:983
clang::AmbiguousConversionSequence::begin
const_iterator begin() const
Definition: Overload.h:427
clang::AttrSyntax::C
clang::BadConversionSequence::unrelated_class
Definition: Overload.h:440
Expr.h
clang::StandardConversionSequence::FromTypePtr
void * FromTypePtr
FromType - The type that this conversion is converting from.
Definition: Overload.h:289
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2396
clang::StandardConversionSequence::getRank
ImplicitConversionRank getRank() const
getRank - Retrieve the rank of this standard conversion sequence (C++ 13.3.3.1.1p3).
Definition: SemaOverload.cpp:204
getKind
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:954
clang::CallExpr::ADLCallKind
ADLCallKind
Definition: Expr.h:2443
clang::ConversionFixItGenerator
The class facilities generation and storage of conversion FixIts.
Definition: SemaFixItUtils.h:33
clang::ICK_Zero_Event_Conversion
Zero constant to event (OpenCL1.2 6.12.10)
Definition: Overload.h:153
clang::StandardConversionSequence::First
ImplicitConversionKind First
First – The first conversion can be an lvalue-to-rvalue conversion, array-to-pointer conversion...
Definition: Overload.h:235
clang::OR_No_Viable_Function
No viable function found.
Definition: Overload.h:57
clang::OverloadCandidate::DeductionFailure
DeductionFailureInfo DeductionFailure
Definition: Overload.h:786
clang::OverloadCandidateSet::size
size_t size() const
Definition: Overload.h:929
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:249
clang::StandardConversionSequence::dump
void dump() const
dump - Print this standard conversion sequence to standard error.
Definition: SemaOverload.cpp:468
clang::ICK_Pointer_Member
Pointer-to-member conversions (C++ [conv.mem])
Definition: Overload.h:123
clang::BadConversionSequence::bad_qualifiers
Definition: Overload.h:441
clang::StandardConversionSequence::setToType
void setToType(unsigned Idx, QualType T)
Definition: Overload.h:306
clang::FunctionDecl::getNumParams
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3055
clang::OverloadCandidateSet::begin
iterator begin()
Definition: Overload.h:926
clang::ovl_fail_bad_final_conversion
This conversion candidate is not viable because its result type is not implicitly convertible to the ...
Definition: Overload.h:694
clang::AmbiguousConversionSequence::end
const_iterator end() const
Definition: Overload.h:428
clang::FunctionTemplateDecl
Declaration of a template function.
Definition: DeclTemplate.h:969
clang::BadConversionSequence::lvalue_ref_to_rvalue
Definition: Overload.h:442
clang::StandardConversionSequence
StandardConversionSequence - represents a standard conversion sequence (C++ 13.3.3.1.1).
Definition: Overload.h:230