summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2017-08-25 16:12:17 +0000
committerAlex Lorenz <arphaman@gmail.com>2017-08-25 16:12:17 +0000
commitd9f1284009d506406ab2e81d6f04cb23a2205282 (patch)
tree169e34bb3cb91a7a1a3bd0ab8c6bf173e5ec4956 /clang
parentd0e27266d886dbd206202189a1113a98b141d458 (diff)
downloadbcm5719-llvm-d9f1284009d506406ab2e81d6f04cb23a2205282.tar.gz
bcm5719-llvm-d9f1284009d506406ab2e81d6f04cb23a2205282.zip
[ObjC] Add a -Wobjc-messaging-id warning
-Wobjc-messaging-id is a new, non-default warning that warns about message sends to unqualified id in Objective-C. This warning is useful for projects that would like to avoid any potential future compiler errors/warnings, as the system frameworks might add a method with the same selector which could make the message send to id ambiguous. rdar://33303354 llvm-svn: 311779
Diffstat (limited to 'clang')
-rw-r--r--clang/docs/ReleaseNotes.rst6
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td4
-rw-r--r--clang/lib/Sema/SemaExprObjC.cpp3
-rw-r--r--clang/test/SemaObjC/warn-messaging-id.mm21
4 files changed, 34 insertions, 0 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index be038234df7..45bf166068a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -66,6 +66,12 @@ Improvements to Clang's diagnostics
a non-default alignment that has been specified using a ``#pragma pack``
directive prior to the ``#include``.
+- ``-Wobjc-messaging-id`` is a new, non-default warning that warns about
+ message sends to unqualified ``id`` in Objective-C. This warning is useful
+ for projects that would like to avoid any potential future compiler
+ errors/warnings, as the system frameworks might add a method with the same
+ selector which could make the message send to ``id`` ambiguous.
+
Non-comprehensive list of changes in this release
-------------------------------------------------
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 37066b46786..04576b60a0e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1211,6 +1211,10 @@ def err_objc_method_unsupported_param_ret_type : Error<
"%0 %select{parameter|return}1 type is unsupported; "
"support for vector types for this target is introduced in %2">;
+def warn_messaging_unqualified_id : Warning<
+ "messaging unqualified id">, DefaultIgnore,
+ InGroup<DiagGroup<"objc-messaging-id">>;
+
// C++ declarations
def err_static_assert_expression_is_not_constant : Error<
"static_assert expression is not an integral constant expression">;
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 28581bad1a7..83ef799392a 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -2705,6 +2705,9 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
}
}
+ if (ReceiverType->isObjCIdType() && !isImplicit)
+ Diag(Receiver->getExprLoc(), diag::warn_messaging_unqualified_id);
+
// There's a somewhat weird interaction here where we assume that we
// won't actually have a method unless we also don't need to do some
// of the more detailed type-checking on the receiver.
diff --git a/clang/test/SemaObjC/warn-messaging-id.mm b/clang/test/SemaObjC/warn-messaging-id.mm
new file mode 100644
index 00000000000..8112cfa3d52
--- /dev/null
+++ b/clang/test/SemaObjC/warn-messaging-id.mm
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class -Wobjc-messaging-id %s
+
+@interface CallMeMaybe
+
+- (void)doThing:(int)intThing;
+
+@property int thing;
+
+@end
+
+template<typename T>
+void instantiate(const T &x) {
+ [x setThing: 22]; // expected-warning {{messaging unqualified id}}
+}
+
+void fn() {
+ id myObject;
+ [myObject doThing: 10]; // expected-warning {{messaging unqualified id}}
+ [myObject setThing: 11]; // expected-warning {{messaging unqualified id}}
+ instantiate(myObject); // expected-note {{in instantiation}}
+}
OpenPOWER on IntegriCloud