Overload.h 43 KB

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