diff options
author | Douglas Gregor <dgregor@apple.com> | 2008-12-19 17:40:08 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2008-12-19 17:40:08 +0000 |
commit | 47d3f2742a3b69e1231aa09d0daf9eed3d8163c9 (patch) | |
tree | ad803fe30ac0aeb021276735427d90071c1fcda5 /clang/lib/Sema/SemaExprCXX.cpp | |
parent | 324de7ba46c961e5cce879f30f9be57a040c6a3e (diff) | |
download | bcm5719-llvm-47d3f2742a3b69e1231aa09d0daf9eed3d8163c9.tar.gz bcm5719-llvm-47d3f2742a3b69e1231aa09d0daf9eed3d8163c9.zip |
Allow downcasts of pointers to Objective-C interfaces, with a
warning. This matches GCC's behavior and addresses
<rdar://problem/6458293>.
llvm-svn: 61246
Diffstat (limited to 'clang/lib/Sema/SemaExprCXX.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index e951016361a..e18f1437ab6 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -708,14 +708,16 @@ Sema::IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType) { /// PerformImplicitConversion - Perform an implicit conversion of the /// expression From to the type ToType. Returns true if there was an /// error, false otherwise. The expression From is replaced with the -/// converted expression. +/// converted expression. Flavor is the kind of conversion we're +/// performing, used in the error message. bool -Sema::PerformImplicitConversion(Expr *&From, QualType ToType) +Sema::PerformImplicitConversion(Expr *&From, QualType ToType, + const char *Flavor) { ImplicitConversionSequence ICS = TryImplicitConversion(From, ToType); switch (ICS.ConversionKind) { case ImplicitConversionSequence::StandardConversion: - if (PerformImplicitConversion(From, ToType, ICS.Standard)) + if (PerformImplicitConversion(From, ToType, ICS.Standard, Flavor)) return true; break; @@ -742,10 +744,12 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType) /// expression From to the type ToType by following the standard /// conversion sequence SCS. Returns true if there was an error, false /// otherwise. The expression From is replaced with the converted -/// expression. +/// expression. Flavor is the context in which we're performing this +/// conversion, for use in error messages. bool Sema::PerformImplicitConversion(Expr *&From, QualType ToType, - const StandardConversionSequence& SCS) + const StandardConversionSequence& SCS, + const char *Flavor) { // Overall FIXME: we are recomputing too many types here and doing // far too much extra work. What this means is that we need to keep @@ -808,6 +812,14 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, break; case ICK_Pointer_Conversion: + if (SCS.IncompatibleObjC) { + // Diagnose incompatible Objective-C conversions + Diag(From->getSourceRange().getBegin(), + diag::ext_typecheck_convert_incompatible_pointer) + << From->getType() << ToType << Flavor + << From->getSourceRange(); + } + if (CheckPointerConversion(From, ToType)) return true; ImpCastExprToType(From, ToType); |