Coverage Report

Created: 2020-02-15 09:57

/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
    /// A vector splat from an arithmetic type
164
    ICK_Vector_Splat,
165
166
    /// Complex-real conversions (C99 6.3.1.7)
167
    ICK_Complex_Real,
168
169
    /// Block Pointer conversions
170
    ICK_Block_Pointer_Conversion,
171
172
    /// Transparent Union Conversions
173
    ICK_TransparentUnionConversion,
174
175
    /// Objective-C ARC writeback conversion
176
    ICK_Writeback_Conversion,
177
178
    /// Zero constant to event (OpenCL1.2 6.12.10)
179
    ICK_Zero_Event_Conversion,
180
181
    /// Zero constant to queue
182
    ICK_Zero_Queue_Conversion,
183
184
    /// Conversions allowed in C, but not C++
185
    ICK_C_Only_Conversion,
186
187
    /// C-only conversion between pointers with incompatible types
188
    ICK_Incompatible_Pointer_Conversion,
189
190
    /// The number of conversion kinds
191
    ICK_Num_Conversion_Kinds,
192
  };
193
194
  /// ImplicitConversionRank - The rank of an implicit conversion
195
  /// kind. The enumerator values match with Table 9 of (C++
196
  /// 13.3.3.1.1) and are listed such that better conversion ranks
197
  /// have smaller values.
198
  enum ImplicitConversionRank {
199
    /// Exact Match
200
    ICR_Exact_Match = 0,
201
202
    /// Promotion
203
    ICR_Promotion,
204
205
    /// Conversion
206
    ICR_Conversion,
207
208
    /// OpenCL Scalar Widening
209
    ICR_OCL_Scalar_Widening,
210
211
    /// Complex <-> Real conversion
212
    ICR_Complex_Real_Conversion,
213
214
    /// ObjC ARC writeback conversion
215
    ICR_Writeback_Conversion,
216
217
    /// Conversion only allowed in the C standard (e.g. void* to char*).
218
    ICR_C_Conversion,
219
220
    /// Conversion not allowed by the C standard, but that we accept as an
221
    /// extension anyway.
222
    ICR_C_Conversion_Extension
223
  };
224
225
  ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind);
226
227
  /// NarrowingKind - The kind of narrowing conversion being performed by a
228
  /// standard conversion sequence according to C++11 [dcl.init.list]p7.
229
  enum NarrowingKind {
230
    /// Not a narrowing conversion.
231
    NK_Not_Narrowing,
232
233
    /// A narrowing conversion by virtue of the source and destination types.
234
    NK_Type_Narrowing,
235
236
    /// A narrowing conversion, because a constant expression got narrowed.
237
    NK_Constant_Narrowing,
238
239
    /// A narrowing conversion, because a non-constant-expression variable might
240
    /// have got narrowed.
241
    NK_Variable_Narrowing,
242
243
    /// Cannot tell whether this is a narrowing conversion because the
244
    /// expression is value-dependent.
245
    NK_Dependent_Narrowing,
246
  };
247
248
  /// StandardConversionSequence - represents a standard conversion
249
  /// sequence (C++ 13.3.3.1.1). A standard conversion sequence
250
  /// contains between zero and three conversions. If a particular
251
  /// conversion is not needed, it will be set to the identity conversion
252
  /// (ICK_Identity). Note that the three conversions are
253
  /// specified as separate members (rather than in an array) so that
254
  /// we can keep the size of a standard conversion sequence to a
255
  /// single word.
