@@ -166,7 +166,49 @@ C++1z Feature Support
166
166
Objective-C Language Changes in Clang
167
167
-------------------------------------
168
168
169
- - ...
169
+ - In both Objective-C and
170
+ Objective-C++, ``-Wcompare-distinct-pointer-types `` will now warn when
171
+ comparing ObjC ``Class `` with an ObjC instance type pointer.
172
+
173
+ .. code-block :: objc
174
+
175
+ Class clz = ...;
176
+ MyType *instance = ...;
177
+ bool eq = (clz == instance); // Previously undiagnosed, now warns.
178
+
179
+ - Objective-C++ now diagnoses conversions between ``Class `` and ObjC
180
+ instance type pointers. Such conversions already emitted an
181
+ on-by-default ``-Wincompatible-pointer-types `` warning in Objective-C
182
+ mode, but had inadvertently been missed entirely in
183
+ Objective-C++. This has been fixed, and they are now diagnosed as
184
+ errors, consistent with the usual C++ treatment for conversions
185
+ between unrelated pointer types.
186
+
187
+ .. code-block :: objc
188
+
189
+ Class clz = ...;
190
+ MyType *instance = ...;
191
+ clz = instance; // Previously undiagnosed, now an error.
192
+ instance = clz; // Previously undiagnosed, now an error.
193
+
194
+ One particular issue you may run into is attempting to use a class
195
+ as a key in a dictionary literal. This will now result in an error,
196
+ because ``Class `` is not convertable to ``id<NSCopying> ``. (Note that
197
+ this was already a warning in Objective-C mode.) While an arbitrary
198
+ ``Class `` object is not guaranteed to implement ``NSCopying ``, the
199
+ default metaclass implementation does. Therefore, the recommended
200
+ solution is to insert an explicit cast to ``id ``, which disables the
201
+ type-checking here.
202
+
203
+ .. code-block :: objc
204
+
205
+ Class cls = ...;
206
+
207
+ // Error: cannot convert from Class to id<NSCoding>.
208
+ NSDictionary * d = @{cls : @"Hello"};
209
+
210
+ // Fix: add an explicit cast to 'id'.
211
+ NSDictionary * d = @{(id)cls : @"Hello"};
170
212
171
213
OpenCL C Language Changes in Clang
172
214
----------------------------------
0 commit comments