]> granicus.if.org Git - clang/commit
Implement Objective-C Related Result Type semantics.
authorDouglas Gregor <dgregor@apple.com>
Sat, 11 Jun 2011 01:09:30 +0000 (01:09 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 11 Jun 2011 01:09:30 +0000 (01:09 +0000)
commit926df6cfabf3eaa4afc990c097fa4619b76a9b57
treef48a5ca74fa783c76ae30e190d130881fc5febe8
parent45937ae10a0f70f74508165aab4f2b63e18ea747
Implement Objective-C Related Result Type semantics.

Related result types apply Cocoa conventions to the type of message
sends and property accesses to Objective-C methods that are known to
always return objects whose type is the same as the type of the
receiving class (or a subclass thereof), such as +alloc and
-init. This tightens up static type safety for Objective-C, so that we
now diagnose mistakes like this:

t.m:4:10: warning: incompatible pointer types initializing 'NSSet *'
with an
      expression of type 'NSArray *' [-Wincompatible-pointer-types]
  NSSet *array = [[NSArray alloc] init];
         ^       ~~~~~~~~~~~~~~~~~~~~~~
/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:72:1:
note:
      instance method 'init' is assumed to return an instance of its
      receiver
      type ('NSArray *')
- (id)init;
^

It also means that we get decent type inference when writing code in
Objective-C++0x:

  auto array = [[NSMutableArray alloc] initWithObjects:@"one",  @"two",nil];
  //    ^ now infers NSMutableArray* rather than id

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132868 91177308-0d34-0410-b5e6-96231b3b80d8
33 files changed:
docs/LanguageExtensions.html
include/clang/AST/DeclObjC.h
include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Basic/IdentifierTable.h
include/clang/Basic/LangOptions.h
include/clang/Driver/CC1Options.td
include/clang/Driver/Options.td
include/clang/Sema/Sema.h
lib/AST/ASTImporter.cpp
lib/AST/DeclObjC.cpp
lib/AST/DumpXML.cpp
lib/Analysis/CocoaConventions.cpp
lib/Basic/IdentifierTable.cpp
lib/CodeGen/CGObjC.cpp
lib/Driver/Tools.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Parse/ParseObjc.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaExprCXX.cpp
lib/Sema/SemaExprObjC.cpp
lib/Sema/SemaInit.cpp
lib/Sema/SemaStmt.cpp
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriter.cpp
lib/Serialization/ASTWriterDecl.cpp
test/Driver/rewrite-objc.m
test/PCH/objc_methods.h
test/PCH/objc_methods.m
test/SemaObjC/related-result-type-inference.m [new file with mode: 0644]
test/SemaObjCXX/related-result-type-inference.mm [new file with mode: 0644]