256
  class StandardConversionSequence {
257
  public:
258
    /// First -- The first conversion can be an lvalue-to-rvalue
259
    /// conversion, array-to-pointer conversion, or
260
    /// function-to-pointer conversion.
261
    ImplicitConversionKind First : 8;
262
263
    /// Second - The second conversion can be an integral promotion,
264
    /// floating point promotion, integral conversion, floating point
265
    /// conversion, floating-integral conversion, pointer conversion,
266
    /// pointer-to-member conversion, or boolean conversion.
267
    ImplicitConversionKind Second : 8;
268
269
    /// Third - The third conversion can be a qualification conversion
270
    /// or a function conversion.
271
    ImplicitConversionKind Third : 8;
272
273
    /// Whether this is the deprecated conversion of a
274
    /// string literal to a pointer to non-const character data
275
    /// (C++ 4.2p2).
276
    unsigned DeprecatedStringLiteralToCharPtr : 1;
277
278
    /// Whether the qualification conversion involves a change in the
279
    /// Objective-C lifetime (for automatic reference counting).
280
    unsigned QualificationIncludesObjCLifetime : 1;
281
282
    /// IncompatibleObjC - Whether this is an Objective-C conversion
283
    /// that we should warn about (if we actually use it).
284
    unsigned IncompatibleObjC : 1;
285
286
    /// ReferenceBinding - True when this is a reference binding
287
    /// (C++ [over.ics.ref]).
288
    unsigned ReferenceBinding : 1;
289
290
    /// DirectBinding - True when this is a reference binding that is a
291
    /// direct binding (C++ [dcl.init.ref]).
292
    unsigned DirectBinding : 1;
293
294
    /// Whether this is an lvalue reference binding (otherwise, it's
295
    /// an rvalue reference binding).
296
    unsigned IsLvalueReference : 1;
297
298
    /// Whether we're binding to a function lvalue.
299
    unsigned BindsToFunctionLvalue : 1;
300
301
    /// Whether we're binding to an rvalue.
302
    unsigned BindsToRvalue : 1;
303
304
    /// Whether this binds an implicit object argument to a
305
    /// non-static member function without a ref-qualifier.
306
    unsigned BindsImplicitObjectArgumentWithoutRefQualifier : 1;
307
308
    /// Whether this binds a reference to an object with a different
309
    /// Objective-C lifetime qualifier.
310
    unsigned ObjCLifetimeConversionBinding : 1;
311
312
    /// FromType - The type that this conversion is converting
313
    /// from. This is an opaque pointer that can be translated into a
314
    /// QualType.
315
    void *FromTypePtr;
316
317
    /// ToType - The types that this conversion is converting to in
318
    /// each step. This is an opaque pointer that can be translated
319
    /// into a QualType.
320
    void *ToTypePtrs[3];
321
322
    /// CopyConstructor - The copy constructor that is used to perform
323
    /// this conversion, when the conversion is actually just the
324
    /// initialization of an object via copy constructor. Such
325
    /// conversions are either identity conversions or derived-to-base
326
    /// conversions.
327
    CXXConstructorDecl *CopyConstructor;
328
    DeclAccessPair FoundCopyConstructor;
329
330
21.2M
    void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
331
332
59.6M
    void setToType(unsigned Idx, QualType T) {
333
59.6M
      assert(Idx < 3 && "To type index is out of range");
334
59.6M
      ToTypePtrs[Idx] = T.getAsOpaquePtr();
335
59.6M
    }
336
337
1.23M
    void setAllToTypes(QualType T) {
338
1.23M
      ToTypePtrs[0] = T.getAsOpaquePtr();
339
1.23M
      ToTypePtrs[1] = ToTypePtrs[0];
340
1.23M
      ToTypePtrs[2] = ToTypePtrs[0];
341
1.23M
    }
342
343
11.1M
    QualType getFromType() const {
344
11.1M
      return QualType::getFromOpaquePtr(FromTypePtr);
345
11.1M
    }
346
347
27.9M
    QualType getToType(unsigned Idx) const {
348
27.9M
      assert(Idx < 3 && "To type index is out of range");
349
27.9M
      return QualType::getFromOpaquePtr(ToTypePtrs[Idx]);
350
27.9M
    }
351
352
    void setAsIdentityConversion();
353
354
38.1M
    bool isIdentityConversion() const {
355
38.1M
      return Second == ICK_Identity && 
Third == ICK_Identity13.5M
;
356
38.1M
    }
357
358
    ImplicitConversionRank getRank() const;
359
    NarrowingKind
360
    getNarrowingKind(ASTContext &Context, const Expr *Converted,
361
                     APValue &ConstantValue, QualType &ConstantType,
362
                     bool IgnoreFloatToIntegralConversion = false) const;
363
    bool isPointerConversionToBool() const;
364
    bool isPointerConversionToVoidPointer(ASTContext& Context) const;
365
    void dump() const;
366
  };
367
368
  /// UserDefinedConversionSequence - Represents a user-defined
369
  /// conversion sequence (C++ 13.3.3.1.2).
370
  struct UserDefinedConversionSequence {
371
    /// Represents the standard conversion that occurs before
372
    /// the actual user-defined conversion.
373
    ///
374
    /// C++11 13.3.3.1.2p1:
375
    ///   If the user-defined conversion is specified by a constructor
376
    ///   (12.3.1), the initial standard conversion sequence converts
377
    ///   the source type to the type required by the argument of the
378
    ///   constructor. If the user-defined conversion is specified by
379
    ///   a conversion function (12.3.2), the initial standard
380
    ///   conversion sequence converts the source type to the implicit
381
    ///   object parameter of the conversion function.
382
    StandardConversionSequence Before;
383
384
    /// EllipsisConversion - When this is true, it means user-defined
385
    /// conversion sequence starts with a ... (ellipsis) conversion, instead of
386
    /// a standard conversion. In this case, 'Before' field must be ignored.
387
    // FIXME. I much rather put this as the first field. But there seems to be
388
    // a gcc code gen. bug which causes a crash in a test. Putting it here seems
389
    // to work around the crash.
390
    bool EllipsisConversion : 1;
391
392
    /// HadMultipleCandidates - When this is true, it means that the
393
    /// conversion function was resolved from an overloaded set having
394
    /// size greater than 1.
395
    bool HadMultipleCandidates : 1;
396
397
    /// After - Represents the standard conversion that occurs after
398
    /// the actual user-defined conversion.
399
    StandardConversionSequence After;
400
401
    /// ConversionFunction - The function that will perform the
402
    /// user-defined conversion. Null if the conversion is an
403
    /// aggregate initialization from an initializer list.
404
    FunctionDecl* ConversionFunction;
405
406
    /// The declaration that we found via name lookup, which might be
407
    /// the same as \c ConversionFunction or it might be a using declaration
408
    /// that refers to \c ConversionFunction.
409
    DeclAccessPair FoundConversionFunction;
410
411
    void dump() const;
412
  };
413
414
  /// Represents an ambiguous user-defined conversion sequence.
