Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Sema/Overload.h
Line
Count
Source (jump to first uncovered line)
1
//===- Overload.h - C++ Overloading -----------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file defines the data structures and types used in C++
10
// overload resolution.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_SEMA_OVERLOAD_H
15
#define LLVM_CLANG_SEMA_OVERLOAD_H
16
17
#include "clang/AST/Decl.h"
18
#include "clang/AST/DeclAccessPair.h"
19
#include "clang/AST/DeclBase.h"
20
#include "clang/AST/DeclCXX.h"
21
#include "clang/AST/DeclTemplate.h"
22
#include "clang/AST/Expr.h"
23
#include "clang/AST/Type.h"
24
#include "clang/Basic/LLVM.h"
25
#include "clang/Basic/SourceLocation.h"
26
#include "clang/Sema/SemaFixItUtils.h"
27
#include "clang/Sema/TemplateDeduction.h"
28
#include "llvm/ADT/ArrayRef.h"
29
#include "llvm/ADT/None.h"
30
#include "llvm/ADT/STLExtras.h"
31
#include "llvm/ADT/SmallPtrSet.h"
32
#include "llvm/ADT/SmallVector.h"
33
#include "llvm/ADT/StringRef.h"
34
#include "llvm/Support/AlignOf.h"
35
#include "llvm/Support/Allocator.h"
36
#include "llvm/Support/Casting.h"
37
#include "llvm/Support/ErrorHandling.h"
38
#include <cassert>
39
#include <cstddef>
40
#include <cstdint>
41
#include <utility>
42
43
namespace clang {
44
45
class APValue;
46
class ASTContext;
47
class Sema;
48
49
  /// OverloadingResult - Capture the result of performing overload
50
  /// resolution.
51
  enum OverloadingResult {
52
    /// Overload resolution succeeded.
53
    OR_Success,
54
55
    /// No viable function found.
56
    OR_No_Viable_Function,
57
58
    /// Ambiguous candidates found.
59
    OR_Ambiguous,
60
61
    /// Succeeded, but refers to a deleted function.
62
    OR_Deleted
63
  };
64
65
  enum OverloadCandidateDisplayKind {
66
    /// Requests that all candidates be shown.  Viable candidates will
67
    /// be printed first.
68
    OCD_AllCandidates,
69
70
    /// Requests that only viable candidates be shown.
71
    OCD_ViableCandidates,
72
73
    /// Requests that only tied-for-best candidates be shown.
74
    OCD_AmbiguousCandidates
75
  };
76
77
  /// The parameter ordering that will be used for the candidate. This is
78
  /// used to represent C++20 binary operator rewrites that reverse the order
79
  /// of the arguments. If the parameter ordering is Reversed, the Args list is
80
  /// reversed (but obviously the ParamDecls for the function are not).
81
  ///
82
  /// After forming an OverloadCandidate with reversed parameters, the list
83
  /// of conversions will (as always) be indexed by argument, so will be
84
  /// in reverse parameter order.
85
  enum class OverloadCandidateParamOrder : char { Normal, Reversed };
86
87
  /// The kinds of rewrite we perform on overload candidates. Note that the
88
  /// values here are chosen to serve as both bitflags and as a rank (lower
89
  /// values are preferred by overload resolution).
90
  enum OverloadCandidateRewriteKind : unsigned {
91
    /// Candidate is not a rewritten candidate.
92
    CRK_None = 0x0,
93
94
    /// Candidate is a rewritten candidate with a different operator name.
95
    CRK_DifferentOperator = 0x1,
96
97
    /// Candidate is a rewritten candidate with a reversed order of parameters.
98
    CRK_Reversed = 0x2,
99
  };
100
101
  /// ImplicitConversionKind - The kind of implicit conversion used to
102
  /// convert an argument to a parameter's type. The enumerator values
103
  /// match with the table titled 'Conversions' in [over.ics.scs] and are listed
104
  /// such that better conversion kinds have smaller values.
105
  enum ImplicitConversionKind {
106
    /// Identity conversion (no conversion)
107
    ICK_Identity = 0,
108
109
    /// Lvalue-to-rvalue conversion (C++ [conv.lval])
110
    ICK_Lvalue_To_Rvalue,
111
112
    /// Array-to-pointer conversion (C++ [conv.array])
113
    ICK_Array_To_Pointer,
114
115
    /// Function-to-pointer (C++ [conv.array])
116
    ICK_Function_To_Pointer,
117
118
    /// Function pointer conversion (C++17 [conv.fctptr])
119
    ICK_Function_Conversion,
120
121
    /// Qualification conversions (C++ [conv.qual])
122
    ICK_Qualification,
123
124
    /// Integral promotions (C++ [conv.prom])
125
    ICK_Integral_Promotion,
126
127
    /// Floating point promotions (C++ [conv.fpprom])
128
    ICK_Floating_Promotion,
129
130
    /// Complex promotions (Clang extension)
131
    ICK_Complex_Promotion,
132
133
    /// Integral conversions (C++ [conv.integral])
134
    ICK_Integral_Conversion,
135
136
    /// Floating point conversions (C++ [conv.double]
137
    ICK_Floating_Conversion,
138
139
    /// Complex conversions (C99 6.3.1.6)
140
    ICK_Complex_Conversion,
141
142
    /// Floating-integral conversions (C++ [conv.fpint])
143
    ICK_Floating_Integral,
144
145
    /// Pointer conversions (C++ [conv.ptr])
146
    ICK_Pointer_Conversion,
147
148
    /// Pointer-to-member conversions (C++ [conv.mem])
149
    ICK_Pointer_Member,
150
151
    /// Boolean conversions (C++ [conv.bool])
152
    ICK_Boolean_Conversion,
153
154
    /// Conversions between compatible types in C99
155
    ICK_Compatible_Conversion,
156
157
    /// Derived-to-base (C++ [over.best.ics])
158
    ICK_Derived_To_Base,
159
160
    /// Vector conversions
161
    ICK_Vector_Conversion,
162
163
    /// Arm SVE Vector conversions
164
    ICK_SVE_Vector_Conversion,
165
166
    /// A vector splat from an arithmetic type
167
    ICK_Vector_Splat,
168
169
    /// Complex-real conversions (C99 6.3.1.7)
170
    ICK_Complex_Real,
171
172
    /// Block Pointer conversions
173
    ICK_Block_Pointer_Conversion,
174
175
    /// Transparent Union Conversions
176
    ICK_TransparentUnionConversion,
177
178
    /// Objective-C ARC writeback conversion
179
    ICK_Writeback_Conversion,
180
181
    /// Zero constant to event (OpenCL1.2 6.12.10)
182
    ICK_Zero_Event_Conversion,
183
184
    /// Zero constant to queue
185
    ICK_Zero_Queue_Conversion,
186
187
    /// Conversions allowed in C, but not C++
188
    ICK_C_Only_Conversion,
189
190
    /// C-only conversion between pointers with incompatible types
191
    ICK_Incompatible_Pointer_Conversion,
192
193
    /// The number of conversion kinds
194
    ICK_Num_Conversion_Kinds,
195
  };
196
197
  /// ImplicitConversionRank - The rank of an implicit conversion
198
  /// kind. The enumerator values match with Table 9 of (C++
199
  /// 13.3.3.1.1) and are listed such that better conversion ranks
200
  /// have smaller values.
201
  enum ImplicitConversionRank {
202
    /// Exact Match
203
    ICR_Exact_Match = 0,
204
205
    /// Promotion
206
    ICR_Promotion,
207
208
    /// Conversion
209
    ICR_Conversion,
210
211
    /// OpenCL Scalar Widening
212
    ICR_OCL_Scalar_Widening,
213
214
    /// Complex <-> Real conversion
215
    ICR_Complex_Real_Conversion,
216
217
    /// ObjC ARC writeback conversion
218
    ICR_Writeback_Conversion,
219
220
    /// Conversion only allowed in the C standard (e.g. void* to char*).
221
    ICR_C_Conversion,
222
223
    /// Conversion not allowed by the C standard, but that we accept as an
224
    /// extension anyway.
225
    ICR_C_Conversion_Extension
226
  };
227
228
  ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind);
