[PATCH] D67983: [ObjC] Diagnose implicit type coercion from ObjC 'Class' to object pointer types.
James Y Knight via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 24 13:59:04 PDT 2019
jyknight created this revision.
jyknight added a reviewer: rjmccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
For example, in Objective-C mode, the initialization of 'x' in:
@implementation MyType
+ (void)someClassMethod {
MyType *x = self;
}
@end
is correctly diagnosed with an incompatible-pointer-types warning, but
in Objective-C++ mode, it is not diagnosed at all -- even though
incompatible pointer conversions generally become an error in C++.
This patch fixes that oversight, allowing implicit conversions
involving Class only to/from unqualified-id, and between qualified and
unqualified Class, where the protocols are compatible.
Note that this does change some behaviors in Objective-C, as well, as
shown by the modified tests.
Of particular note is that assignment from from 'Class<MyProtocol>' to
'id<MyProtocol>' now warns. (Despite appearances, those are not
compatible types. 'Class<MyProtocol>' is not expected to have instance
methods defined by 'MyProtocol', while 'id<MyProtocol>' is.)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D67983
Files:
clang/lib/AST/ASTContext.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaObjC/comptypes-1.m
clang/test/SemaObjCXX/class-method-self.mm
clang/test/SemaObjCXX/comptypes-1.mm
clang/test/SemaObjCXX/comptypes-7.mm
clang/test/SemaObjCXX/instancetype.mm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67983.221587.patch
Type: text/x-patch
Size: 18611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190924/8e4d14f3/attachment-0001.bin>
More information about the cfe-commits
mailing list