415
  struct AmbiguousConversionSequence {
416
    using ConversionSet =
417
        SmallVector<std::pair<NamedDecl *, FunctionDecl *>, 4>;
418
419
    void *FromTypePtr;
420
    void *ToTypePtr;
421
    char Buffer[sizeof(ConversionSet)];
422
423
10
    QualType getFromType() const {
424
10
      return QualType::getFromOpaquePtr(FromTypePtr);
425
10
    }
426
427
10
    QualType getToType() const {
428
10
      return QualType::getFromOpaquePtr(ToTypePtr);
429
10
    }
430
431
7.97k
    void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
432
7.97k
    void setToType(QualType T) { ToTypePtr = T.getAsOpaquePtr(); }
433
434
47.9k
    ConversionSet &conversions() {
435
47.9k
      return *reinterpret_cast<ConversionSet*>(Buffer);
436
47.9k
    }
437
438
8.02k
    const ConversionSet &conversions() const {
439
8.02k
      return *reinterpret_cast<const ConversionSet*>(Buffer);
440
8.02k
    }
441
442
15.9k
    void addConversion(NamedDecl *Found, FunctionDecl *D) {
443
15.9k
      conversions().push_back(std::make_pair(Found, D));
444
15.9k
    }
445
446
    using iterator = ConversionSet::iterator;
447
448
0
    iterator begin() { return conversions().begin(); }
449
0
    iterator end() { return conversions().end(); }
450
451
    using const_iterator = ConversionSet::const_iterator;
452
453
10
    const_iterator begin() const { return conversions().begin(); }
454
10
    const_iterator end() const { return conversions().end(); }
455
456
    void construct();
457
    void destruct();
458
    void copyFrom(const AmbiguousConversionSequence &);
459
  };
460
461
  /// BadConversionSequence - Records information about an invalid
462
  /// conversion sequence.
463
  struct BadConversionSequence {
464
    enum FailureKind {
465
      no_conversion,
466
      unrelated_class,
467
      bad_qualifiers,
468
      lvalue_ref_to_rvalue,
469
      rvalue_ref_to_lvalue
470
    };
471
472
    // This can be null, e.g. for implicit object arguments.
473
    Expr *FromExpr;
474
475
    FailureKind Kind;
476
477
  private:
478
    // The type we're converting from (an opaque QualType).
479
    void *FromTy;
480
481
    // The type we're converting to (an opaque QualType).
482
    void *ToTy;
483
484
  public:
485
5.53M
    void init(FailureKind K, Expr *From, QualType To) {
486
5.53M
      init(K, From->getType(), To);
487
5.53M
      FromExpr = From;
488
5.53M
    }
489
490
5.55M
    void init(FailureKind K, QualType From, QualType To) {
491
5.55M
      Kind = K;
492
5.55M
      FromExpr = nullptr;
493
5.55M
      setFromType(From);
494
5.55M
      setToType(To);
495
5.55M
    }
496
497
14.5k
    QualType getFromType() const { return QualType::getFromOpaquePtr(FromTy); }
498
14.5k
    QualType getToType() const { return QualType::getFromOpaquePtr(ToTy); }
499
500
0
    void setFromExpr(Expr *E) {
501
0
      FromExpr = E;
502
0
      setFromType(E->getType());
503
0
    }
504
505
5.55M
    void setFromType(QualType T) { FromTy = T.getAsOpaquePtr(); }
506
5.55M
    void setToType(QualType T) { ToTy = T.getAsOpaquePtr(); }
507
  };
508
509
  /// ImplicitConversionSequence - Represents an implicit conversion
510
  /// sequence, which may be a standard conversion sequence
511
  /// (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2),
512
  /// or an ellipsis conversion sequence (C++ 13.3.3.1.3).