229
230
  /// NarrowingKind - The kind of narrowing conversion being performed by a
231
  /// standard conversion sequence according to C++11 [dcl.init.list]p7.
232
  enum NarrowingKind {
233
    /// Not a narrowing conversion.
234
    NK_Not_Narrowing,
235
236
    /// A narrowing conversion by virtue of the source and destination types.
237
    NK_Type_Narrowing,
238
239
    /// A narrowing conversion, because a constant expression got narrowed.
240
    NK_Constant_Narrowing,
241
242
    /// A narrowing conversion, because a non-constant-expression variable might
243
    /// have got narrowed.
244
    NK_Variable_Narrowing,
245
246
    /// Cannot tell whether this is a narrowing conversion because the
247
    /// expression is value-dependent.
248
    NK_Dependent_Narrowing,
249
  };
250
251
  /// StandardConversionSequence - represents a standard conversion
252
  /// sequence (C++ 13.3.3.1.1). A standard conversion sequence
253
  /// contains between zero and three conversions. If a particular
254
  /// conversion is not needed, it will be set to the identity conversion
255
  /// (ICK_Identity). Note that the three conversions are
256
  /// specified as separate members (rather than in an array) so that
257
  /// we can keep the size of a standard conversion sequence to a
258
  /// single word.
259
  class StandardConversionSequence {
260
  public:
261
    /// First -- The first conversion can be an lvalue-to-rvalue
262
    /// conversion, array-to-pointer conversion, or
263
    /// function-to-pointer conversion.
264
    ImplicitConversionKind First : 8;
265
266
    /// Second - The second conversion can be an integral promotion,
267
    /// floating point promotion, integral conversion, floating point
268
    /// conversion, floating-integral conversion, pointer conversion,
269
    /// pointer-to-member conversion, or boolean conversion.
270
    ImplicitConversionKind Second : 8;
271
272
    /// Third - The third conversion can be a qualification conversion
273
    /// or a function conversion.
274
    ImplicitConversionKind Third : 8;
275
276
    /// Whether this is the deprecated conversion of a
277
    /// string literal to a pointer to non-const character data
278
    /// (C++ 4.2p2).
279
    unsigned DeprecatedStringLiteralToCharPtr : 1;
280
281
    /// Whether the qualification conversion involves a change in the
282
    /// Objective-C lifetime (for automatic reference counting).
283
    unsigned QualificationIncludesObjCLifetime : 1;
284
285
    /// IncompatibleObjC - Whether this is an Objective-C conversion
286
    /// that we should warn about (if we actually use it).
287
    unsigned IncompatibleObjC : 1;
288
289
    /// ReferenceBinding - True when this is a reference binding
290
    /// (C++ [over.ics.ref]).
291
    unsigned ReferenceBinding : 1;
292
293
    /// DirectBinding - True when this is a reference binding that is a
294
    /// direct binding (C++ [dcl.init.ref]).
295
    unsigned DirectBinding : 1;
296
297
    /// Whether this is an lvalue reference binding (otherwise, it's
298
    /// an rvalue reference binding).
299
    unsigned IsLvalueReference : 1;
300
301
    /// Whether we're binding to a function lvalue.
302
    unsigned BindsToFunctionLvalue : 1;
303
304
    /// Whether we're binding to an rvalue.
305
    unsigned BindsToRvalue : 1;
306
307
    /// Whether this binds an implicit object argument to a
308
    /// non-static member function without a ref-qualifier.
309
    unsigned BindsImplicitObjectArgumentWithoutRefQualifier : 1;
310
311
    /// Whether this binds a reference to an object with a different
312
    /// Objective-C lifetime qualifier.
313
    unsigned ObjCLifetimeConversionBinding : 1;
314
315
    /// FromType - The type that this conversion is converting
316
    /// from. This is an opaque pointer that can be translated into a
317
    /// QualType.
318
    void *FromTypePtr;
319
320
    /// ToType - The types that this conversion is converting to in
321
    /// each step. This is an opaque pointer that can be translated
322
    /// into a QualType.
323
    void *ToTypePtrs[3];
324
325
    /// CopyConstructor - The copy constructor that is used to perform
326
    /// this conversion, when the conversion is actually just the
327
    /// initialization of an object via copy constructor. Such
328
    /// conversions are either identity conversions or derived-to-base
329
    /// conversions.
330
    CXXConstructorDecl *CopyConstructor;
331
    DeclAccessPair FoundCopyConstructor;
332
333
29.2M
    void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
334
335
78.4M
    void setToType(unsigned Idx, QualType T) {
336
78.4M
      assert(Idx < 3 && "To type index is out of range");
337
0
      ToTypePtrs[Idx] = T.getAsOpaquePtr();
338
78.4M
    }
339
340
1.90M
    void setAllToTypes(QualType T) {
341
1.90M
      ToTypePtrs[0] = T.getAsOpaquePtr();
342
1.90M
      ToTypePtrs[1] = ToTypePtrs[0];
343
1.90M
      ToTypePtrs[2] = ToTypePtrs[0];
344
1.90M
    }
345
346
9.13M
    QualType getFromType() const {
347
9.13M
      return QualType::getFromOpaquePtr(FromTypePtr);
348
9.13M
    }
349
350
26.1M
    QualType getToType(unsigned Idx) const {
351
26.1M
      assert(Idx < 3 && "To type index is out of range");
352
0
      return QualType::getFromOpaquePtr(ToTypePtrs[Idx]);
353
26.1M
    }
354
355
    void setAsIdentityConversion();
356
357
43.5M
    bool isIdentityConversion() const {
358
43.5M
      return Second == ICK_Identity && 
Third == ICK_Identity15.5M
;
359
43.5M
    }
360
361
    ImplicitConversionRank getRank() const;
362
    NarrowingKind
363
    getNarrowingKind(ASTContext &Context, const Expr *Converted,
364
                     APValue &ConstantValue, QualType &ConstantType,
365
                     bool IgnoreFloatToIntegralConversion = false) const;
366
    bool isPointerConversionToBool() const;
367
    bool isPointerConversionToVoidPointer(ASTContext& Context) const;
368
    void dump() const;
369
  };
