blob: d6b46e91c9530920a55d983558cdb8daa4bbbab7 [file] [log] [blame]
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001//===--- Overload.h - C++ Overloading ---------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the data structures and types used in C++
11// overload resolution.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_SEMA_OVERLOAD_H
16#define LLVM_CLANG_SEMA_OVERLOAD_H
17
Douglas Gregor20093b42009-12-09 23:02:17 +000018#include "clang/AST/Decl.h"
John McCalladbb8f82010-01-13 09:16:55 +000019#include "clang/AST/Expr.h"
Douglas Gregor20093b42009-12-09 23:02:17 +000020#include "clang/AST/Type.h"
John McCall9aa472c2010-03-19 07:35:19 +000021#include "clang/AST/UnresolvedSet.h"
Douglas Gregor20093b42009-12-09 23:02:17 +000022#include "llvm/ADT/SmallPtrSet.h"
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000023#include "llvm/ADT/SmallVector.h"
24
25namespace clang {
Douglas Gregor20093b42009-12-09 23:02:17 +000026 class ASTContext;
Douglas Gregor225c41e2008-11-03 19:09:14 +000027 class CXXConstructorDecl;
Douglas Gregor20093b42009-12-09 23:02:17 +000028 class CXXConversionDecl;
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000029 class FunctionDecl;
30
Douglas Gregor20093b42009-12-09 23:02:17 +000031 /// OverloadingResult - Capture the result of performing overload
32 /// resolution.
33 enum OverloadingResult {
34 OR_Success, ///< Overload resolution succeeded.
35 OR_No_Viable_Function, ///< No viable function found.
36 OR_Ambiguous, ///< Ambiguous candidates found.
Sean Huntc39f6972010-04-07 22:52:07 +000037 OR_Deleted ///< Succeeded, but refers to a deleted function.
Douglas Gregor20093b42009-12-09 23:02:17 +000038 };
39
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000040 /// ImplicitConversionKind - The kind of implicit conversion used to
41 /// convert an argument to a parameter's type. The enumerator values
42 /// match with Table 9 of (C++ 13.3.3.1.1) and are listed such that
43 /// better conversion kinds have smaller values.
44 enum ImplicitConversionKind {
Douglas Gregorf9201e02009-02-11 23:02:49 +000045 ICK_Identity = 0, ///< Identity conversion (no conversion)
46 ICK_Lvalue_To_Rvalue, ///< Lvalue-to-rvalue conversion (C++ 4.1)
47 ICK_Array_To_Pointer, ///< Array-to-pointer conversion (C++ 4.2)
48 ICK_Function_To_Pointer, ///< Function-to-pointer (C++ 4.3)
Douglas Gregor43c79c22009-12-09 00:47:37 +000049 ICK_NoReturn_Adjustment, ///< Removal of noreturn from a type (Clang)
Douglas Gregorf9201e02009-02-11 23:02:49 +000050 ICK_Qualification, ///< Qualification conversions (C++ 4.4)
51 ICK_Integral_Promotion, ///< Integral promotions (C++ 4.5)
52 ICK_Floating_Promotion, ///< Floating point promotions (C++ 4.6)
Douglas Gregor5cdf8212009-02-12 00:15:05 +000053 ICK_Complex_Promotion, ///< Complex promotions (Clang extension)
Douglas Gregorf9201e02009-02-11 23:02:49 +000054 ICK_Integral_Conversion, ///< Integral conversions (C++ 4.7)
55 ICK_Floating_Conversion, ///< Floating point conversions (C++ 4.8)
Douglas Gregor5cdf8212009-02-12 00:15:05 +000056 ICK_Complex_Conversion, ///< Complex conversions (C99 6.3.1.6)
Douglas Gregorf9201e02009-02-11 23:02:49 +000057 ICK_Floating_Integral, ///< Floating-integral conversions (C++ 4.9)
58 ICK_Pointer_Conversion, ///< Pointer conversions (C++ 4.10)
59 ICK_Pointer_Member, ///< Pointer-to-member conversions (C++ 4.11)
60 ICK_Boolean_Conversion, ///< Boolean conversions (C++ 4.12)
61 ICK_Compatible_Conversion, ///< Conversions between compatible types in C99
62 ICK_Derived_To_Base, ///< Derived-to-base (C++ [over.best.ics])
Chandler Carruth23a370f2010-02-25 07:20:54 +000063 ICK_Complex_Real, ///< Complex-real conversions (C99 6.3.1.7)
Douglas Gregorf9201e02009-02-11 23:02:49 +000064 ICK_Num_Conversion_Kinds ///< The number of conversion kinds
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000065 };
66
67 /// ImplicitConversionCategory - The category of an implicit
68 /// conversion kind. The enumerator values match with Table 9 of
69 /// (C++ 13.3.3.1.1) and are listed such that better conversion
70 /// categories have smaller values.
71 enum ImplicitConversionCategory {
72 ICC_Identity = 0, ///< Identity
73 ICC_Lvalue_Transformation, ///< Lvalue transformation
74 ICC_Qualification_Adjustment, ///< Qualification adjustment
75 ICC_Promotion, ///< Promotion
76 ICC_Conversion ///< Conversion
77 };
78
Mike Stump1eb44332009-09-09 15:08:12 +000079 ImplicitConversionCategory
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000080 GetConversionCategory(ImplicitConversionKind Kind);
81
82 /// ImplicitConversionRank - The rank of an implicit conversion
83 /// kind. The enumerator values match with Table 9 of (C++
84 /// 13.3.3.1.1) and are listed such that better conversion ranks
85 /// have smaller values.
86 enum ImplicitConversionRank {
Chandler Carruth23a370f2010-02-25 07:20:54 +000087 ICR_Exact_Match = 0, ///< Exact Match
88 ICR_Promotion, ///< Promotion
89 ICR_Conversion, ///< Conversion
90 ICR_Complex_Real_Conversion ///< Complex <-> Real conversion
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000091 };
92
93 ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind);
94
95 /// StandardConversionSequence - represents a standard conversion
96 /// sequence (C++ 13.3.3.1.1). A standard conversion sequence
97 /// contains between zero and three conversions. If a particular
98 /// conversion is not needed, it will be set to the identity conversion
99 /// (ICK_Identity). Note that the three conversions are
100 /// specified as separate members (rather than in an array) so that
101 /// we can keep the size of a standard conversion sequence to a
102 /// single word.
103 struct StandardConversionSequence {
104 /// First -- The first conversion can be an lvalue-to-rvalue
105 /// conversion, array-to-pointer conversion, or
106 /// function-to-pointer conversion.
107 ImplicitConversionKind First : 8;
108
109 /// Second - The second conversion can be an integral promotion,
110 /// floating point promotion, integral conversion, floating point
111 /// conversion, floating-integral conversion, pointer conversion,
112 /// pointer-to-member conversion, or boolean conversion.
113 ImplicitConversionKind Second : 8;
114
115 /// Third - The third conversion can be a qualification conversion.
116 ImplicitConversionKind Third : 8;
117
Douglas Gregor15da57e2008-10-29 02:00:59 +0000118 /// Deprecated - Whether this the deprecated conversion of a
Mike Stump1eb44332009-09-09 15:08:12 +0000119 /// string literal to a pointer to non-const character data
Douglas Gregor15da57e2008-10-29 02:00:59 +0000120 /// (C++ 4.2p2).
Douglas Gregora9bff302010-02-28 18:30:25 +0000121 bool DeprecatedStringLiteralToCharPtr : 1;
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000122
Douglas Gregor45920e82008-12-19 17:40:08 +0000123 /// IncompatibleObjC - Whether this is an Objective-C conversion
124 /// that we should warn about (if we actually use it).
125 bool IncompatibleObjC : 1;
126
Mike Stump1eb44332009-09-09 15:08:12 +0000127 /// ReferenceBinding - True when this is a reference binding
Douglas Gregorf70bdb92008-10-29 14:50:44 +0000128 /// (C++ [over.ics.ref]).
129 bool ReferenceBinding : 1;
130
Mike Stump1eb44332009-09-09 15:08:12 +0000131 /// DirectBinding - True when this is a reference binding that is a
Douglas Gregorf70bdb92008-10-29 14:50:44 +0000132 /// direct binding (C++ [dcl.init.ref]).
133 bool DirectBinding : 1;
134
Sebastian Redla9845802009-03-29 15:27:50 +0000135 /// RRefBinding - True when this is a reference binding of an rvalue
136 /// reference to an rvalue (C++0x [over.ics.rank]p3b4).
137 bool RRefBinding : 1;
138
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000139 /// FromType - The type that this conversion is converting
Douglas Gregorbc0805a2008-10-23 00:40:37 +0000140 /// from. This is an opaque pointer that can be translated into a
141 /// QualType.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000142 void *FromTypePtr;
143
Douglas Gregorad323a82010-01-27 03:51:04 +0000144 /// ToType - The types that this conversion is converting to in
145 /// each step. This is an opaque pointer that can be translated
146 /// into a QualType.
147 void *ToTypePtrs[3];
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000148
Douglas Gregor225c41e2008-11-03 19:09:14 +0000149 /// CopyConstructor - The copy constructor that is used to perform
150 /// this conversion, when the conversion is actually just the
151 /// initialization of an object via copy constructor. Such
152 /// conversions are either identity conversions or derived-to-base
153 /// conversions.
154 CXXConstructorDecl *CopyConstructor;
155
John McCall1d318332010-01-12 00:44:57 +0000156 void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
Douglas Gregorad323a82010-01-27 03:51:04 +0000157 void setToType(unsigned Idx, QualType T) {
158 assert(Idx < 3 && "To type index is out of range");
159 ToTypePtrs[Idx] = T.getAsOpaquePtr();
160 }
161 void setAllToTypes(QualType T) {
162 ToTypePtrs[0] = T.getAsOpaquePtr();
163 ToTypePtrs[1] = ToTypePtrs[0];
164 ToTypePtrs[2] = ToTypePtrs[0];
165 }
166
John McCall1d318332010-01-12 00:44:57 +0000167 QualType getFromType() const {
168 return QualType::getFromOpaquePtr(FromTypePtr);
169 }
Douglas Gregorad323a82010-01-27 03:51:04 +0000170 QualType getToType(unsigned Idx) const {
171 assert(Idx < 3 && "To type index is out of range");
172 return QualType::getFromOpaquePtr(ToTypePtrs[Idx]);
John McCall1d318332010-01-12 00:44:57 +0000173 }
174
Mike Stump1eb44332009-09-09 15:08:12 +0000175 void setAsIdentityConversion();
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000176 ImplicitConversionRank getRank() const;
177 bool isPointerConversionToBool() const;
Douglas Gregorbc0805a2008-10-23 00:40:37 +0000178 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000179 void DebugPrint() const;
180 };
181
182 /// UserDefinedConversionSequence - Represents a user-defined
183 /// conversion sequence (C++ 13.3.3.1.2).
184 struct UserDefinedConversionSequence {
185 /// Before - Represents the standard conversion that occurs before
186 /// the actual user-defined conversion. (C++ 13.3.3.1.2p1):
187 ///
188 /// If the user-defined conversion is specified by a constructor
189 /// (12.3.1), the initial standard conversion sequence converts
190 /// the source type to the type required by the argument of the
191 /// constructor. If the user-defined conversion is specified by
192 /// a conversion function (12.3.2), the initial standard
193 /// conversion sequence converts the source type to the implicit
194 /// object parameter of the conversion function.
195 StandardConversionSequence Before;
196
Fariborz Jahanian966256a2009-11-06 00:23:08 +0000197 /// EllipsisConversion - When this is true, it means user-defined
198 /// conversion sequence starts with a ... (elipsis) conversion, instead of
199 /// a standard conversion. In this case, 'Before' field must be ignored.
200 // FIXME. I much rather put this as the first field. But there seems to be
201 // a gcc code gen. bug which causes a crash in a test. Putting it here seems
202 // to work around the crash.
203 bool EllipsisConversion : 1;
204
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000205 /// After - Represents the standard conversion that occurs after
206 /// the actual user-defined conversion.
207 StandardConversionSequence After;
Mike Stump1eb44332009-09-09 15:08:12 +0000208
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000209 /// ConversionFunction - The function that will perform the
210 /// user-defined conversion.
211 FunctionDecl* ConversionFunction;
212
213 void DebugPrint() const;
214 };
215
John McCall1d318332010-01-12 00:44:57 +0000216 /// Represents an ambiguous user-defined conversion sequence.
217 struct AmbiguousConversionSequence {
218 typedef llvm::SmallVector<FunctionDecl*, 4> ConversionSet;
219
220 void *FromTypePtr;
221 void *ToTypePtr;
222 char Buffer[sizeof(ConversionSet)];
223
224 QualType getFromType() const {
225 return QualType::getFromOpaquePtr(FromTypePtr);
226 }
227 QualType getToType() const {
228 return QualType::getFromOpaquePtr(ToTypePtr);
229 }
230 void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); }
231 void setToType(QualType T) { ToTypePtr = T.getAsOpaquePtr(); }
232
233 ConversionSet &conversions() {
234 return *reinterpret_cast<ConversionSet*>(Buffer);
235 }
236
237 const ConversionSet &conversions() const {
238 return *reinterpret_cast<const ConversionSet*>(Buffer);
239 }
240
241 void addConversion(FunctionDecl *D) {
242 conversions().push_back(D);
243 }
244
245 typedef ConversionSet::iterator iterator;
246 iterator begin() { return conversions().begin(); }
247 iterator end() { return conversions().end(); }
248
249 typedef ConversionSet::const_iterator const_iterator;
250 const_iterator begin() const { return conversions().begin(); }
251 const_iterator end() const { return conversions().end(); }
252
253 void construct();
254 void destruct();
255 void copyFrom(const AmbiguousConversionSequence &);
256 };
257
John McCalladbb8f82010-01-13 09:16:55 +0000258 /// BadConversionSequence - Records information about an invalid
259 /// conversion sequence.
260 struct BadConversionSequence {
261 enum FailureKind {
262 no_conversion,
263 unrelated_class,
264 suppressed_user,
265 bad_qualifiers
266 };
267
268 // This can be null, e.g. for implicit object arguments.
269 Expr *FromExpr;
270
271 FailureKind Kind;
272
273 private:
274 // The type we're converting from (an opaque QualType).
275 void *FromTy;
276
277 // The type we're converting to (an opaque QualType).
278 void *ToTy;
279
280 public:
281 void init(FailureKind K, Expr *From, QualType To) {
282 init(K, From->getType(), To);
283 FromExpr = From;
284 }
285 void init(FailureKind K, QualType From, QualType To) {
286 Kind = K;
287 FromExpr = 0;
288 setFromType(From);
289 setToType(To);
290 }
291
292 QualType getFromType() const { return QualType::getFromOpaquePtr(FromTy); }
293 QualType getToType() const { return QualType::getFromOpaquePtr(ToTy); }
294
295 void setFromExpr(Expr *E) {
296 FromExpr = E;
297 setFromType(E->getType());
298 }
299 void setFromType(QualType T) { FromTy = T.getAsOpaquePtr(); }
300 void setToType(QualType T) { ToTy = T.getAsOpaquePtr(); }
301 };
302
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000303 /// ImplicitConversionSequence - Represents an implicit conversion
Mike Stump1eb44332009-09-09 15:08:12 +0000304 /// sequence, which may be a standard conversion sequence
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000305 /// (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2),
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000306 /// or an ellipsis conversion sequence (C++ 13.3.3.1.3).
307 struct ImplicitConversionSequence {
308 /// Kind - The kind of implicit conversion sequence. BadConversion
309 /// specifies that there is no conversion from the source type to
John McCall1d318332010-01-12 00:44:57 +0000310 /// the target type. AmbiguousConversion represents the unique
311 /// ambiguous conversion (C++0x [over.best.ics]p10).
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000312 enum Kind {
313 StandardConversion = 0,
314 UserDefinedConversion,
John McCall1d318332010-01-12 00:44:57 +0000315 AmbiguousConversion,
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000316 EllipsisConversion,
317 BadConversion
318 };
319
John McCall1d318332010-01-12 00:44:57 +0000320 private:
John McCallb1bdc622010-02-25 01:37:24 +0000321 enum {
322 Uninitialized = BadConversion + 1
323 };
324
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000325 /// ConversionKind - The kind of implicit conversion sequence.
John McCallb1bdc622010-02-25 01:37:24 +0000326 unsigned ConversionKind;
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000327
John McCall1d318332010-01-12 00:44:57 +0000328 void setKind(Kind K) {
John McCallb1bdc622010-02-25 01:37:24 +0000329 destruct();
John McCall1d318332010-01-12 00:44:57 +0000330 ConversionKind = K;
331 }
332
John McCallb1bdc622010-02-25 01:37:24 +0000333 void destruct() {
334 if (ConversionKind == AmbiguousConversion) Ambiguous.destruct();
335 }
336
John McCall1d318332010-01-12 00:44:57 +0000337 public:
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000338 union {
339 /// When ConversionKind == StandardConversion, provides the
340 /// details of the standard conversion sequence.
341 StandardConversionSequence Standard;
342
343 /// When ConversionKind == UserDefinedConversion, provides the
344 /// details of the user-defined conversion sequence.
345 UserDefinedConversionSequence UserDefined;
John McCall1d318332010-01-12 00:44:57 +0000346
347 /// When ConversionKind == AmbiguousConversion, provides the
348 /// details of the ambiguous conversion.
349 AmbiguousConversionSequence Ambiguous;
John McCalladbb8f82010-01-13 09:16:55 +0000350
351 /// When ConversionKind == BadConversion, provides the details
352 /// of the bad conversion.
353 BadConversionSequence Bad;
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000354 };
John McCall1d318332010-01-12 00:44:57 +0000355
John McCallb1bdc622010-02-25 01:37:24 +0000356 ImplicitConversionSequence() : ConversionKind(Uninitialized) {}
John McCall1d318332010-01-12 00:44:57 +0000357 ~ImplicitConversionSequence() {
John McCallb1bdc622010-02-25 01:37:24 +0000358 destruct();
John McCall1d318332010-01-12 00:44:57 +0000359 }
360 ImplicitConversionSequence(const ImplicitConversionSequence &Other)
361 : ConversionKind(Other.ConversionKind)
362 {
363 switch (ConversionKind) {
John McCallb1bdc622010-02-25 01:37:24 +0000364 case Uninitialized: break;
John McCall1d318332010-01-12 00:44:57 +0000365 case StandardConversion: Standard = Other.Standard; break;
366 case UserDefinedConversion: UserDefined = Other.UserDefined; break;
367 case AmbiguousConversion: Ambiguous.copyFrom(Other.Ambiguous); break;
368 case EllipsisConversion: break;
John McCalladbb8f82010-01-13 09:16:55 +0000369 case BadConversion: Bad = Other.Bad; break;
John McCall1d318332010-01-12 00:44:57 +0000370 }
371 }
372
373 ImplicitConversionSequence &
374 operator=(const ImplicitConversionSequence &Other) {
John McCallb1bdc622010-02-25 01:37:24 +0000375 destruct();
John McCall1d318332010-01-12 00:44:57 +0000376 new (this) ImplicitConversionSequence(Other);
377 return *this;
378 }
Fariborz Jahanianb1663d02009-09-23 00:58:07 +0000379
John McCallb1bdc622010-02-25 01:37:24 +0000380 Kind getKind() const {
381 assert(isInitialized() && "querying uninitialized conversion");
382 return Kind(ConversionKind);
383 }
384 bool isBad() const { return getKind() == BadConversion; }
385 bool isStandard() const { return getKind() == StandardConversion; }
386 bool isEllipsis() const { return getKind() == EllipsisConversion; }
387 bool isAmbiguous() const { return getKind() == AmbiguousConversion; }
388 bool isUserDefined() const { return getKind() == UserDefinedConversion; }
389
390 /// Determines whether this conversion sequence has been
391 /// initialized. Most operations should never need to query
392 /// uninitialized conversions and should assert as above.
393 bool isInitialized() const { return ConversionKind != Uninitialized; }
394
395 /// Sets this sequence as a bad conversion for an explicit argument.
396 void setBad(BadConversionSequence::FailureKind Failure,
397 Expr *FromExpr, QualType ToType) {
398 setKind(BadConversion);
399 Bad.init(Failure, FromExpr, ToType);
John McCall1d318332010-01-12 00:44:57 +0000400 }
401
John McCallb1bdc622010-02-25 01:37:24 +0000402 /// Sets this sequence as a bad conversion for an implicit argument.
403 void setBad(BadConversionSequence::FailureKind Failure,
404 QualType FromType, QualType ToType) {
405 setKind(BadConversion);
406 Bad.init(Failure, FromType, ToType);
407 }
408
John McCall1d318332010-01-12 00:44:57 +0000409 void setStandard() { setKind(StandardConversion); }
410 void setEllipsis() { setKind(EllipsisConversion); }
411 void setUserDefined() { setKind(UserDefinedConversion); }
412 void setAmbiguous() {
John McCallb1bdc622010-02-25 01:37:24 +0000413 if (ConversionKind == AmbiguousConversion) return;
John McCall1d318332010-01-12 00:44:57 +0000414 ConversionKind = AmbiguousConversion;
415 Ambiguous.construct();
416 }
417
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000418 // The result of a comparison between implicit conversion
419 // sequences. Use Sema::CompareImplicitConversionSequences to
420 // actually perform the comparison.
421 enum CompareKind {
Douglas Gregor57373262008-10-22 14:17:15 +0000422 Better = -1,
423 Indistinguishable = 0,
424 Worse = 1
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000425 };
426
427 void DebugPrint() const;
428 };
429
John McCalladbb8f82010-01-13 09:16:55 +0000430 enum OverloadFailureKind {
431 ovl_fail_too_many_arguments,
432 ovl_fail_too_few_arguments,
433 ovl_fail_bad_conversion,
John McCall717e8912010-01-23 05:17:32 +0000434 ovl_fail_bad_deduction,
435
436 /// This conversion candidate was not considered because it
437 /// duplicates the work of a trivial or derived-to-base
438 /// conversion.
439 ovl_fail_trivial_conversion,
440
441 /// This conversion candidate is not viable because its result
442 /// type is not implicitly convertible to the desired type.
443 ovl_fail_bad_final_conversion
John McCalladbb8f82010-01-13 09:16:55 +0000444 };
445
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000446 /// OverloadCandidate - A single candidate in an overload set (C++ 13.3).
447 struct OverloadCandidate {
Douglas Gregoreb8f3062008-11-12 17:17:38 +0000448 /// Function - The actual function that this candidate
Mike Stump1eb44332009-09-09 15:08:12 +0000449 /// represents. When NULL, this is a built-in candidate
450 /// (C++ [over.oper]) or a surrogate for a conversion to a
Douglas Gregor106c6eb2008-11-19 22:57:39 +0000451 /// function pointer or reference (C++ [over.call.object]).
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000452 FunctionDecl *Function;
Douglas Gregor106c6eb2008-11-19 22:57:39 +0000453
John McCall9aa472c2010-03-19 07:35:19 +0000454 /// FoundDecl - The original declaration that was looked up /
455 /// invented / otherwise found, together with its access.
456 /// Might be a UsingShadowDecl or a FunctionTemplateDecl.
457 DeclAccessPair FoundDecl;
458
Douglas Gregoreb8f3062008-11-12 17:17:38 +0000459 // BuiltinTypes - Provides the return and parameter types of a
460 // built-in overload candidate. Only valid when Function is NULL.
461 struct {
462 QualType ResultTy;
463 QualType ParamTypes[3];
464 } BuiltinTypes;
Mike Stump1eb44332009-09-09 15:08:12 +0000465
Douglas Gregor106c6eb2008-11-19 22:57:39 +0000466 /// Surrogate - The conversion function for which this candidate
467 /// is a surrogate, but only if IsSurrogate is true.
468 CXXConversionDecl *Surrogate;
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000469
470 /// Conversions - The conversion sequences used to convert the
471 /// function arguments to the function parameters.
472 llvm::SmallVector<ImplicitConversionSequence, 4> Conversions;
473
474 /// Viable - True to indicate that this overload candidate is viable.
475 bool Viable;
Douglas Gregorf1991ea2008-11-07 22:36:19 +0000476
Douglas Gregor106c6eb2008-11-19 22:57:39 +0000477 /// IsSurrogate - True to indicate that this candidate is a
478 /// surrogate for a conversion to a function pointer or reference
479 /// (C++ [over.call.object]).
480 bool IsSurrogate;
481
Douglas Gregor88a35142008-12-22 05:46:06 +0000482 /// IgnoreObjectArgument - True to indicate that the first
483 /// argument's conversion, which for this function represents the
484 /// implicit object argument, should be ignored. This will be true
485 /// when the candidate is a static member function (where the
486 /// implicit object argument is just a placeholder) or a
487 /// non-static member function when the call doesn't have an
488 /// object argument.
489 bool IgnoreObjectArgument;
490
John McCalladbb8f82010-01-13 09:16:55 +0000491 /// FailureKind - The reason why this candidate is not viable.
492 /// Actually an OverloadFailureKind.
493 unsigned char FailureKind;
494
John McCall342fec42010-02-01 18:53:26 +0000495 /// A structure used to record information about a failed
496 /// template argument deduction.
497 struct DeductionFailureInfo {
498 // A Sema::TemplateDeductionResult.
499 unsigned Result;
500
501 // A TemplateParameter.
502 void *TemplateParameter;
503 };
504
505 union {
506 DeductionFailureInfo DeductionFailure;
507
508 /// FinalConversion - For a conversion function (where Function is
509 /// a CXXConversionDecl), the standard conversion that occurs
510 /// after the call to the overload candidate to convert the result
511 /// of calling the conversion function to the required type.
512 StandardConversionSequence FinalConversion;
513 };
John McCall1d318332010-01-12 00:44:57 +0000514
515 /// hasAmbiguousConversion - Returns whether this overload
516 /// candidate requires an ambiguous conversion or not.
517 bool hasAmbiguousConversion() const {
518 for (llvm::SmallVectorImpl<ImplicitConversionSequence>::const_iterator
519 I = Conversions.begin(), E = Conversions.end(); I != E; ++I) {
John McCallb1bdc622010-02-25 01:37:24 +0000520 if (!I->isInitialized()) return false;
John McCall1d318332010-01-12 00:44:57 +0000521 if (I->isAmbiguous()) return true;
522 }
523 return false;
524 }
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000525 };
526
527 /// OverloadCandidateSet - A set of overload candidates, used in C++
528 /// overload resolution (C++ 13.3).
Douglas Gregor3f396022009-09-28 04:47:19 +0000529 class OverloadCandidateSet : public llvm::SmallVector<OverloadCandidate, 16> {
Douglas Gregor20093b42009-12-09 23:02:17 +0000530 typedef llvm::SmallVector<OverloadCandidate, 16> inherited;
Douglas Gregor3f396022009-09-28 04:47:19 +0000531 llvm::SmallPtrSet<Decl *, 16> Functions;
John McCall5769d612010-02-08 23:07:23 +0000532
533 SourceLocation Loc;
Douglas Gregor3f396022009-09-28 04:47:19 +0000534 public:
John McCall5769d612010-02-08 23:07:23 +0000535 OverloadCandidateSet(SourceLocation Loc) : Loc(Loc) {}
536
537 SourceLocation getLocation() const { return Loc; }
538
Douglas Gregor3f396022009-09-28 04:47:19 +0000539 /// \brief Determine when this overload candidate will be new to the
540 /// overload set.
541 bool isNewCandidate(Decl *F) {
542 return Functions.insert(F->getCanonicalDecl());
543 }
Douglas Gregor20093b42009-12-09 23:02:17 +0000544
545 /// \brief Clear out all of the candidates.
546 void clear() {
547 inherited::clear();
548 Functions.clear();
549 }
Douglas Gregor3f396022009-09-28 04:47:19 +0000550 };
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000551} // end namespace clang
552
553#endif // LLVM_CLANG_SEMA_OVERLOAD_H