513
  class ImplicitConversionSequence {
514
  public:
515
    /// Kind - The kind of implicit conversion sequence. BadConversion
516
    /// specifies that there is no conversion from the source type to
517
    /// the target type.  AmbiguousConversion represents the unique
518
    /// ambiguous conversion (C++0x [over.best.ics]p10).
519
    enum Kind {
520
      StandardConversion = 0,
521
      UserDefinedConversion,
522
      AmbiguousConversion,
523
      EllipsisConversion,
524
      BadConversion
525
    };
526
527
  private:
528
    enum {
529
      Uninitialized = BadConversion + 1
530
    };
531
532
    /// ConversionKind - The kind of implicit conversion sequence.
533
    unsigned ConversionKind : 30;
534
535
    /// Whether the target is really a std::initializer_list, and the
536
    /// sequence only represents the worst element conversion.
537
    unsigned StdInitializerListElement : 1;
538
539
26.0M
    void setKind(Kind K) {
540
26.0M
      destruct();
541
26.0M
      ConversionKind = K;
542
26.0M
    }
543
544
116M
    void destruct() {
545
116M
      if (ConversionKind == AmbiguousConversion) 
Ambiguous.destruct()15.9k
;
546
116M
    }
547
548
  public:
549
    union {
550
      /// When ConversionKind == StandardConversion, provides the
551
      /// details of the standard conversion sequence.
552
      StandardConversionSequence Standard;
553
554
      /// When ConversionKind == UserDefinedConversion, provides the
555
      /// details of the user-defined conversion sequence.
556
      UserDefinedConversionSequence UserDefined;
557
558
      /// When ConversionKind == AmbiguousConversion, provides the
559
      /// details of the ambiguous conversion.
560
      AmbiguousConversionSequence Ambiguous;
561
562
      /// When ConversionKind == BadConversion, provides the details
563
      /// of the bad conversion.
564
      BadConversionSequence Bad;
565
    };
566
567
    ImplicitConversionSequence()
568
49.8M
        : ConversionKind(Uninitialized), StdInitializerListElement(false) {
569
49.8M
      Standard.setAsIdentityConversion();
570
49.8M
    }
571
572
    ImplicitConversionSequence(const ImplicitConversionSequence &Other)
573
        : ConversionKind(Other.ConversionKind),
574
40.7M
          StdInitializerListElement(Other.StdInitializerListElement) {
575
40.7M
      switch (ConversionKind) {
576
0
      case Uninitialized: break;
577
35.3M
      case StandardConversion: Standard = Other.Standard; break;
578
268k
      case UserDefinedConversion: UserDefined = Other.UserDefined; break;
579
8.00k
      case AmbiguousConversion: Ambiguous.copyFrom(Other.Ambiguous); break;
580
0
      case EllipsisConversion: break;
581
5.07M
      case BadConversion: Bad = Other.Bad; break;
582
40.7M
      }
583
40.7M
    }
584
585
    ImplicitConversionSequence &
586
18.6M
    operator=(const ImplicitConversionSequence &Other) {
587
18.6M
      destruct();
588
18.6M
      new (this) ImplicitConversionSequence(Other);
589
18.6M
      return *this;
590
18.6M
    }
591
592
71.9M
    ~ImplicitConversionSequence() {
593
71.9M
      destruct();
594
71.9M
    }
595
596
281M
    Kind getKind() const {
597
281M
      assert(isInitialized() && "querying uninitialized conversion");
598
281M
      return Kind(ConversionKind);
599
281M
    }
600
601
    /// Return a ranking of the implicit conversion sequence
602
    /// kind, where smaller ranks represent better conversion
603
    /// sequences.
604
    ///
605
    /// In particular, this routine gives user-defined conversion
606
    /// sequences and ambiguous conversion sequences the same rank,
607
    /// per C++ [over.best.ics]p10.
608
60.6M
    unsigned getKindRank() const {
609
60.6M
      switch (getKind()) {
610
58.9M
      case StandardConversion:
611
58.9M
        return 0;
612
0
613
1.56M
      case UserDefinedConversion:
614
1.56M
      case AmbiguousConversion:
615
1.56M
        return 1;
616
1.56M
617
1.56M
      case EllipsisConversion:
618
90.1k
        return 2;
619
1.56M
620
1.56M
      case BadConversion:
621
47.2k
        return 3;
622
0
      }
623
0
624
0
      llvm_unreachable("Invalid ImplicitConversionSequence::Kind!");
625
0
    }
626
627
35.6M
    bool isBad() const { return getKind() == BadConversion; }
628
83.8M
    bool isStandard() const { return getKind() == StandardConversion; }
629
21.1k
    bool isEllipsis() const { return getKind() == EllipsisConversion; }
630
1.37k
    bool isAmbiguous() const { return getKind() == AmbiguousConversion; }
631
60.2M
    bool isUserDefined() const { return getKind() == UserDefinedConversion; }
632
1.50k
    bool isFailure() const { return isBad() || 
isAmbiguous()1.28k
; }
633
634
    /// Determines whether this conversion sequence has been
635
    /// initialized.  Most operations should never need to query
636
    /// uninitialized conversions and should assert as above.
637
285M
    bool isInitialized() const { return ConversionKind != Uninitialized; }
638
639
    /// Sets this sequence as a bad conversion for an explicit argument.
640
    void setBad(BadConversionSequence::FailureKind Failure,
641
5.53M
                Expr *FromExpr, QualType ToType) {
642
5.53M
      setKind(BadConversion);
643
5.53M
      Bad.init(Failure, FromExpr, ToType);
644
5.53M
    }
645
646
    /// Sets this sequence as a bad conversion for an implicit argument.
647
    void setBad(BadConversionSequence::FailureKind Failure,
648
17.9k
                QualType FromType, QualType ToType) {
649
17.9k
      setKind(BadConversion);
650
17.9k
      Bad.init(Failure, FromType, ToType);
651
17.9k
    }
652
653
20.1M
    void setStandard() { setKind(StandardConversion); }
654
86.3k
    void setEllipsis() { setKind(EllipsisConversion); }
655
250k
    void setUserDefined() { setKind(UserDefinedConversion); }
656
657
7.97k
    void setAmbiguous() {
658
7.97k
      if (ConversionKind == AmbiguousConversion) 
return0
;
659
7.97k
      ConversionKind = AmbiguousConversion;
660
7.97k
      Ambiguous.construct();
661
7.97k
    }
662
663
56
    void setAsIdentityConversion(QualType T) {
664
56
      setStandard();
665
56
      Standard.setAsIdentityConversion();
666
56
      Standard.setFromType(T);
667
56
      Standard.setAllToTypes(T);
668
56
    }
669
670
    /// Whether the target is really a std::initializer_list, and the
671
    /// sequence only represents the worst element conversion.
672
45.1M
    bool isStdInitializerListElement() const {
673
45.1M
      return StdInitializerListElement;
674
45.1M
    }
675
676
805
    void setStdInitializerListElement(bool V = true) {
677
805
      StdInitializerListElement = V;
678
805
    }
679
680
    /// Form an "implicit" conversion sequence from nullptr_t to bool, for a
681
    /// direct-initialization of a bool object from nullptr_t.
682
    static ImplicitConversionSequence getNullptrToBool(QualType SourceType,
683
                                                       QualType DestType,
684
26
                                                       bool NeedLValToRVal) {
685
26
      ImplicitConversionSequence ICS;
686
26
      ICS.setStandard();
687
26
      ICS.Standard.setAsIdentityConversion();
688
26
      ICS.Standard.setFromType(SourceType);
689
26
      if (NeedLValToRVal)
690
1
        ICS.Standard.First = ICK_Lvalue_To_Rvalue;
691
26
      ICS.Standard.setToType(0, SourceType);
692
26
      ICS.Standard.Second = ICK_Boolean_Conversion;
693
26
      ICS.Standard.setToType(1, DestType);
694
26
      ICS.Standard.setToType(2, DestType);
695
26
      return ICS;
696
26
    }
697
698
    // The result of a comparison between implicit conversion
699
    // sequences. Use Sema::CompareImplicitConversionSequences to
700
    // actually perform the comparison.
701
    enum CompareKind {
702
      Better = -1,
703
      Indistinguishable = 0,
704
      Worse = 1
705
    };
706
707
    void DiagnoseAmbiguousConversion(Sema &S,
708
                                     SourceLocation CaretLoc,
709
                                     const PartialDiagnostic &PDiag) const;
710
711
    void dump() const;
712
  };