370
371
  /// UserDefinedConversionSequence - Represents a user-defined
372
  /// conversion sequence (C++ 13.3.3.1.2).
373
  struct UserDefinedConversionSequence {
374
    /// Represents the standard conversion that occurs before
375
    /// the actual user-defined conversion.
376
    ///
377
    /// C++11 13.3.3.1.2p1:
378
    ///   If the user-defined conversion is specified by a constructor
379
    ///   (12.3.1), the initial standard conversion sequence converts
380
    ///   the source type to the type required by the argument of the
381
    ///   constructor. If the user-defined conversion is specified by
382
    ///   a conversion function (12.3.2), the initial standard
383
    ///   conversion sequence converts the source type to the implicit
384
    ///   object parameter of the conversion function.
385
    StandardConversionSequence Before;
386
387
    /// EllipsisConversion - When this is true, it means user-defined
388
    /// conversion sequence starts with a ... (ellipsis) conversion, instead of
389
    /// a standard conversion. In this case, 'Before' field must be ignored.
390
    // FIXME. I much rather put this as the first field. But there seems to be
391
    // a gcc code gen. bug which causes a crash in a test. Putting it here seems
392
    // to work around the crash.
393
    bool EllipsisConversion : 1;
394
395
    /// HadMultipleCandidates - When this is true, it means that the
396
    /// conversion function was resolved from an overloaded set having
397
    /// size greater than 1.
398
    bool HadMultipleCandidates : 1;
399
400
    /// After - Represents the standard conversion that occurs after
401
    /// the actual user-defined conversion.
402
    StandardConversionSequence After;
403
404
    /// ConversionFunction - The function that will perform the
405
    /// user-defined conversion. Null if the conversion is an
406
    /// aggregate initialization from an initializer list.
407
    FunctionDecl* ConversionFunction;
408
409
    /// The declaration that we found via name lookup, which might be
410
    /// the same as \c ConversionFunction or it might be a using declaration
411
    /// that refers to \c ConversionFunction.
412
    DeclAccessPair FoundConversionFunction;
413
414
    void dump() const;
415
  };
416
417
  /// Represents an ambiguous user-defined conversion sequence.
418
  struct AmbiguousConversionSequence {
419
    using ConversionSet =
420
        SmallVector<std::pair<NamedDecl *, FunctionDecl *>, 4>;
421
422
    void *FromTypePtr;
423
    void *ToTypePtr;
424
    char Buffer[sizeof(ConversionSet)];
425
426
13
    QualType getFromType() const {
427
13
      return QualType::getFromOpaquePtr(FromTypePtr);
428
13
    }
429
430
13
    QualType getToType() const {
431
13
      return QualType::getFromOpaquePtr(ToTypePtr);
432
13
    }
433
434
7.97k
    void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
435
7.97k
    void setToType(QualType T) { ToTypePtr = T.getAsOpaquePtr(); }
436
437
47.9k
    ConversionSet &conversions() {
438
47.9k
      return *reinterpret_cast<ConversionSet*>(Buffer);
439
47.9k
    }
440
441
8.03k
    const ConversionSet &conversions() const {
442
8.03k
      return *reinterpret_cast<const ConversionSet*>(Buffer);
443
8.03k
    }
444
445
15.9k
    void addConversion(NamedDecl *Found, FunctionDecl *D) {
446
15.9k
      conversions().push_back(std::make_pair(Found, D));
447
15.9k
    }
448
449
    using iterator = ConversionSet::iterator;
450
451
0
    iterator begin() { return conversions().begin(); }
452
0
    iterator end() { return conversions().end(); }
453
454
    using const_iterator = ConversionSet::const_iterator;
455
456
13
    const_iterator begin() const { return conversions().begin(); }
457
13
    const_iterator end() const { return conversions().end(); }
458
459
    void construct();
460
    void destruct();
461
    void copyFrom(const AmbiguousConversionSequence &);
462
  };
463
464
  /// BadConversionSequence - Records information about an invalid
465
  /// conversion sequence.
466
  struct BadConversionSequence {
467
    enum FailureKind {
468
      no_conversion,
469
      unrelated_class,
470
      bad_qualifiers,
471
      lvalue_ref_to_rvalue,
472
      rvalue_ref_to_lvalue,
473
      too_few_initializers,
474
      too_many_initializers,
475
    };
476
477
    // This can be null, e.g. for implicit object arguments.
478
    Expr *FromExpr;
479
480
    FailureKind Kind;
481
482
  private:
483
    // The type we're converting from (an opaque QualType).
484
    void *FromTy;
485
486
    // The type we're converting to (an opaque QualType).
487
    void *ToTy;
488
489
  public:
490
8.11M
    void init(FailureKind K, Expr *From, QualType To) {
491
8.11M
      init(K, From->getType(), To);
492
8.11M
      FromExpr = From;
493
8.11M
    }
494
495
8.14M
    void init(FailureKind K, QualType From, QualType To) {
496
8.14M
      Kind = K;
497
8.14M
      FromExpr = nullptr;
498
8.14M
      setFromType(From);
499
8.14M
      setToType(To);
500
8.14M
    }
501
502
22.9k
    QualType getFromType() const { return QualType::getFromOpaquePtr(FromTy); }
503
22.9k
    QualType getToType() const { return QualType::getFromOpaquePtr(ToTy); }
504
505
0
    void setFromExpr(Expr *E) {
506
0
      FromExpr = E;
507
0
      setFromType(E->getType());
508
0
    }
509
510
8.14M
    void setFromType(QualType T) { FromTy = T.getAsOpaquePtr(); }
511
8.14M
    void setToType(QualType T) { ToTy = T.getAsOpaquePtr(); }
512
  };
