blob: 2aeab44db3df97ee9515778bbad2bf6ea0ca7374 [file] [log] [blame]
Sebastian Redl26d85b12008-11-05 21:50:06 +00001//===--- SemaNamedCast.cpp - Semantic Analysis for Named Casts ------------===//
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 implements semantic analysis for C++ named casts.
11//
12//===----------------------------------------------------------------------===//
13
14#include "Sema.h"
15#include "SemaInherit.h"
16#include "clang/AST/ExprCXX.h"
17#include "clang/AST/ASTContext.h"
18#include "clang/Basic/Diagnostic.h"
19#include "llvm/ADT/SmallVector.h"
Sebastian Redle3dc28a2008-11-07 23:29:29 +000020#include <set>
Sebastian Redl26d85b12008-11-05 21:50:06 +000021using namespace clang;
22
Sebastian Redl37d6de32008-11-08 13:00:26 +000023enum TryStaticCastResult {
24 TSC_NotApplicable, ///< The cast method is not applicable.
25 TSC_Success, ///< The cast method is appropriate and successful.
26 TSC_Failed ///< The cast method is appropriate, but failed. A
27 ///< diagnostic has been emitted.
28};
29
30static void CheckConstCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
31 const SourceRange &OpRange,
32 const SourceRange &DestRange);
33static void CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
34 const SourceRange &OpRange,
35 const SourceRange &DestRange);
36static void CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
37 const SourceRange &OpRange);
38static void CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
39 const SourceRange &OpRange,
40 const SourceRange &DestRange);
41
42static bool CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType);
43static TryStaticCastResult TryStaticReferenceDowncast(
44 Sema &Self, Expr *SrcExpr, QualType DestType, const SourceRange &OpRange);
45static TryStaticCastResult TryStaticPointerDowncast(
46 Sema &Self, QualType SrcType, QualType DestType, const SourceRange &OpRange);
47static TryStaticCastResult TryStaticDowncast(Sema &Self, QualType SrcType,
48 QualType DestType,
49 const SourceRange &OpRange,
50 QualType OrigSrcType,
51 QualType OrigDestType);
52static TryStaticCastResult TryStaticImplicitCast(Sema &Self, Expr *SrcExpr,
53 QualType DestType,
54 const SourceRange &OpRange);
55
Sebastian Redl26d85b12008-11-05 21:50:06 +000056/// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
57Action::ExprResult
58Sema::ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
59 SourceLocation LAngleBracketLoc, TypeTy *Ty,
60 SourceLocation RAngleBracketLoc,
61 SourceLocation LParenLoc, ExprTy *E,
62 SourceLocation RParenLoc) {
63 Expr *Ex = (Expr*)E;
64 QualType DestType = QualType::getFromOpaquePtr(Ty);
65 SourceRange OpRange(OpLoc, RParenLoc);
66 SourceRange DestRange(LAngleBracketLoc, RAngleBracketLoc);
67
Douglas Gregor9103bb22008-12-17 22:52:20 +000068 // If the type is dependent, we won't do the semantic analysis now.
69 // FIXME: should we check this in a more fine-grained manner?
70 bool TypeDependent = DestType->isDependentType() || Ex->isTypeDependent();
71
Sebastian Redl26d85b12008-11-05 21:50:06 +000072 switch (Kind) {
73 default: assert(0 && "Unknown C++ cast!");
74
75 case tok::kw_const_cast:
Douglas Gregor9103bb22008-12-17 22:52:20 +000076 if (!TypeDependent)
77 CheckConstCast(*this, Ex, DestType, OpRange, DestRange);
Sebastian Redl26d85b12008-11-05 21:50:06 +000078 return new CXXConstCastExpr(DestType.getNonReferenceType(), Ex,
79 DestType, OpLoc);
80
81 case tok::kw_dynamic_cast:
Douglas Gregor9103bb22008-12-17 22:52:20 +000082 if (!TypeDependent)
83 CheckDynamicCast(*this, Ex, DestType, OpRange, DestRange);
Sebastian Redl26d85b12008-11-05 21:50:06 +000084 return new CXXDynamicCastExpr(DestType.getNonReferenceType(), Ex,
85 DestType, OpLoc);
86
87 case tok::kw_reinterpret_cast:
Douglas Gregor9103bb22008-12-17 22:52:20 +000088 if (!TypeDependent)
89 CheckReinterpretCast(*this, Ex, DestType, OpRange, DestRange);
Sebastian Redl26d85b12008-11-05 21:50:06 +000090 return new CXXReinterpretCastExpr(DestType.getNonReferenceType(), Ex,
91 DestType, OpLoc);
92
93 case tok::kw_static_cast:
Douglas Gregor9103bb22008-12-17 22:52:20 +000094 if (!TypeDependent)
95 CheckStaticCast(*this, Ex, DestType, OpRange);
Sebastian Redl26d85b12008-11-05 21:50:06 +000096 return new CXXStaticCastExpr(DestType.getNonReferenceType(), Ex,
97 DestType, OpLoc);
98 }
99
100 return true;
101}
102
103/// CheckConstCast - Check that a const_cast\<DestType\>(SrcExpr) is valid.
104/// Refer to C++ 5.2.11 for details. const_cast is typically used in code
105/// like this:
106/// const char *str = "literal";
107/// legacy_function(const_cast\<char*\>(str));
108void
Sebastian Redl37d6de32008-11-08 13:00:26 +0000109CheckConstCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
110 const SourceRange &OpRange, const SourceRange &DestRange)
Sebastian Redl26d85b12008-11-05 21:50:06 +0000111{
112 QualType OrigDestType = DestType, OrigSrcType = SrcExpr->getType();
113
Sebastian Redl37d6de32008-11-08 13:00:26 +0000114 DestType = Self.Context.getCanonicalType(DestType);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000115 QualType SrcType = SrcExpr->getType();
116 if (const ReferenceType *DestTypeTmp = DestType->getAsReferenceType()) {
Sebastian Redl37d6de32008-11-08 13:00:26 +0000117 if (SrcExpr->isLvalue(Self.Context) != Expr::LV_Valid) {
Sebastian Redl26d85b12008-11-05 21:50:06 +0000118 // Cannot cast non-lvalue to reference type.
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000119 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_rvalue)
Chris Lattnerd1625842008-11-24 06:25:27 +0000120 << "const_cast" << OrigDestType << SrcExpr->getSourceRange();
Sebastian Redl26d85b12008-11-05 21:50:06 +0000121 return;
122 }
123
124 // C++ 5.2.11p4: An lvalue of type T1 can be [cast] to an lvalue of type T2
125 // [...] if a pointer to T1 can be [cast] to the type pointer to T2.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000126 DestType = Self.Context.getPointerType(DestTypeTmp->getPointeeType());
127 SrcType = Self.Context.getPointerType(SrcType);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000128 } else {
129 // C++ 5.2.11p1: Otherwise, the result is an rvalue and the
130 // lvalue-to-rvalue, array-to-pointer, and function-to-pointer standard
131 // conversions are performed on the expression.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000132 Self.DefaultFunctionArrayConversion(SrcExpr);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000133 SrcType = SrcExpr->getType();
134 }
135
Sebastian Redlf20269b2009-01-26 22:19:12 +0000136 // C++ 5.2.11p5: For a const_cast involving pointers to data members [...]
137 // the rules for const_cast are the same as those used for pointers.
138
139 if (!DestType->isPointerType() && !DestType->isMemberPointerType()) {
Sebastian Redl26d85b12008-11-05 21:50:06 +0000140 // Cannot cast to non-pointer, non-reference type. Note that, if DestType
141 // was a reference type, we converted it to a pointer above.
142 // C++ 5.2.11p3: For two pointer types [...]
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000143 Self.Diag(OpRange.getBegin(), diag::err_bad_const_cast_dest)
Chris Lattnerd1625842008-11-24 06:25:27 +0000144 << OrigDestType << DestRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000145 return;
146 }
Sebastian Redlf20269b2009-01-26 22:19:12 +0000147 if (DestType->isFunctionPointerType() ||
148 DestType->isMemberFunctionPointerType()) {
Sebastian Redl26d85b12008-11-05 21:50:06 +0000149 // Cannot cast direct function pointers.
150 // C++ 5.2.11p2: [...] where T is any object type or the void type [...]
151 // T is the ultimate pointee of source and target type.
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000152 Self.Diag(OpRange.getBegin(), diag::err_bad_const_cast_dest)
Chris Lattnerd1625842008-11-24 06:25:27 +0000153 << OrigDestType << DestRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000154 return;
155 }
Sebastian Redl37d6de32008-11-08 13:00:26 +0000156 SrcType = Self.Context.getCanonicalType(SrcType);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000157
158 // Unwrap the pointers. Ignore qualifiers. Terminate early if the types are
159 // completely equal.
160 // FIXME: const_cast should probably not be able to convert between pointers
161 // to different address spaces.
162 // C++ 5.2.11p3 describes the core semantics of const_cast. All cv specifiers
163 // in multi-level pointers may change, but the level count must be the same,
164 // as must be the final pointee type.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000165 while (SrcType != DestType &&
166 Self.UnwrapSimilarPointerTypes(SrcType, DestType)) {
Sebastian Redl26d85b12008-11-05 21:50:06 +0000167 SrcType = SrcType.getUnqualifiedType();
168 DestType = DestType.getUnqualifiedType();
169 }
170
171 // Doug Gregor said to disallow this until users complain.
172#if 0
173 // If we end up with constant arrays of equal size, unwrap those too. A cast
174 // from const int [N] to int (&)[N] is invalid by my reading of the
175 // standard, but g++ accepts it even with -ansi -pedantic.
176 // No more than one level, though, so don't embed this in the unwrap loop
177 // above.
178 const ConstantArrayType *SrcTypeArr, *DestTypeArr;
Sebastian Redl37d6de32008-11-08 13:00:26 +0000179 if ((SrcTypeArr = Self.Context.getAsConstantArrayType(SrcType)) &&
180 (DestTypeArr = Self.Context.getAsConstantArrayType(DestType)))
Sebastian Redl26d85b12008-11-05 21:50:06 +0000181 {
182 if (SrcTypeArr->getSize() != DestTypeArr->getSize()) {
183 // Different array sizes.
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000184 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic)
Chris Lattnerd1625842008-11-24 06:25:27 +0000185 << "const_cast" << OrigDestType << OrigSrcType << OpRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000186 return;
187 }
188 SrcType = SrcTypeArr->getElementType().getUnqualifiedType();
189 DestType = DestTypeArr->getElementType().getUnqualifiedType();
190 }
191#endif
192
193 // Since we're dealing in canonical types, the remainder must be the same.
194 if (SrcType != DestType) {
195 // Cast between unrelated types.
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000196 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic)
Chris Lattnerd1625842008-11-24 06:25:27 +0000197 << "const_cast" << OrigDestType << OrigSrcType << OpRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000198 return;
199 }
200}
201
202/// CheckReinterpretCast - Check that a reinterpret_cast\<DestType\>(SrcExpr) is
203/// valid.
204/// Refer to C++ 5.2.10 for details. reinterpret_cast is typically used in code
205/// like this:
206/// char *bytes = reinterpret_cast\<char*\>(int_ptr);
207void
Sebastian Redl37d6de32008-11-08 13:00:26 +0000208CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
209 const SourceRange &OpRange, const SourceRange &DestRange)
Sebastian Redl26d85b12008-11-05 21:50:06 +0000210{
211 QualType OrigDestType = DestType, OrigSrcType = SrcExpr->getType();
212
Sebastian Redl37d6de32008-11-08 13:00:26 +0000213 DestType = Self.Context.getCanonicalType(DestType);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000214 QualType SrcType = SrcExpr->getType();
215 if (const ReferenceType *DestTypeTmp = DestType->getAsReferenceType()) {
Sebastian Redl37d6de32008-11-08 13:00:26 +0000216 if (SrcExpr->isLvalue(Self.Context) != Expr::LV_Valid) {
Sebastian Redl26d85b12008-11-05 21:50:06 +0000217 // Cannot cast non-lvalue to reference type.
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000218 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_rvalue)
Chris Lattnerd1625842008-11-24 06:25:27 +0000219 << "reinterpret_cast" << OrigDestType << SrcExpr->getSourceRange();
Sebastian Redl26d85b12008-11-05 21:50:06 +0000220 return;
221 }
222
223 // C++ 5.2.10p10: [...] a reference cast reinterpret_cast<T&>(x) has the
224 // same effect as the conversion *reinterpret_cast<T*>(&x) with the
225 // built-in & and * operators.
226 // This code does this transformation for the checked types.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000227 DestType = Self.Context.getPointerType(DestTypeTmp->getPointeeType());
228 SrcType = Self.Context.getPointerType(SrcType);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000229 } else {
230 // C++ 5.2.10p1: [...] the lvalue-to-rvalue, array-to-pointer, and
231 // function-to-pointer standard conversions are performed on the
232 // expression v.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000233 Self.DefaultFunctionArrayConversion(SrcExpr);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000234 SrcType = SrcExpr->getType();
235 }
236
237 // Canonicalize source for comparison.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000238 SrcType = Self.Context.getCanonicalType(SrcType);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000239
240 bool destIsPtr = DestType->isPointerType();
241 bool srcIsPtr = SrcType->isPointerType();
242 if (!destIsPtr && !srcIsPtr) {
243 // Except for std::nullptr_t->integer, which is not supported yet, and
244 // lvalue->reference, which is handled above, at least one of the two
245 // arguments must be a pointer.
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000246 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic)
Chris Lattnerd1625842008-11-24 06:25:27 +0000247 << "reinterpret_cast" << OrigDestType << OrigSrcType << OpRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000248 return;
249 }
250
251 if (SrcType == DestType) {
252 // C++ 5.2.10p2 has a note that mentions that, subject to all other
253 // restrictions, a cast to the same type is allowed. The intent is not
254 // entirely clear here, since all other paragraphs explicitly forbid casts
255 // to the same type. However, the behavior of compilers is pretty consistent
256 // on this point: allow same-type conversion if the involved are pointers,
257 // disallow otherwise.
258 return;
259 }
260
261 // Note: Clang treats enumeration types as integral types. If this is ever
262 // changed for C++, the additional check here will be redundant.
263 if (DestType->isIntegralType() && !DestType->isEnumeralType()) {
Sebastian Redl03a6cf92008-11-05 22:15:14 +0000264 assert(srcIsPtr && "One type must be a pointer");
Sebastian Redl26d85b12008-11-05 21:50:06 +0000265 // C++ 5.2.10p4: A pointer can be explicitly converted to any integral
266 // type large enough to hold it.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000267 if (Self.Context.getTypeSize(SrcType) >
268 Self.Context.getTypeSize(DestType)) {
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000269 Self.Diag(OpRange.getBegin(), diag::err_bad_reinterpret_cast_small_int)
Chris Lattnerd1625842008-11-24 06:25:27 +0000270 << OrigDestType << DestRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000271 }
272 return;
273 }
274
275 if (SrcType->isIntegralType() || SrcType->isEnumeralType()) {
Sebastian Redl03a6cf92008-11-05 22:15:14 +0000276 assert(destIsPtr && "One type must be a pointer");
Sebastian Redl26d85b12008-11-05 21:50:06 +0000277 // C++ 5.2.10p5: A value of integral or enumeration type can be explicitly
278 // converted to a pointer.
279 return;
280 }
281
282 if (!destIsPtr || !srcIsPtr) {
283 // With the valid non-pointer conversions out of the way, we can be even
284 // more stringent.
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000285 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic)
Chris Lattnerd1625842008-11-24 06:25:27 +0000286 << "reinterpret_cast" << OrigDestType << OrigSrcType << OpRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000287 return;
288 }
289
290 // C++ 5.2.10p2: The reinterpret_cast operator shall not cast away constness.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000291 if (CastsAwayConstness(Self, SrcType, DestType)) {
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000292 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_const_away)
Chris Lattnerd1625842008-11-24 06:25:27 +0000293 << "reinterpret_cast" << OrigDestType << OrigSrcType << OpRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000294 return;
295 }
296
297 // Not casting away constness, so the only remaining check is for compatible
298 // pointer categories.
299
300 if (SrcType->isFunctionPointerType()) {
301 if (DestType->isFunctionPointerType()) {
302 // C++ 5.2.10p6: A pointer to a function can be explicitly converted to
303 // a pointer to a function of a different type.
304 return;
305 }
306
307 // FIXME: Handle member pointers.
308
309 // C++0x 5.2.10p8: Converting a pointer to a function into a pointer to
310 // an object type or vice versa is conditionally-supported.
311 // Compilers support it in C++03 too, though, because it's necessary for
312 // casting the return value of dlsym() and GetProcAddress().
313 // FIXME: Conditionally-supported behavior should be configurable in the
314 // TargetInfo or similar.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000315 if (!Self.getLangOptions().CPlusPlus0x) {
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000316 Self.Diag(OpRange.getBegin(), diag::ext_reinterpret_cast_fn_obj)
317 << OpRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000318 }
319 return;
320 }
321
322 // FIXME: Handle member pointers.
323
324 if (DestType->isFunctionPointerType()) {
325 // See above.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000326 if (!Self.getLangOptions().CPlusPlus0x) {
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000327 Self.Diag(OpRange.getBegin(), diag::ext_reinterpret_cast_fn_obj)
328 << OpRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000329 }
330 return;
331 }
332
333 // C++ 5.2.10p7: A pointer to an object can be explicitly converted to
334 // a pointer to an object of different type.
335 // Void pointers are not specified, but supported by every compiler out there.
336 // So we finish by allowing everything that remains - it's got to be two
337 // object pointers.
338}
339
340/// CastsAwayConstness - Check if the pointer conversion from SrcType
341/// to DestType casts away constness as defined in C++
342/// 5.2.11p8ff. This is used by the cast checkers. Both arguments
343/// must denote pointer types.
344bool
Sebastian Redl37d6de32008-11-08 13:00:26 +0000345CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType)
Sebastian Redl26d85b12008-11-05 21:50:06 +0000346{
347 // Casting away constness is defined in C++ 5.2.11p8 with reference to
348 // C++ 4.4.
349 // We piggyback on Sema::IsQualificationConversion for this, since the rules
350 // are non-trivial. So first we construct Tcv *...cv* as described in
351 // C++ 5.2.11p8.
352
353 QualType UnwrappedSrcType = SrcType, UnwrappedDestType = DestType;
354 llvm::SmallVector<unsigned, 8> cv1, cv2;
355
356 // Find the qualifications.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000357 while (Self.UnwrapSimilarPointerTypes(UnwrappedSrcType, UnwrappedDestType)) {
Sebastian Redl26d85b12008-11-05 21:50:06 +0000358 cv1.push_back(UnwrappedSrcType.getCVRQualifiers());
359 cv2.push_back(UnwrappedDestType.getCVRQualifiers());
360 }
361 assert(cv1.size() > 0 && "Must have at least one pointer level.");
362
363 // Construct void pointers with those qualifiers (in reverse order of
364 // unwrapping, of course).
Sebastian Redl37d6de32008-11-08 13:00:26 +0000365 QualType SrcConstruct = Self.Context.VoidTy;
366 QualType DestConstruct = Self.Context.VoidTy;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000367 for (llvm::SmallVector<unsigned, 8>::reverse_iterator i1 = cv1.rbegin(),
368 i2 = cv2.rbegin();
369 i1 != cv1.rend(); ++i1, ++i2)
370 {
Sebastian Redl37d6de32008-11-08 13:00:26 +0000371 SrcConstruct = Self.Context.getPointerType(
372 SrcConstruct.getQualifiedType(*i1));
373 DestConstruct = Self.Context.getPointerType(
374 DestConstruct.getQualifiedType(*i2));
Sebastian Redl26d85b12008-11-05 21:50:06 +0000375 }
376
377 // Test if they're compatible.
378 return SrcConstruct != DestConstruct &&
Sebastian Redl37d6de32008-11-08 13:00:26 +0000379 !Self.IsQualificationConversion(SrcConstruct, DestConstruct);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000380}
381
382/// CheckStaticCast - Check that a static_cast\<DestType\>(SrcExpr) is valid.
383/// Refer to C++ 5.2.9 for details. Static casts are mostly used for making
384/// implicit conversions explicit and getting rid of data loss warnings.
385void
Sebastian Redl37d6de32008-11-08 13:00:26 +0000386CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
387 const SourceRange &OpRange)
Sebastian Redl26d85b12008-11-05 21:50:06 +0000388{
389 // The order the tests is not entirely arbitrary. There is one conversion
390 // that can be handled in two different ways. Given:
391 // struct A {};
392 // struct B : public A {
393 // B(); B(const A&);
394 // };
395 // const A &a = B();
396 // the cast static_cast<const B&>(a) could be seen as either a static
397 // reference downcast, or an explicit invocation of the user-defined
398 // conversion using B's conversion constructor.
399 // DR 427 specifies that the downcast is to be applied here.
400
401 // C++ 5.2.9p4: Any expression can be explicitly converted to type "cv void".
402 if (DestType->isVoidType()) {
403 return;
404 }
405
406 // C++ 5.2.9p5, reference downcast.
407 // See the function for details.
408 // DR 427 specifies that this is to be applied before paragraph 2.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000409 if (TryStaticReferenceDowncast(Self, SrcExpr, DestType, OpRange)
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000410 > TSC_NotApplicable) {
Sebastian Redl26d85b12008-11-05 21:50:06 +0000411 return;
412 }
413
414 // C++ 5.2.9p2: An expression e can be explicitly converted to a type T
415 // [...] if the declaration "T t(e);" is well-formed, [...].
Sebastian Redl37d6de32008-11-08 13:00:26 +0000416 if (TryStaticImplicitCast(Self, SrcExpr, DestType, OpRange) >
417 TSC_NotApplicable) {
Sebastian Redl26d85b12008-11-05 21:50:06 +0000418 return;
419 }
420
421 // C++ 5.2.9p6: May apply the reverse of any standard conversion, except
422 // lvalue-to-rvalue, array-to-pointer, function-to-pointer, and boolean
423 // conversions, subject to further restrictions.
424 // Also, C++ 5.2.9p1 forbids casting away constness, which makes reversal
425 // of qualification conversions impossible.
426
427 // The lvalue-to-rvalue, array-to-pointer and function-to-pointer conversions
428 // are applied to the expression.
429 QualType OrigSrcType = SrcExpr->getType();
Sebastian Redl37d6de32008-11-08 13:00:26 +0000430 Self.DefaultFunctionArrayConversion(SrcExpr);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000431
Sebastian Redl37d6de32008-11-08 13:00:26 +0000432 QualType SrcType = Self.Context.getCanonicalType(SrcExpr->getType());
Sebastian Redl26d85b12008-11-05 21:50:06 +0000433
434 // Reverse integral promotion/conversion. All such conversions are themselves
435 // again integral promotions or conversions and are thus already handled by
436 // p2 (TryDirectInitialization above).
437 // (Note: any data loss warnings should be suppressed.)
438 // The exception is the reverse of enum->integer, i.e. integer->enum (and
439 // enum->enum). See also C++ 5.2.9p7.
440 // The same goes for reverse floating point promotion/conversion and
441 // floating-integral conversions. Again, only floating->enum is relevant.
442 if (DestType->isEnumeralType()) {
443 if (SrcType->isComplexType() || SrcType->isVectorType()) {
444 // Fall through - these cannot be converted.
445 } else if (SrcType->isArithmeticType() || SrcType->isEnumeralType()) {
446 return;
447 }
448 }
449
450 // Reverse pointer upcast. C++ 4.10p3 specifies pointer upcast.
451 // C++ 5.2.9p8 additionally disallows a cast path through virtual inheritance.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000452 if (TryStaticPointerDowncast(Self, SrcType, DestType, OpRange)
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000453 > TSC_NotApplicable) {
Sebastian Redl26d85b12008-11-05 21:50:06 +0000454 return;
455 }
456
457 // Reverse member pointer conversion. C++ 5.11 specifies member pointer
458 // conversion. C++ 5.2.9p9 has additional information.
459 // DR54's access restrictions apply here also.
460 // FIXME: Don't have member pointers yet.
461
462 // Reverse pointer conversion to void*. C++ 4.10.p2 specifies conversion to
463 // void*. C++ 5.2.9p10 specifies additional restrictions, which really is
464 // just the usual constness stuff.
465 if (const PointerType *SrcPointer = SrcType->getAsPointerType()) {
466 QualType SrcPointee = SrcPointer->getPointeeType();
467 if (SrcPointee->isVoidType()) {
468 if (const PointerType *DestPointer = DestType->getAsPointerType()) {
469 QualType DestPointee = DestPointer->getPointeeType();
470 if (DestPointee->isObjectType()) {
471 // This is definitely the intended conversion, but it might fail due
472 // to a const violation.
473 if (!DestPointee.isAtLeastAsQualifiedAs(SrcPointee)) {
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000474 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_const_away)
Chris Lattnerd1625842008-11-24 06:25:27 +0000475 << "static_cast" << DestType << OrigSrcType << OpRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000476 }
477 return;
478 }
479 }
480 }
481 }
482
483 // We tried everything. Everything! Nothing works! :-(
484 // FIXME: Error reporting could be a lot better. Should store the reason
485 // why every substep failed and, at the end, select the most specific and
486 // report that.
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000487 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic)
Chris Lattnerd1625842008-11-24 06:25:27 +0000488 << "static_cast" << DestType << OrigSrcType
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000489 << OpRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000490}
491
492/// Tests whether a conversion according to C++ 5.2.9p5 is valid.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000493TryStaticCastResult
494TryStaticReferenceDowncast(Sema &Self, Expr *SrcExpr, QualType DestType,
495 const SourceRange &OpRange)
Sebastian Redl26d85b12008-11-05 21:50:06 +0000496{
497 // C++ 5.2.9p5: An lvalue of type "cv1 B", where B is a class type, can be
498 // cast to type "reference to cv2 D", where D is a class derived from B,
499 // if a valid standard conversion from "pointer to D" to "pointer to B"
500 // exists, cv2 >= cv1, and B is not a virtual base class of D.
501 // In addition, DR54 clarifies that the base must be accessible in the
502 // current context. Although the wording of DR54 only applies to the pointer
503 // variant of this rule, the intent is clearly for it to apply to the this
504 // conversion as well.
505
Sebastian Redl37d6de32008-11-08 13:00:26 +0000506 if (SrcExpr->isLvalue(Self.Context) != Expr::LV_Valid) {
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000507 return TSC_NotApplicable;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000508 }
509
510 const ReferenceType *DestReference = DestType->getAsReferenceType();
511 if (!DestReference) {
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000512 return TSC_NotApplicable;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000513 }
514 QualType DestPointee = DestReference->getPointeeType();
515
Sebastian Redl37d6de32008-11-08 13:00:26 +0000516 return TryStaticDowncast(Self, SrcExpr->getType(), DestPointee, OpRange,
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000517 SrcExpr->getType(), DestType);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000518}
519
520/// Tests whether a conversion according to C++ 5.2.9p8 is valid.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000521TryStaticCastResult
522TryStaticPointerDowncast(Sema &Self, QualType SrcType, QualType DestType,
523 const SourceRange &OpRange)
Sebastian Redl26d85b12008-11-05 21:50:06 +0000524{
525 // C++ 5.2.9p8: An rvalue of type "pointer to cv1 B", where B is a class
526 // type, can be converted to an rvalue of type "pointer to cv2 D", where D
527 // is a class derived from B, if a valid standard conversion from "pointer
528 // to D" to "pointer to B" exists, cv2 >= cv1, and B is not a virtual base
529 // class of D.
530 // In addition, DR54 clarifies that the base must be accessible in the
531 // current context.
532
533 const PointerType *SrcPointer = SrcType->getAsPointerType();
534 if (!SrcPointer) {
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000535 return TSC_NotApplicable;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000536 }
537
538 const PointerType *DestPointer = DestType->getAsPointerType();
539 if (!DestPointer) {
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000540 return TSC_NotApplicable;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000541 }
542
Sebastian Redl37d6de32008-11-08 13:00:26 +0000543 return TryStaticDowncast(Self, SrcPointer->getPointeeType(),
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000544 DestPointer->getPointeeType(),
545 OpRange, SrcType, DestType);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000546}
547
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000548/// TryStaticDowncast - Common functionality of TryStaticReferenceDowncast and
549/// TryStaticPointerDowncast. Tests whether a static downcast from SrcType to
Sebastian Redl26d85b12008-11-05 21:50:06 +0000550/// DestType, both of which must be canonical, is possible and allowed.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000551TryStaticCastResult
552TryStaticDowncast(Sema &Self, QualType SrcType, QualType DestType,
553 const SourceRange &OpRange, QualType OrigSrcType,
554 QualType OrigDestType)
Sebastian Redl26d85b12008-11-05 21:50:06 +0000555{
556 // Downcast can only happen in class hierarchies, so we need classes.
557 if (!DestType->isRecordType() || !SrcType->isRecordType()) {
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000558 return TSC_NotApplicable;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000559 }
560
561 BasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/false,
562 /*DetectVirtual=*/true);
Sebastian Redl37d6de32008-11-08 13:00:26 +0000563 if (!Self.IsDerivedFrom(DestType, SrcType, Paths)) {
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000564 return TSC_NotApplicable;
565 }
566
567 // Target type does derive from source type. Now we're serious. If an error
568 // appears now, it's not ignored.
569 // This may not be entirely in line with the standard. Take for example:
570 // struct A {};
571 // struct B : virtual A {
572 // B(A&);
573 // };
574 //
575 // void f()
576 // {
577 // (void)static_cast<const B&>(*((A*)0));
578 // }
579 // As far as the standard is concerned, p5 does not apply (A is virtual), so
580 // p2 should be used instead - "const B& t(*((A*)0));" is perfectly valid.
581 // However, both GCC and Comeau reject this example, and accepting it would
582 // mean more complex code if we're to preserve the nice error message.
583 // FIXME: Being 100% compliant here would be nice to have.
584
585 // Must preserve cv, as always.
586 if (!DestType.isAtLeastAsQualifiedAs(SrcType)) {
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000587 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_const_away)
Chris Lattnerd1625842008-11-24 06:25:27 +0000588 << "static_cast" << OrigDestType << OrigSrcType << OpRange;
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000589 return TSC_Failed;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000590 }
591
592 if (Paths.isAmbiguous(SrcType.getUnqualifiedType())) {
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000593 // This code is analoguous to that in CheckDerivedToBaseConversion, except
594 // that it builds the paths in reverse order.
595 // To sum up: record all paths to the base and build a nice string from
596 // them. Use it to spice up the error message.
597 Paths.clear();
598 Paths.setRecordingPaths(true);
Sebastian Redl37d6de32008-11-08 13:00:26 +0000599 Self.IsDerivedFrom(DestType, SrcType, Paths);
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000600 std::string PathDisplayStr;
601 std::set<unsigned> DisplayedPaths;
602 for (BasePaths::paths_iterator Path = Paths.begin();
603 Path != Paths.end(); ++Path) {
604 if (DisplayedPaths.insert(Path->back().SubobjectNumber).second) {
605 // We haven't displayed a path to this particular base
606 // class subobject yet.
607 PathDisplayStr += "\n ";
608 for (BasePath::const_reverse_iterator Element = Path->rbegin();
609 Element != Path->rend(); ++Element)
610 PathDisplayStr += Element->Base->getType().getAsString() + " -> ";
611 PathDisplayStr += DestType.getAsString();
612 }
613 }
614
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000615 Self.Diag(OpRange.getBegin(), diag::err_ambiguous_base_to_derived_cast)
Chris Lattnerd1625842008-11-24 06:25:27 +0000616 << SrcType.getUnqualifiedType() << DestType.getUnqualifiedType()
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000617 << PathDisplayStr << OpRange;
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000618 return TSC_Failed;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000619 }
620
621 if (Paths.getDetectedVirtual() != 0) {
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000622 QualType VirtualBase(Paths.getDetectedVirtual(), 0);
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000623 Self.Diag(OpRange.getBegin(), diag::err_static_downcast_via_virtual)
Chris Lattnerd1625842008-11-24 06:25:27 +0000624 << OrigSrcType << OrigDestType << VirtualBase << OpRange;
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000625 return TSC_Failed;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000626 }
627
628 // FIXME: Test accessibility.
629
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000630 return TSC_Success;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000631}
632
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000633/// TryStaticImplicitCast - Tests whether a conversion according to C++ 5.2.9p2
634/// is valid:
635///
636/// An expression e can be explicitly converted to a type T using a
637/// @c static_cast if the declaration "T t(e);" is well-formed [...].
Sebastian Redl37d6de32008-11-08 13:00:26 +0000638TryStaticCastResult
639TryStaticImplicitCast(Sema &Self, Expr *SrcExpr, QualType DestType,
640 const SourceRange &OpRange)
Sebastian Redl26d85b12008-11-05 21:50:06 +0000641{
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000642 if (DestType->isReferenceType()) {
643 // At this point of CheckStaticCast, if the destination is a reference,
644 // this has to work. There is no other way that works.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000645 return Self.CheckReferenceInit(SrcExpr, DestType) ?
646 TSC_Failed : TSC_Success;
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000647 }
648 if (DestType->isRecordType()) {
649 // FIXME: Use an implementation of C++ [over.match.ctor] for this.
650 return TSC_NotApplicable;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000651 }
652
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000653 // FIXME: To get a proper error from invalid conversions here, we need to
654 // reimplement more of this.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000655 ImplicitConversionSequence ICS = Self.TryImplicitConversion(
656 SrcExpr, DestType);
Sebastian Redle3dc28a2008-11-07 23:29:29 +0000657 return ICS.ConversionKind == ImplicitConversionSequence::BadConversion ?
658 TSC_NotApplicable : TSC_Success;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000659}
660
661/// CheckDynamicCast - Check that a dynamic_cast\<DestType\>(SrcExpr) is valid.
662/// Refer to C++ 5.2.7 for details. Dynamic casts are used mostly for runtime-
663/// checked downcasts in class hierarchies.
664void
Sebastian Redl37d6de32008-11-08 13:00:26 +0000665CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
666 const SourceRange &OpRange,
667 const SourceRange &DestRange)
Sebastian Redl26d85b12008-11-05 21:50:06 +0000668{
669 QualType OrigDestType = DestType, OrigSrcType = SrcExpr->getType();
Sebastian Redl37d6de32008-11-08 13:00:26 +0000670 DestType = Self.Context.getCanonicalType(DestType);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000671
672 // C++ 5.2.7p1: T shall be a pointer or reference to a complete class type,
673 // or "pointer to cv void".
674
675 QualType DestPointee;
676 const PointerType *DestPointer = DestType->getAsPointerType();
677 const ReferenceType *DestReference = DestType->getAsReferenceType();
678 if (DestPointer) {
679 DestPointee = DestPointer->getPointeeType();
680 } else if (DestReference) {
681 DestPointee = DestReference->getPointeeType();
682 } else {
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000683 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ref_or_ptr)
Chris Lattnerd1625842008-11-24 06:25:27 +0000684 << OrigDestType << DestRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000685 return;
686 }
687
688 const RecordType *DestRecord = DestPointee->getAsRecordType();
689 if (DestPointee->isVoidType()) {
690 assert(DestPointer && "Reference to void is not possible");
691 } else if (DestRecord) {
Douglas Gregor4ec339f2009-01-19 19:26:10 +0000692 if (Self.DiagnoseIncompleteType(OpRange.getBegin(), DestPointee,
693 diag::err_bad_dynamic_cast_incomplete,
694 DestRange))
Sebastian Redl26d85b12008-11-05 21:50:06 +0000695 return;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000696 } else {
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000697 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class)
Chris Lattnerd1625842008-11-24 06:25:27 +0000698 << DestPointee.getUnqualifiedType() << DestRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000699 return;
700 }
701
702 // C++ 5.2.7p2: If T is a pointer type, v shall be an rvalue of a pointer to
703 // complete class type, [...]. If T is a reference type, v shall be an
704 // lvalue of a complete class type, [...].
705
Sebastian Redl37d6de32008-11-08 13:00:26 +0000706 QualType SrcType = Self.Context.getCanonicalType(OrigSrcType);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000707 QualType SrcPointee;
708 if (DestPointer) {
709 if (const PointerType *SrcPointer = SrcType->getAsPointerType()) {
710 SrcPointee = SrcPointer->getPointeeType();
711 } else {
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000712 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ptr)
Chris Lattnerd1625842008-11-24 06:25:27 +0000713 << OrigSrcType << SrcExpr->getSourceRange();
Sebastian Redl26d85b12008-11-05 21:50:06 +0000714 return;
715 }
716 } else {
Sebastian Redl37d6de32008-11-08 13:00:26 +0000717 if (SrcExpr->isLvalue(Self.Context) != Expr::LV_Valid) {
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000718 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_rvalue)
Chris Lattnerd1625842008-11-24 06:25:27 +0000719 << "dynamic_cast" << OrigDestType << OpRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000720 }
721 SrcPointee = SrcType;
722 }
723
724 const RecordType *SrcRecord = SrcPointee->getAsRecordType();
725 if (SrcRecord) {
Douglas Gregor4ec339f2009-01-19 19:26:10 +0000726 if (Self.DiagnoseIncompleteType(OpRange.getBegin(), SrcPointee,
727 diag::err_bad_dynamic_cast_incomplete,
728 SrcExpr->getSourceRange()))
Sebastian Redl26d85b12008-11-05 21:50:06 +0000729 return;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000730 } else {
Chris Lattnerd3a94e22008-11-20 06:06:08 +0000731 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class)
Chris Lattnerd1625842008-11-24 06:25:27 +0000732 << SrcPointee.getUnqualifiedType() << SrcExpr->getSourceRange();
Sebastian Redl26d85b12008-11-05 21:50:06 +0000733 return;
734 }
735
736 assert((DestPointer || DestReference) &&
737 "Bad destination non-ptr/ref slipped through.");
738 assert((DestRecord || DestPointee->isVoidType()) &&
739 "Bad destination pointee slipped through.");
740 assert(SrcRecord && "Bad source pointee slipped through.");
741
742 // C++ 5.2.7p1: The dynamic_cast operator shall not cast away constness.
743 if (!DestPointee.isAtLeastAsQualifiedAs(SrcPointee)) {
Chris Lattnerc9c7c4e2008-11-18 22:52:51 +0000744 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_const_away)
Chris Lattnerd1625842008-11-24 06:25:27 +0000745 << "dynamic_cast" << OrigDestType << OrigSrcType << OpRange;
Sebastian Redl26d85b12008-11-05 21:50:06 +0000746 return;
747 }
748
749 // C++ 5.2.7p3: If the type of v is the same as the required result type,
750 // [except for cv].
751 if (DestRecord == SrcRecord) {
752 return;
753 }
754
755 // C++ 5.2.7p5
756 // Upcasts are resolved statically.
Sebastian Redl37d6de32008-11-08 13:00:26 +0000757 if (DestRecord && Self.IsDerivedFrom(SrcPointee, DestPointee)) {
758 Self.CheckDerivedToBaseConversion(SrcPointee, DestPointee,
Chris Lattnerd1625842008-11-24 06:25:27 +0000759 OpRange.getBegin(), OpRange);
Sebastian Redl26d85b12008-11-05 21:50:06 +0000760 // Diagnostic already emitted on error.
761 return;
762 }
763
764 // C++ 5.2.7p6: Otherwise, v shall be [polymorphic].
Sebastian Redl37d6de32008-11-08 13:00:26 +0000765 const RecordDecl *SrcDecl = SrcRecord->getDecl()->getDefinition(Self.Context);
Sebastian Redld93f0dd2008-11-06 15:59:35 +0000766 assert(SrcDecl && "Definition missing");
767 if (!cast<CXXRecordDecl>(SrcDecl)->isPolymorphic()) {
Chris Lattnerd3a94e22008-11-20 06:06:08 +0000768 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_polymorphic)
Chris Lattnerd1625842008-11-24 06:25:27 +0000769 << SrcPointee.getUnqualifiedType() << SrcExpr->getSourceRange();
Sebastian Redld93f0dd2008-11-06 15:59:35 +0000770 }
Sebastian Redl26d85b12008-11-05 21:50:06 +0000771
772 // Done. Everything else is run-time checks.
773}