713
714
  enum OverloadFailureKind {
715
    ovl_fail_too_many_arguments,
716
    ovl_fail_too_few_arguments,
717
    ovl_fail_bad_conversion,
718
    ovl_fail_bad_deduction,
719
720
    /// This conversion candidate was not considered because it
721
    /// duplicates the work of a trivial or derived-to-base
722
    /// conversion.
723
    ovl_fail_trivial_conversion,
724
725
    /// This conversion candidate was not considered because it is
726
    /// an illegal instantiation of a constructor temploid: it is
727
    /// callable with one argument, we only have one argument, and
728
    /// its first parameter type is exactly the type of the class.
729
    ///
730
    /// Defining such a constructor directly is illegal, and
731
    /// template-argument deduction is supposed to ignore such
732
    /// instantiations, but we can still get one with the right
733
    /// kind of implicit instantiation.
734
    ovl_fail_illegal_constructor,
735
736
    /// This conversion candidate is not viable because its result
737
    /// type is not implicitly convertible to the desired type.
738
    ovl_fail_bad_final_conversion,
739
740
    /// This conversion function template specialization candidate is not
741
    /// viable because the final conversion was not an exact match.
742
    ovl_fail_final_conversion_not_exact,
743
744
    /// (CUDA) This candidate was not viable because the callee
745
    /// was not accessible from the caller's target (i.e. host->device,
746
    /// global->host, device->host).
747
    ovl_fail_bad_target,
748
749
    /// This candidate function was not viable because an enable_if
750
    /// attribute disabled it.
751
    ovl_fail_enable_if,
752
753
    /// This candidate constructor or conversion function is explicit but
754
    /// the context doesn't permit explicit functions.
755
    ovl_fail_explicit,
756
757
    /// This candidate was not viable because its address could not be taken.
758
    ovl_fail_addr_not_available,
759
760
    /// This candidate was not viable because its OpenCL extension is disabled.
761
    ovl_fail_ext_disabled,
762
763
    /// This inherited constructor is not viable because it would slice the
764
    /// argument.
765
    ovl_fail_inhctor_slice,
766
767
    /// This candidate was not viable because it is a non-default multiversioned
768
    /// function.
769
    ovl_non_default_multiversion_function,
770
771
    /// This constructor/conversion candidate fail due to an address space
772
    /// mismatch between the object being constructed and the overload
773
    /// candidate.
774
    ovl_fail_object_addrspace_mismatch,
775
776
    /// This candidate was not viable because its associated constraints were
777
    /// not satisfied.
778
    ovl_fail_constraints_not_satisfied,
779
  };
780
781
  /// A list of implicit conversion sequences for the arguments of an
782
  /// OverloadCandidate.
783
  using ConversionSequenceList =
784
      llvm::MutableArrayRef<ImplicitConversionSequence>;
785
786
  /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