513
514
  /// ImplicitConversionSequence - Represents an implicit conversion
515
  /// sequence, which may be a standard conversion sequence
516
  /// (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2),
517
  /// or an ellipsis conversion sequence (C++ 13.3.3.1.3).
518
  class ImplicitConversionSequence {
519
  public:
520
    /// Kind - The kind of implicit conversion sequence. BadConversion
521
    /// specifies that there is no conversion from the source type to
522
    /// the target type.  AmbiguousConversion represents the unique
523
    /// ambiguous conversion (C++0x [over.best.ics]p10).
524
    enum Kind {
525
      StandardConversion = 0,
526
      UserDefinedConversion,
527
      AmbiguousConversion,
528
      EllipsisConversion,
529
      BadConversion
530
    };
531
532
  private:
533
    enum {
534
      Uninitialized = BadConversion + 1
535
    };
536
537
    /// ConversionKind - The kind of implicit conversion sequence.
538
    unsigned ConversionKind : 31;
539
540
    // Whether the initializer list was of an incomplete array.
541
    unsigned InitializerListOfIncompleteArray : 1;
542
543
    /// When initializing an array or std::initializer_list from an
544
    /// initializer-list, this is the array or std::initializer_list type being
545
    /// initialized. The remainder of the conversion sequence, including ToType,
546
    /// describe the worst conversion of an initializer to an element of the
547
    /// array or std::initializer_list. (Note, 'worst' is not well defined.)
548
    QualType InitializerListContainerType;
549
550
35.0M
    void setKind(Kind K) {
551
35.0M
      destruct();
552
35.0M
      ConversionKind = K;
553
35.0M
    }
554
555
149M
    void destruct() {
556
149M
      if (ConversionKind == AmbiguousConversion) 
Ambiguous.destruct()15.9k
;
557
149M
    }
558
559
  public:
560
    union {
561
      /// When ConversionKind == StandardConversion, provides the
562
      /// details of the standard conversion sequence.
563
      StandardConversionSequence Standard;
564
565
      /// When ConversionKind == UserDefinedConversion, provides the
566
      /// details of the user-defined conversion sequence.
567
      UserDefinedConversionSequence UserDefined;
568
569
      /// When ConversionKind == AmbiguousConversion, provides the
570
      /// details of the ambiguous conversion.
571
      AmbiguousConversionSequence Ambiguous;
572
573
      /// When ConversionKind == BadConversion, provides the details
574
      /// of the bad conversion.
575
      BadConversionSequence Bad;
576
    };
577
578
    ImplicitConversionSequence()
579
        : ConversionKind(Uninitialized),
580
63.6M
          InitializerListOfIncompleteArray(false) {
581
63.6M
      Standard.setAsIdentityConversion();
582
63.6M
    }
583
584
    ImplicitConversionSequence(const ImplicitConversionSequence &Other)
585
        : ConversionKind(Other.ConversionKind),
586
          InitializerListOfIncompleteArray(
587
              Other.InitializerListOfIncompleteArray),
588
50.5M
          InitializerListContainerType(Other.InitializerListContainerType) {
589
50.5M
      switch (ConversionKind) {
590
0
      case Uninitialized: break;
591
42.2M
      case StandardConversion: Standard = Other.Standard; break;
592
497k
      case UserDefinedConversion: UserDefined = Other.UserDefined; break;
593
8.00k
      case AmbiguousConversion: Ambiguous.copyFrom(Other.Ambiguous); break;
594
0
      case EllipsisConversion: break;
595
7.72M
      case BadConversion: Bad = Other.Bad; break;
596
50.5M
      }
597
50.5M
    }
598
599
    ImplicitConversionSequence &
600
20.8M
    operator=(const ImplicitConversionSequence &Other) {
601
20.8M
      destruct();
602
20.8M
      new (this) ImplicitConversionSequence(Other);
603
20.8M
      return *this;
604
20.8M
    }
605
606
93.3M
    ~ImplicitConversionSequence() {
607
93.3M
      destruct();
608
93.3M
    }
609
610
341M
    Kind getKind() const {
611
341M
      assert(isInitialized() && "querying uninitialized conversion");
612
0
      return Kind(ConversionKind);
613
341M
    }
614
615
    /// Return a ranking of the implicit conversion sequence
616
    /// kind, where smaller ranks represent better conversion
617
    /// sequences.
618
    ///
619
    /// In particular, this routine gives user-defined conversion
620
    /// sequences and ambiguous conversion sequences the same rank,
621
    /// per C++ [over.best.ics]p10.
622
69.8M
    unsigned getKindRank() const {
623
69.8M
      switch (getKind()) {
624
66.7M
      case StandardConversion:
625
66.7M
        return 0;
626
627
2.95M
      case UserDefinedConversion:
628
2.97M
      case AmbiguousConversion:
629
2.97M
        return 1;
630
631
122k
      case EllipsisConversion:
632
122k
        return 2;
633
634
27.7k
      case BadConversion:
635
27.7k
        return 3;
636
69.8M
      }
637
638
0
      llvm_unreachable("Invalid ImplicitConversionSequence::Kind!");
639
0
    }
640
641
44.4M
    bool isBad() const { return getKind() == BadConversion; }
642
99.8M
    bool isStandard() const { return getKind() == StandardConversion; }
643
29.5k
    bool isEllipsis() const { return getKind() == EllipsisConversion; }
644
1.32k
    bool isAmbiguous() const { return getKind() == AmbiguousConversion; }
645
76.9M
    bool isUserDefined() const { return getKind() == UserDefinedConversion; }
646
1.70k
    bool isFailure() const { return isBad() || 
isAmbiguous()1.22k
; }
647
648
    /// Determines whether this conversion sequence has been
649
    /// initialized.  Most operations should never need to query
650
    /// uninitialized conversions and should assert as above.
651
345M
    bool isInitialized() const { return ConversionKind != Uninitialized; }
652
653
    /// Sets this sequence as a bad conversion for an explicit argument.
654
    void setBad(BadConversionSequence::FailureKind Failure,
655
8.11M
                Expr *FromExpr, QualType ToType) {
656
8.11M
      setKind(BadConversion);
657
8.11M
      Bad.init(Failure, FromExpr, ToType);
658
8.11M
    }
659
660
    /// Sets this sequence as a bad conversion for an implicit argument.
661
    void setBad(BadConversionSequence::FailureKind Failure,
662
23.7k
                QualType FromType, QualType ToType) {
663
23.7k
      setKind(BadConversion);
664
23.7k
      Bad.init(Failure, FromType, ToType);
665
23.7k
    }
666
667
26.2M
    void setStandard() { setKind(StandardConversion); }
668
140k
    void setEllipsis() { setKind(EllipsisConversion); }
669
473k
    void setUserDefined() { setKind(UserDefinedConversion); }
670
671
7.98k
    void setAmbiguous() {
672
7.98k
      if (ConversionKind == AmbiguousConversion) 
return0
;
673
7.98k
      ConversionKind = AmbiguousConversion;
674
7.98k
      Ambiguous.construct();
675
7.98k
    }
676
677
26
    void setAsIdentityConversion(QualType T) {
678
26
      setStandard();
679
26
      Standard.setAsIdentityConversion();
680
26
      Standard.setFromType(T);
681
26
      Standard.setAllToTypes(T);
682
26
    }
683
684
    // True iff this is a conversion sequence from an initializer list to an
685
    // array or std::initializer.
686
51.9M
    bool hasInitializerListContainerType() const {
687
51.9M
      return !InitializerListContainerType.isNull();
688
51.9M
    }
689
1.19k
    void setInitializerListContainerType(QualType T, bool IA) {
690
1.19k
      InitializerListContainerType = T;
691
1.19k
      InitializerListOfIncompleteArray = IA;
692
1.19k
    }
693
50
    bool isInitializerListOfIncompleteArray() const {
694
50
      return InitializerListOfIncompleteArray;
695
50
    }
696
769
    QualType getInitializerListContainerType() const {
697
769
      assert(hasInitializerListContainerType() &&
698
769
             "not initializer list container");
699
0
      return InitializerListContainerType;
700
769
    }
701
702
    /// Form an "implicit" conversion sequence from nullptr_t to bool, for a
703
    /// direct-initialization of a bool object from nullptr_t.
704
    static ImplicitConversionSequence getNullptrToBool(QualType SourceType,
705
                                                       QualType DestType,
706
29
                                                       bool NeedLValToRVal) {
707
29
      ImplicitConversionSequence ICS;
708
29
      ICS.setStandard();
709
29
      ICS.Standard.setAsIdentityConversion();
710
29
      ICS.Standard.setFromType(SourceType);
711
29
      if (NeedLValToRVal)
712
1
        ICS.Standard.First = ICK_Lvalue_To_Rvalue;
713
29
      ICS.Standard.setToType(0, SourceType);
714
29
      ICS.Standard.Second = ICK_Boolean_Conversion;
715
29
      ICS.Standard.setToType(1, DestType);
716
29
      ICS.Standard.setToType(2, DestType);
717
29
      return ICS;
718
29
    }
719
720
    // The result of a comparison between implicit conversion
721
    // sequences. Use Sema::CompareImplicitConversionSequences to
722
    // actually perform the comparison.
723
    enum CompareKind {
724
      Better = -1,
725
      Indistinguishable = 0,
726
      Worse = 1
727
    };
728
729
    void DiagnoseAmbiguousConversion(Sema &S,
730
                                     SourceLocation CaretLoc,
731
                                     const PartialDiagnostic &PDiag) const;
732
733
    void dump() const;
734
  };
735
736
  enum OverloadFailureKind {
737
    ovl_fail_too_many_arguments,
738
    ovl_fail_too_few_arguments,
739
    ovl_fail_bad_conversion,
740
    ovl_fail_bad_deduction,
741
742
    /// This conversion candidate was not considered because it
743
    /// duplicates the work of a trivial or derived-to-base
744
    /// conversion.
745
    ovl_fail_trivial_conversion,
746
747
    /// This conversion candidate was not considered because it is
748
    /// an illegal instantiation of a constructor temploid: it is
749
    /// callable with one argument, we only have one argument, and
750
    /// its first parameter type is exactly the type of the class.
751
    ///
752
    /// Defining such a constructor directly is illegal, and
753
    /// template-argument deduction is supposed to ignore such
754
    /// instantiations, but we can still get one with the right
755
    /// kind of implicit instantiation.
756
    ovl_fail_illegal_constructor,
757
758
    /// This conversion candidate is not viable because its result
759
    /// type is not implicitly convertible to the desired type.
760
    ovl_fail_bad_final_conversion,
761
762
    /// This conversion function template specialization candidate is not
763
    /// viable because the final conversion was not an exact match.
764
    ovl_fail_final_conversion_not_exact,
765
766
    /// (CUDA) This candidate was not viable because the callee
767
    /// was not accessible from the caller's target (i.e. host->device,
768
    /// global->host, device->host).
769
    ovl_fail_bad_target,
770
771
    /// This candidate function was not viable because an enable_if
772
    /// attribute disabled it.
773
    ovl_fail_enable_if,
774
775
    /// This candidate constructor or conversion function is explicit but
776
    /// the context doesn't permit explicit functions.
777
    ovl_fail_explicit,
778
779
    /// This candidate was not viable because its address could not be taken.
780
    ovl_fail_addr_not_available,
781
782
    /// This inherited constructor is not viable because it would slice the
783
    /// argument.
784
    ovl_fail_inhctor_slice,
785
786
    /// This candidate was not viable because it is a non-default multiversioned
787
    /// function.
788
    ovl_non_default_multiversion_function,
789
790
    /// This constructor/conversion candidate fail due to an address space
791
    /// mismatch between the object being constructed and the overload
792
    /// candidate.
793
    ovl_fail_object_addrspace_mismatch,
794
795
    /// This candidate was not viable because its associated constraints were
796
    /// not satisfied.
797
    ovl_fail_constraints_not_satisfied,
798
  };
799
800
  /// A list of implicit conversion sequences for the arguments of an
801
  /// OverloadCandidate.
802
  using ConversionSequenceList =
803
      llvm::MutableArrayRef<ImplicitConversionSequence>;
804
805
  /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