787
  struct OverloadCandidate {
788
    /// Function - The actual function that this candidate
789
    /// represents. When NULL, this is a built-in candidate
790
    /// (C++ [over.oper]) or a surrogate for a conversion to a
791
    /// function pointer or reference (C++ [over.call.object]).
792
    FunctionDecl *Function;
793
794
    /// FoundDecl - The original declaration that was looked up /
795
    /// invented / otherwise found, together with its access.
796
    /// Might be a UsingShadowDecl or a FunctionTemplateDecl.
797
    DeclAccessPair FoundDecl;
798
799
    /// BuiltinParamTypes - Provides the parameter types of a built-in overload
800
    /// candidate. Only valid when Function is NULL.
801
    QualType BuiltinParamTypes[3];
802
803
    /// Surrogate - The conversion function for which this candidate
804
    /// is a surrogate, but only if IsSurrogate is true.
805
    CXXConversionDecl *Surrogate;
806
807
    /// The conversion sequences used to convert the function arguments
808
    /// to the function parameters. Note that these are indexed by argument,
809
    /// so may not match the parameter order of Function.
810
    ConversionSequenceList Conversions;
811
812
    /// The FixIt hints which can be used to fix the Bad candidate.
813
    ConversionFixItGenerator Fix;
814
815
    /// Viable - True to indicate that this overload candidate is viable.
816
    bool Viable : 1;
817
818
    /// Whether this candidate is the best viable function, or tied for being
819
    /// the best viable function.
820
    ///
821
    /// For an ambiguous overload resolution, indicates whether this candidate
822
    /// was part of the ambiguity kernel: the minimal non-empty set of viable
823
    /// candidates such that all elements of the ambiguity kernel are better
824
    /// than all viable candidates not in the ambiguity kernel.
825
    bool Best : 1;
826
827
    /// IsSurrogate - True to indicate that this candidate is a
828
    /// surrogate for a conversion to a function pointer or reference
829
    /// (C++ [over.call.object]).
830
    bool IsSurrogate : 1;
831
832
    /// IgnoreObjectArgument - True to indicate that the first
833
    /// argument's conversion, which for this function represents the
834
    /// implicit object argument, should be ignored. This will be true
835
    /// when the candidate is a static member function (where the
836
    /// implicit object argument is just a placeholder) or a
837
    /// non-static member function when the call doesn't have an
838
    /// object argument.
839
    bool IgnoreObjectArgument : 1;
840
841
    /// True if the candidate was found using ADL.
842
    CallExpr::ADLCallKind IsADLCandidate : 1;
843
844
    /// Whether this is a rewritten candidate, and if so, of what kind?
845
    unsigned RewriteKind : 2;
846
847
    /// FailureKind - The reason why this candidate is not viable.
848
    /// Actually an OverloadFailureKind.
849
    unsigned char FailureKind;
850
851
    /// The number of call arguments that were explicitly provided,
852
    /// to be used while performing partial ordering of function templates.
853
    unsigned ExplicitCallArguments;
854
855
    union {
856
      DeductionFailureInfo DeductionFailure;
857
858
      /// FinalConversion - For a conversion function (where Function is
859
      /// a CXXConversionDecl), the standard conversion that occurs
860
      /// after the call to the overload candidate to convert the result
861
      /// of calling the conversion function to the required type.
862
      StandardConversionSequence FinalConversion;
863
    };
864
865
    /// Get RewriteKind value in OverloadCandidateRewriteKind type (This
866
    /// function is to workaround the spurious GCC bitfield enum warning)
867
124k
    OverloadCandidateRewriteKind getRewriteKind() const {
868
124k
      return static_cast<OverloadCandidateRewriteKind>(RewriteKind);
869
124k
    }
870
871
113k
    bool isReversed() const { return getRewriteKind() & CRK_Reversed; }
872
873
    /// hasAmbiguousConversion - Returns whether this overload
874
    /// candidate requires an ambiguous conversion or not.
875
0
    bool hasAmbiguousConversion() const {
876
0
      for (auto &C : Conversions) {
877
0
        if (!C.isInitialized()) return false;
878
0
        if (C.isAmbiguous()) return true;
879
0
      }
880
0
      return false;
881
0
    }
882
883
7.26k
    bool TryToFixBadConversion(unsigned Idx, Sema &S) {
884
7.26k
      bool CanFix = Fix.tryToFixConversion(
885
7.26k
                      Conversions[Idx].Bad.FromExpr,
886
7.26k
                      Conversions[Idx].Bad.getFromType(),
887
7.26k
                      Conversions[Idx].Bad.getToType(), S);
888
7.26k
889
7.26k
      // If at least one conversion fails, the candidate cannot be fixed.
890
7.26k
      if (!CanFix)
891
7.22k
        Fix.clear();
892
7.26k
893
7.26k
      return CanFix;
894
7.26k
    }
895
896
2.95k
    unsigned getNumParams() const {
897
2.95k
      if (IsSurrogate) {
898
9
        QualType STy = Surrogate->getConversionType();
899
18
        while (STy->isPointerType() || 
STy->isReferenceType()9
)
900
9
          STy = STy->getPointeeType();
901
9
        return STy->castAs<FunctionProtoType>()->getNumParams();
902
9
      }
903
2.94k
      if (Function)
904
2.94k
        return Function->getNumParams();
905
0
      return ExplicitCallArguments;
906
0
    }
907
908
  private:
909
    friend class OverloadCandidateSet;
910
    OverloadCandidate()
911
12.6M
        : IsADLCandidate(CallExpr::NotADL), RewriteKind(CRK_None) {}
912
  };
913
914
  /// OverloadCandidateSet - A set of overload candidates, used in C++
915
  /// overload resolution (C++ 13.3).