806
  struct OverloadCandidate {
807
    /// Function - The actual function that this candidate
808
    /// represents. When NULL, this is a built-in candidate
809
    /// (C++ [over.oper]) or a surrogate for a conversion to a
810
    /// function pointer or reference (C++ [over.call.object]).
811
    FunctionDecl *Function;
812
813
    /// FoundDecl - The original declaration that was looked up /
814
    /// invented / otherwise found, together with its access.
815
    /// Might be a UsingShadowDecl or a FunctionTemplateDecl.
816
    DeclAccessPair FoundDecl;
817
818
    /// BuiltinParamTypes - Provides the parameter types of a built-in overload
819
    /// candidate. Only valid when Function is NULL.
820
    QualType BuiltinParamTypes[3];
821
822
    /// Surrogate - The conversion function for which this candidate
823
    /// is a surrogate, but only if IsSurrogate is true.
824
    CXXConversionDecl *Surrogate;
825
826
    /// The conversion sequences used to convert the function arguments
827
    /// to the function parameters. Note that these are indexed by argument,
828
    /// so may not match the parameter order of Function.
829
    ConversionSequenceList Conversions;
830
831
    /// The FixIt hints which can be used to fix the Bad candidate.
832
    ConversionFixItGenerator Fix;
833
834
    /// Viable - True to indicate that this overload candidate is viable.
835
    bool Viable : 1;
836
837
    /// Whether this candidate is the best viable function, or tied for being
838
    /// the best viable function.
839
    ///
840
    /// For an ambiguous overload resolution, indicates whether this candidate
841
    /// was part of the ambiguity kernel: the minimal non-empty set of viable
842
    /// candidates such that all elements of the ambiguity kernel are better
843
    /// than all viable candidates not in the ambiguity kernel.
844
    bool Best : 1;
845
846
    /// IsSurrogate - True to indicate that this candidate is a
847
    /// surrogate for a conversion to a function pointer or reference
848
    /// (C++ [over.call.object]).
849
    bool IsSurrogate : 1;
850
851
    /// IgnoreObjectArgument - True to indicate that the first
852
    /// argument's conversion, which for this function represents the
853
    /// implicit object argument, should be ignored. This will be true
854
    /// when the candidate is a static member function (where the
855
    /// implicit object argument is just a placeholder) or a
856
    /// non-static member function when the call doesn't have an
857
    /// object argument.
858
    bool IgnoreObjectArgument : 1;
859
860
    /// True if the candidate was found using ADL.
861
    CallExpr::ADLCallKind IsADLCandidate : 1;
862
863
    /// Whether this is a rewritten candidate, and if so, of what kind?
864
    unsigned RewriteKind : 2;
865
866
    /// FailureKind - The reason why this candidate is not viable.
867
    /// Actually an OverloadFailureKind.
868
    unsigned char FailureKind;
869
870
    /// The number of call arguments that were explicitly provided,
871
    /// to be used while performing partial ordering of function templates.
872
    unsigned ExplicitCallArguments;
873
874
    union {
875
      DeductionFailureInfo DeductionFailure;
876
877
      /// FinalConversion - For a conversion function (where Function is
878
      /// a CXXConversionDecl), the standard conversion that occurs
879
      /// after the call to the overload candidate to convert the result
880
      /// of calling the conversion function to the required type.
881
      StandardConversionSequence FinalConversion;
882
    };
883
884
    /// Get RewriteKind value in OverloadCandidateRewriteKind type (This
885
    /// function is to workaround the spurious GCC bitfield enum warning)
886
870k
    OverloadCandidateRewriteKind getRewriteKind() const {
887
870k
      return static_cast<OverloadCandidateRewriteKind>(RewriteKind);
888
870k
    }
889
890
857k
    bool isReversed() const { return getRewriteKind() & CRK_Reversed; }
891
892
    /// hasAmbiguousConversion - Returns whether this overload
893
    /// candidate requires an ambiguous conversion or not.
894
0
    bool hasAmbiguousConversion() const {
895
0
      for (auto &C : Conversions) {
896
0
        if (!C.isInitialized()) return false;
897
0
        if (C.isAmbiguous()) return true;
898
0
      }
899
0
      return false;
900
0
    }
901
902
11.4k
    bool TryToFixBadConversion(unsigned Idx, Sema &S) {
903
11.4k
      bool CanFix = Fix.tryToFixConversion(
904
11.4k
                      Conversions[Idx].Bad.FromExpr,
905
11.4k
                      Conversions[Idx].Bad.getFromType(),
906
11.4k
                      Conversions[Idx].Bad.getToType(), S);
907
908
      // If at least one conversion fails, the candidate cannot be fixed.
909
11.4k
      if (!CanFix)
910
11.4k
        Fix.clear();
911
912
11.4k
      return CanFix;
913
11.4k
    }
914
915
4.34k
    unsigned getNumParams() const {
916
4.34k
      if (IsSurrogate) {
917
10
        QualType STy = Surrogate->getConversionType();
918
20
        while (STy->isPointerType() || 
STy->isReferenceType()10
)
919
10
          STy = STy->getPointeeType();
920
10
        return STy->castAs<FunctionProtoType>()->getNumParams();
921
10
      }
922
4.33k
      if (Function)
923
4.33k
        return Function->getNumParams();
924
0
      return ExplicitCallArguments;
925
4.33k
    }
926
927
  private:
928
    friend class OverloadCandidateSet;
929
    OverloadCandidate()
930
17.0M
        : IsSurrogate(false), IsADLCandidate(CallExpr::NotADL), RewriteKind(CRK_None) {}
931
  };
932
933
  /// OverloadCandidateSet - A set of overload candidates, used in C++
934
  /// overload resolution (C++ 13.3).
935
  class OverloadCandidateSet {
936
  public:
937
    enum CandidateSetKind {
938
      /// Normal lookup.
939
      CSK_Normal,
940
941
      /// C++ [over.match.oper]:
942
      /// Lookup of operator function candidates in a call using operator
943
      /// syntax. Candidates that have no parameters of class type will be
944
      /// skipped unless there is a parameter of (reference to) enum type and
945
      /// the corresponding argument is of the same enum type.
946
      CSK_Operator,
947
948
      /// C++ [over.match.copy]:
949
      /// Copy-initialization of an object of class type by user-defined
950
      /// conversion.
951
      CSK_InitByUserDefinedConversion,
952
953
      /// C++ [over.match.ctor], [over.match.list]
954
      /// Initialization of an object of class type by constructor,
955
      /// using either a parenthesized or braced list of arguments.
956
      CSK_InitByConstructor,
957
    };
958
959
    /// Information about operator rewrites to consider when adding operator
960
    /// functions to a candidate set.
961
    struct OperatorRewriteInfo {
962
      OperatorRewriteInfo()
963
18.7M
          : OriginalOperator(OO_None), AllowRewrittenCandidates(false) {}
964
      OperatorRewriteInfo(OverloadedOperatorKind Op, bool AllowRewritten)
965
139k
          : OriginalOperator(Op), AllowRewrittenCandidates(AllowRewritten) {}
966
967
      /// The original operator as written in the source.
968
      OverloadedOperatorKind OriginalOperator;
969
      /// Whether we should include rewritten candidates in the overload set.
970
      bool AllowRewrittenCandidates;
971
972
      /// Would use of this function result in a rewrite using a different
973
      /// operator?
974
5.83M
      bool isRewrittenOperator(const FunctionDecl *FD) {
975
5.83M
        return OriginalOperator &&
976
5.83M
               
FD->getDeclName().getCXXOverloadedOperator() != OriginalOperator827k
;
977
5.83M
      }
978
979
583k
      bool isAcceptableCandidate(const FunctionDecl *FD) {
980
583k
        if (!OriginalOperator)
981
13.5k
          return true;
982
983
        // For an overloaded operator, we can have candidates with a different
984
        // name in our unqualified lookup set. Make sure we only consider the
985
        // ones we're supposed to.
986
569k
        OverloadedOperatorKind OO =
987
569k
            FD->getDeclName().getCXXOverloadedOperator();
988
569k
        return OO && (OO == OriginalOperator ||
989
569k
                      
(3.20k
AllowRewrittenCandidates3.20k
&&
990
3.20k
                       
OO == getRewrittenOverloadedOperator(OriginalOperator)3.05k
));
991
583k
      }
992
993
      /// Determine the kind of rewrite that should be performed for this
994
      /// candidate.
995
      OverloadCandidateRewriteKind
996
5.83M
      getRewriteKind(const FunctionDecl *FD, OverloadCandidateParamOrder PO) {
997
5.83M
        OverloadCandidateRewriteKind CRK = CRK_None;
998
5.83M
        if (isRewrittenOperator(FD))
999
8.05k
          CRK = OverloadCandidateRewriteKind(CRK | CRK_DifferentOperator);
1000
5.83M
        if (PO == OverloadCandidateParamOrder::Reversed)
1001
10.0k
          CRK = OverloadCandidateRewriteKind(CRK | CRK_Reversed);
1002
5.83M
        return CRK;
1003
5.83M
      }
1004
1005
      /// Determines whether this operator could be implemented by a function
1006
      /// with reversed parameter order.
1007
3.30k
      bool isReversible() {
1008
3.30k
        return AllowRewrittenCandidates && OriginalOperator &&
1009
3.30k
               (getRewrittenOverloadedOperator(OriginalOperator) != OO_None ||
1010
3.30k
                
shouldAddReversed(OriginalOperator)2.23k
);
1011
3.30k
      }
1012
1013
      /// Determine whether we should consider looking for and adding reversed
1014
      /// candidates for operator Op.
1015
      bool shouldAddReversed(OverloadedOperatorKind Op);
1016
1017
      /// Determine whether we should add a rewritten candidate for \p FD with
1018
      /// reversed parameter order.
1019
      bool shouldAddReversed(ASTContext &Ctx, const FunctionDecl *FD);
1020
    };
1021
1022
  private:
1023
    SmallVector<OverloadCandidate, 16> Candidates;
1024
    llvm::SmallPtrSet<uintptr_t, 16> Functions;
1025
1026
    // Allocator for ConversionSequenceLists. We store the first few of these
1027
    // inline to avoid allocation for small sets.
1028
    llvm::BumpPtrAllocator SlabAllocator;
1029
1030
    SourceLocation Loc;
1031
    CandidateSetKind Kind;
1032
    OperatorRewriteInfo RewriteInfo;
1033
1034
    constexpr static unsigned NumInlineBytes =
1035
        24 * sizeof(ImplicitConversionSequence);
1036
    unsigned NumInlineBytesUsed = 0;
1037
    alignas(void *) char InlineSpace[NumInlineBytes];
1038
1039
    // Address space of the object being constructed.
1040
    LangAS DestAS = LangAS::Default;
1041
1042
    /// If we have space, allocates from inline storage. Otherwise, allocates
1043
    /// from the slab allocator.
1044
    /// FIXME: It would probably be nice to have a SmallBumpPtrAllocator
1045
    /// instead.
1046
    /// FIXME: Now that this only allocates ImplicitConversionSequences, do we
1047
    /// want to un-generalize this?
1048
    template <typename T>
1049
17.0M
    T *slabAllocate(unsigned N) {
1050
      // It's simpler if this doesn't need to consider alignment.
1051
17.0M
      static_assert(alignof(T) == alignof(void *),
1052
17.0M
                    "Only works for pointer-aligned types.");
1053
17.0M
      static_assert(std::is_trivial<T>::value ||
1054
17.0M
                        std::is_same<ImplicitConversionSequence, T>::value,
1055
17.0M
                    "Add destruction logic to OverloadCandidateSet::clear().");
1056
1057
17.0M
      unsigned NBytes = sizeof(T) * N;
1058
17.0M
      if (NBytes > NumInlineBytes - NumInlineBytesUsed)
1059
10.3M
        return SlabAllocator.Allocate<T>(N);
1060
6.79M
      char *FreeSpaceStart = InlineSpace + NumInlineBytesUsed;
1061
6.79M
      assert(uintptr_t(FreeSpaceStart) % alignof(void *) == 0 &&
1062
6.79M
             "Misaligned storage!");
1063
1064
0
      NumInlineBytesUsed += NBytes;
1065
6.79M
      return reinterpret_cast<T *>(FreeSpaceStart);
1066
17.0M
    }
1067
1068
    void destroyCandidates();
1069
1070
  public:
1071
    OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK,
1072
                         OperatorRewriteInfo RewriteInfo = {})
1073
18.9M
        : Loc(Loc), Kind(CSK), RewriteInfo(RewriteInfo) {}
1074
    OverloadCandidateSet(const OverloadCandidateSet &) = delete;
1075
    OverloadCandidateSet &operator=(const OverloadCandidateSet &) = delete;
1076
18.9M
    ~OverloadCandidateSet() { destroyCandidates(); }
1077
1078
6.15M
    SourceLocation getLocation() const { return Loc; }
1079
4.10M
    CandidateSetKind getKind() const { return Kind; }
1080
7.98M
    OperatorRewriteInfo getRewriteInfo() const { return RewriteInfo; }
1081
1082
    /// Whether diagnostics should be deferred.
1083
    bool shouldDeferDiags(Sema &S, ArrayRef<Expr *> Args, SourceLocation OpLoc);
1084
1085
    /// Determine when this overload candidate will be new to the
1086
    /// overload set.
1087
    bool isNewCandidate(Decl *F, OverloadCandidateParamOrder PO =
1088
7.64M
                                     OverloadCandidateParamOrder::Normal) {
1089
7.64M
      uintptr_t Key = reinterpret_cast<uintptr_t>(F->getCanonicalDecl());
1090
7.64M
      Key |= static_cast<uintptr_t>(PO);
1091
7.64M
      return Functions.insert(Key).second;
1092
7.64M
    }