916
  class OverloadCandidateSet {
917
  public:
918
    enum CandidateSetKind {
919
      /// Normal lookup.
920
      CSK_Normal,
921
922
      /// C++ [over.match.oper]:
923
      /// Lookup of operator function candidates in a call using operator
924
      /// syntax. Candidates that have no parameters of class type will be
925
      /// skipped unless there is a parameter of (reference to) enum type and
926
      /// the corresponding argument is of the same enum type.
927
      CSK_Operator,
928
929
      /// C++ [over.match.copy]:
930
      /// Copy-initialization of an object of class type by user-defined
931
      /// conversion.
932
      CSK_InitByUserDefinedConversion,
933
934
      /// C++ [over.match.ctor], [over.match.list]
935
      /// Initialization of an object of class type by constructor,
936
      /// using either a parenthesized or braced list of arguments.
937
      CSK_InitByConstructor,
938
    };
939
940
    /// Information about operator rewrites to consider when adding operator
941
    /// functions to a candidate set.
942
    struct OperatorRewriteInfo {
943
      OperatorRewriteInfo()
944
13.8M
          : OriginalOperator(OO_None), AllowRewrittenCandidates(false) {}
945
      OperatorRewriteInfo(OverloadedOperatorKind Op, bool AllowRewritten)
946
91.3k
          : OriginalOperator(Op), AllowRewrittenCandidates(AllowRewritten) {}
947
948
      /// The original operator as written in the source.
949
      OverloadedOperatorKind OriginalOperator;
950
      /// Whether we should include rewritten candidates in the overload set.
951
      bool AllowRewrittenCandidates;
952
953
      /// Would use of this function result in a rewrite using a different
954
      /// operator?
955
4.26M
      bool isRewrittenOperator(const FunctionDecl *FD) {
956
4.26M
        return OriginalOperator &&
957
4.26M
               
FD->getDeclName().getCXXOverloadedOperator() != OriginalOperator525k
;
958
4.26M
      }
959
960
372k
      bool isAcceptableCandidate(const FunctionDecl *FD) {
961
372k
        if (!OriginalOperator)
962
13.4k
          return true;
963
358k
964
358k
        // For an overloaded operator, we can have candidates with a different
965
358k
        // name in our unqualified lookup set. Make sure we only consider the
966
358k
        // ones we're supposed to.
967
358k
        OverloadedOperatorKind OO =
968
358k
            FD->getDeclName().getCXXOverloadedOperator();
969
358k
        return OO && (OO == OriginalOperator ||
970
358k
                      
(556
AllowRewrittenCandidates556
&&
971
556
                       
OO == getRewrittenOverloadedOperator(OriginalOperator)443
));
972
358k
      }
973
974
      /// Determine the kind of rewrite that should be performed for this
975
      /// candidate.
976
      OverloadCandidateRewriteKind
977
4.26M
      getRewriteKind(const FunctionDecl *FD, OverloadCandidateParamOrder PO) {
978
4.26M
        OverloadCandidateRewriteKind CRK = CRK_None;
979
4.26M
        if (isRewrittenOperator(FD))
980
1.27k
          CRK = OverloadCandidateRewriteKind(CRK | CRK_DifferentOperator);
981
4.26M
        if (PO == OverloadCandidateParamOrder::Reversed)
982
899
          CRK = OverloadCandidateRewriteKind(CRK | CRK_Reversed);
983
4.26M
        return CRK;
984
4.26M
      }
985
986
      /// Determine whether we should consider looking for and adding reversed
987
      /// candidates for operator Op.
988
      bool shouldAddReversed(OverloadedOperatorKind Op);
989
990
      /// Determine whether we should add a rewritten candidate for \p FD with
991
      /// reversed parameter order.
992
      bool shouldAddReversed(ASTContext &Ctx, const FunctionDecl *FD);
993
    };
994
995
  private:
996
    SmallVector<OverloadCandidate, 16> Candidates;
997
    llvm::SmallPtrSet<uintptr_t, 16> Functions;
998
999
    // Allocator for ConversionSequenceLists. We store the first few of these
1000
    // inline to avoid allocation for small sets.
1001
    llvm::BumpPtrAllocator SlabAllocator;
1002
1003
    SourceLocation Loc;
1004
    CandidateSetKind Kind;
1005
    OperatorRewriteInfo RewriteInfo;
1006
1007
    constexpr static unsigned NumInlineBytes =
1008
        24 * sizeof(ImplicitConversionSequence);
1009
    unsigned NumInlineBytesUsed = 0;
1010
    alignas(void *) char InlineSpace[NumInlineBytes];
1011
1012
    // Address space of the object being constructed.
1013
    LangAS DestAS = LangAS::Default;
1014
1015
    /// If we have space, allocates from inline storage. Otherwise, allocates
1016
    /// from the slab allocator.
1017
    /// FIXME: It would probably be nice to have a SmallBumpPtrAllocator
1018
    /// instead.
1019
    /// FIXME: Now that this only allocates ImplicitConversionSequences, do we
1020
    /// want to un-generalize this?
1021
    template <typename T>
1022
12.6M
    T *slabAllocate(unsigned N) {
1023
12.6M
      // It's simpler if this doesn't need to consider alignment.
1024
12.6M
      static_assert(alignof(T) == alignof(void *),
1025
12.6M
                    "Only works for pointer-aligned types.");
1026
12.6M
      static_assert(std::is_trivial<T>::value ||
1027
12.6M
                        std::is_same<ImplicitConversionSequence, T>::value,
1028
12.6M
                    "Add destruction logic to OverloadCandidateSet::clear().");
1029
12.6M
1030
12.6M
      unsigned NBytes = sizeof(T) * N;
1031
12.6M
      if (NBytes > NumInlineBytes - NumInlineBytesUsed)
1032
7.74M
        return SlabAllocator.Allocate<T>(N);
1033
4.93M
      char *FreeSpaceStart = InlineSpace + NumInlineBytesUsed;
1034
4.93M
      assert(uintptr_t(FreeSpaceStart) % alignof(void *) == 0 &&
1035
4.93M
             "Misaligned storage!");
1036
4.93M
1037
4.93M
      NumInlineBytesUsed += NBytes;
1038
4.93M
      return reinterpret_cast<T *>(FreeSpaceStart);
1039
4.93M
    }
1040
1041
    void destroyCandidates();
1042
1043
  public:
1044
    OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK,
1045
                         OperatorRewriteInfo RewriteInfo = {})
1046
13.8M
        : Loc(Loc), Kind(CSK), RewriteInfo(RewriteInfo) {}
1047
    OverloadCandidateSet(const OverloadCandidateSet &) = delete;
1048
    OverloadCandidateSet &operator=(const OverloadCandidateSet &) = delete;
1049
13.8M
    ~OverloadCandidateSet() { destroyCandidates(); }
1050
1051
2.23M
    SourceLocation getLocation() const { return Loc; }
1052
3.11M
    CandidateSetKind getKind() const { return Kind; }
1053
5.66M
    OperatorRewriteInfo getRewriteInfo() const { return RewriteInfo; }
1054
1055
    /// Determine when this overload candidate will be new to the
1056
    /// overload set.
1057
    bool isNewCandidate(Decl *F, OverloadCandidateParamOrder PO =
1058
5.40M
                                     OverloadCandidateParamOrder::Normal) {
1059
5.40M
      uintptr_t Key = reinterpret_cast<uintptr_t>(F->getCanonicalDecl());
1060
5.40M
      Key |= static_cast<uintptr_t>(PO);
1061
5.40M
      return Functions.insert(Key).second;
1062
5.40M
    }
1063
1064
    /// Exclude a function from being considered by overload resolution.
1065
869
    void exclude(Decl *F) {
1066
869
      isNewCandidate(F, OverloadCandidateParamOrder::Normal);
1067
869
      isNewCandidate(F, OverloadCandidateParamOrder::Reversed);
1068
869
    }