1093
1094
    /// Exclude a function from being considered by overload resolution.
1095
1.07k
    void exclude(Decl *F) {
1096
1.07k
      isNewCandidate(F, OverloadCandidateParamOrder::Normal);
1097
1.07k
      isNewCandidate(F, OverloadCandidateParamOrder::Reversed);
1098
1.07k
    }
1099
1100
    /// Clear out all of the candidates.
1101
    void clear(CandidateSetKind CSK);
1102
1103
    using iterator = SmallVectorImpl<OverloadCandidate>::iterator;
1104
1105
27.1M
    iterator begin() { return Candidates.begin(); }
1106
48.4M
    iterator end() { return Candidates.end(); }
1107
1108
4.54M
    size_t size() const { return Candidates.size(); }
1109
854k
    bool empty() const { return Candidates.empty(); }
1110
1111
    /// Allocate storage for conversion sequences for NumConversions
1112
    /// conversions.
1113
    ConversionSequenceList
1114
17.0M
    allocateConversionSequences(unsigned NumConversions) {
1115
17.0M
      ImplicitConversionSequence *Conversions =
1116
17.0M
          slabAllocate<ImplicitConversionSequence>(NumConversions);
1117
1118
      // Construct the new objects.
1119
44.9M
      for (unsigned I = 0; I != NumConversions; 
++I27.8M
)
1120
27.8M
        new (&Conversions[I]) ImplicitConversionSequence();
1121
1122
17.0M
      return ConversionSequenceList(Conversions, NumConversions);
1123
17.0M
    }
1124
1125
    /// Add a new candidate with NumConversions conversion sequence slots
1126
    /// to the overload set.
1127
    OverloadCandidate &addCandidate(unsigned NumConversions = 0,
1128
17.0M
                                    ConversionSequenceList Conversions = None) {
1129
17.0M
      assert((Conversions.empty() || Conversions.size() == NumConversions) &&
1130
17.0M
             "preallocated conversion sequence has wrong length");
1131
1132
0
      Candidates.push_back(OverloadCandidate());
1133
17.0M
      OverloadCandidate &C = Candidates.back();
1134
17.0M
      C.Conversions = Conversions.empty()
1135
17.0M
                          ? 
allocateConversionSequences(NumConversions)16.4M
1136
17.0M
                          : 
Conversions590k
;
1137
17.0M
      return C;
1138
17.0M
    }
1139
1140
    /// Find the best viable function on this overload set, if it exists.
1141
    OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc,
1142
                                         OverloadCandidateSet::iterator& Best);
1143
1144
    SmallVector<OverloadCandidate *, 32> CompleteCandidates(
1145
        Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef<Expr *> Args,
1146
        SourceLocation OpLoc = SourceLocation(),
1147
        llvm::function_ref<bool(OverloadCandidate &)> Filter =
1148
1.31M
            [](OverloadCandidate &) { return true; });
1149
1150
    void NoteCandidates(
1151
        PartialDiagnosticAt PA, Sema &S, OverloadCandidateDisplayKind OCD,
1152
        ArrayRef<Expr *> Args, StringRef Opc = "",
1153
        SourceLocation Loc = SourceLocation(),
1154
        llvm::function_ref<bool(OverloadCandidate &)> Filter =
1155
29.1k
            [](OverloadCandidate &) { return true; });
1156
1157
    void NoteCandidates(Sema &S, ArrayRef<Expr *> Args,
1158
                        ArrayRef<OverloadCandidate *> Cands,
1159
                        StringRef Opc = "",
1160
                        SourceLocation OpLoc = SourceLocation());
1161
1162
1.98M
    LangAS getDestAS() { return DestAS; }
1163
1164
411k
    void setDestAS(LangAS AS) {
1165
411k
      assert((Kind == CSK_InitByConstructor ||
1166
411k
              Kind == CSK_InitByUserDefinedConversion) &&
1167
411k
             "can't set the destination address space when not constructing an "
1168
411k
             "object");
1169
0
      DestAS = AS;
1170
411k
    }
1171
1172
  };
1173
1174
  bool isBetterOverloadCandidate(Sema &S,
1175
                                 const OverloadCandidate &Cand1,
1176
                                 const OverloadCandidate &Cand2,
1177
                                 SourceLocation Loc,
1178
                                 OverloadCandidateSet::CandidateSetKind Kind);
1179
1180
  struct ConstructorInfo {
1181
    DeclAccessPair FoundDecl;
1182
    CXXConstructorDecl *Constructor;
1183
    FunctionTemplateDecl *ConstructorTmpl;
1184
1185
1.24M
    explicit operator bool() const { return Constructor; }
1186
  };
1187
1188
  // FIXME: Add an AddOverloadCandidate / AddTemplateOverloadCandidate overload
1189
  // that takes one of these.
1190
3.11M
  inline ConstructorInfo getConstructorInfo(NamedDecl *ND) {
1191
3.11M
    if (isa<UsingDecl>(ND))
1192
1.72k
      return ConstructorInfo{};
1193
1194
    // For constructors, the access check is performed against the underlying
1195
    // declaration, not the found declaration.
1196
3.11M
    auto *D = ND->getUnderlyingDecl();
1197
3.11M
    ConstructorInfo Info = {DeclAccessPair::make(ND, D->getAccess()), nullptr,
1198
3.11M
                            nullptr};
1199
3.11M
    Info.ConstructorTmpl = dyn_cast<FunctionTemplateDecl>(D);
1200
3.11M
    if (Info.ConstructorTmpl)
1201
696k
      D = Info.ConstructorTmpl->getTemplatedDecl();
1202
3.11M
    Info.Constructor = dyn_cast<CXXConstructorDecl>(D);
1203
3.11M
    return Info;
1204
3.11M
  }
1205
1206
  // Returns false if signature help is relevant despite number of arguments
1207
  // exceeding parameters. Specifically, it returns false when
1208
  // PartialOverloading is true and one of the following:
1209
  // * Function is variadic
1210
  // * Function is template variadic
1211
  // * Function is an instantiation of template variadic function
1212
  // The last case may seem strange. The idea is that if we added one more
1213
  // argument, we'd end up with a function similar to Function. Since, in the
1214
  // context of signature help and/or code completion, we do not know what the
1215
  // type of the next argument (that the user is typing) will be, this is as
1216
  // good candidate as we can get, despite the fact that it takes one less
1217
  // parameter.
1218
  bool shouldEnforceArgLimit(bool PartialOverloading, FunctionDecl *Function);
1219
1220
} // namespace clang
1221
1222
#endif // LLVM_CLANG_SEMA_OVERLOAD_H