1069
1070
    /// Clear out all of the candidates.
1071
    void clear(CandidateSetKind CSK);
1072
1073
    using iterator = SmallVectorImpl<OverloadCandidate>::iterator;
1074
1075
19.3M
    iterator begin() { return Candidates.begin(); }
1076
34.7M
    iterator end() { return Candidates.end(); }
1077
1078
3.05M
    size_t size() const { return Candidates.size(); }
1079
1.12M
    bool empty() const { return Candidates.empty(); }
1080
1081
    /// Allocate storage for conversion sequences for NumConversions
1082
    /// conversions.
1083
    ConversionSequenceList
1084
12.6M
    allocateConversionSequences(unsigned NumConversions) {
1085
12.6M
      ImplicitConversionSequence *Conversions =
1086
12.6M
          slabAllocate<ImplicitConversionSequence>(NumConversions);
1087
12.6M
1088
12.6M
      // Construct the new objects.
1089
33.9M
      for (unsigned I = 0; I != NumConversions; 
++I21.2M
)
1090
21.2M
        new (&Conversions[I]) ImplicitConversionSequence();
1091
12.6M
1092
12.6M
      return ConversionSequenceList(Conversions, NumConversions);
1093
12.6M
    }
1094
1095
    /// Add a new candidate with NumConversions conversion sequence slots
1096
    /// to the overload set.
1097
    OverloadCandidate &addCandidate(unsigned NumConversions = 0,
1098
12.6M
                                    ConversionSequenceList Conversions = None) {
1099
12.6M
      assert((Conversions.empty() || Conversions.size() == NumConversions) &&
1100
12.6M
             "preallocated conversion sequence has wrong length");
1101
12.6M
1102
12.6M
      Candidates.push_back(OverloadCandidate());
1103
12.6M
      OverloadCandidate &C = Candidates.back();
1104
12.6M
      C.Conversions = Conversions.empty()
1105
12.6M
                          ? 
allocateConversionSequences(NumConversions)12.2M
1106
12.6M
                          : 
Conversions410k
;
1107
12.6M
      return C;
1108
12.6M
    }
1109
1110
    /// Find the best viable function on this overload set, if it exists.
1111
    OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc,
1112
                                         OverloadCandidateSet::iterator& Best);
1113
1114
    SmallVector<OverloadCandidate *, 32> CompleteCandidates(
1115
        Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef<Expr *> Args,
1116
        SourceLocation OpLoc = SourceLocation(),
1117
        llvm::function_ref<bool(OverloadCandidate &)> Filter =
1118
599k
            [](OverloadCandidate &) { return true; });
1119
1120
    void NoteCandidates(
1121
        PartialDiagnosticAt PA, Sema &S, OverloadCandidateDisplayKind OCD,
1122
        ArrayRef<Expr *> Args, StringRef Opc = "",
1123
        SourceLocation Loc = SourceLocation(),
1124
        llvm::function_ref<bool(OverloadCandidate &)> Filter =
1125
30.0k
            [](OverloadCandidate &) { return true; });
1126
1127
    void NoteCandidates(Sema &S, ArrayRef<Expr *> Args,
1128
                        ArrayRef<OverloadCandidate *> Cands,
1129
                        StringRef Opc = "",
1130
                        SourceLocation OpLoc = SourceLocation());
1131
1132
1.48M
    LangAS getDestAS() { return DestAS; }
1133
1134
299k
    void setDestAS(LangAS AS) {
1135
299k
      assert((Kind == CSK_InitByConstructor ||
1136
299k
              Kind == CSK_InitByUserDefinedConversion) &&
1137
299k
             "can't set the destination address space when not constructing an "
1138
299k
             "object");
1139
299k
      DestAS = AS;
1140
299k
    }
1141
1142
  };
1143
1144
  bool isBetterOverloadCandidate(Sema &S,
1145
                                 const OverloadCandidate &Cand1,
1146
                                 const OverloadCandidate &Cand2,
1147
                                 SourceLocation Loc,
1148
                                 OverloadCandidateSet::CandidateSetKind Kind);
1149
1150
  struct ConstructorInfo {
1151
    DeclAccessPair FoundDecl;
1152
    CXXConstructorDecl *Constructor;
1153
    FunctionTemplateDecl *ConstructorTmpl;
1154
1155
912k
    explicit operator bool() const { return Constructor; }
1156
  };
1157
1158
  // FIXME: Add an AddOverloadCandidate / AddTemplateOverloadCandidate overload
1159
  // that takes one of these.
1160
2.19M
  inline ConstructorInfo getConstructorInfo(NamedDecl *ND) {
1161
2.19M
    if (isa<UsingDecl>(ND))
1162
1.50k
      return ConstructorInfo{};
1163
2.19M
1164
2.19M
    // For constructors, the access check is performed against the underlying
1165
2.19M
    // declaration, not the found declaration.
1166
2.19M
    auto *D = ND->getUnderlyingDecl();
1167
2.19M
    ConstructorInfo Info = {DeclAccessPair::make(ND, D->getAccess()), nullptr,
1168
2.19M
                            nullptr};
1169
2.19M
    Info.ConstructorTmpl = dyn_cast<FunctionTemplateDecl>(D);
1170
2.19M
    if (Info.ConstructorTmpl)
1171
422k
      D = Info.ConstructorTmpl->getTemplatedDecl();
1172
2.19M
    Info.Constructor = dyn_cast<CXXConstructorDecl>(D);
1173
2.19M
    return Info;
1174
2.19M
  }
1175
1176
} // namespace clang
1177
1178
#endif // LLVM_CLANG_SEMA_OVERLOAD_H