Skip to content

Commit

Permalink
[Sema][ObjC] Disable -Wunused-parameter for ObjC methods
Browse files Browse the repository at this point in the history
The warning isn't very useful when the function is an ObjC method.

rdar://problem/41561853

Differential Revision: https://reviews.llvm.org/D61147

llvm-svn: 359864
  • Loading branch information
ahatanaka committed May 3, 2019
1 parent d724360 commit 8cd01e6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 0 additions & 2 deletions clang/lib/Sema/SemaDecl.cpp
Expand Up @@ -13353,8 +13353,6 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
assert(MD == getCurMethodDecl() && "Method parsing confused");
MD->setBody(Body);
if (!MD->isInvalidDecl()) {
if (!MD->hasSkippedBody())
DiagnoseUnusedParameters(MD->parameters());
DiagnoseSizeOfParametersAndReturnValue(MD->parameters(),
MD->getReturnType(), MD);

Expand Down
8 changes: 6 additions & 2 deletions clang/test/SemaObjC/method-unused-attribute.m
@@ -1,5 +1,9 @@
// RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -verify -Wno-objc-root-class %s

// -Wunused-parameter ignores ObjC method parameters that are unused.

// expected-no-diagnostics

@interface INTF
- (void) correct_use_of_unused: (void *) notice : (id)another_arg;
- (void) will_warn_unused_arg: (void *) notice : (id)warn_unused;
Expand All @@ -9,7 +13,7 @@ - (void) unused_attr_on_decl_ignored: (void *) __attribute__((unused)) will_war
@implementation INTF
- (void) correct_use_of_unused: (void *) __attribute__((unused)) notice : (id) __attribute__((unused)) newarg{
}
- (void) will_warn_unused_arg: (void *) __attribute__((unused)) notice : (id)warn_unused {} // expected-warning {{unused parameter 'warn_unused'}}
- (void) unused_attr_on_decl_ignored: (void *) will_warn{} // expected-warning {{unused parameter 'will_warn'}}
- (void) will_warn_unused_arg: (void *) __attribute__((unused)) notice : (id)warn_unused {}
- (void) unused_attr_on_decl_ignored: (void *) will_warn{}
@end

2 changes: 1 addition & 1 deletion clang/test/SemaObjC/unused.m
Expand Up @@ -33,7 +33,7 @@ - (int) meth: (int)x: // expected-warning {{'x' used as the name of the previous
// expected-note {{introduce a parameter name to make 'x' part of the selector}} \
// expected-note {{or insert whitespace before ':' to use 'x' as parameter name and have an empty entry in the selector}}

(int)y: // expected-warning {{unused}} expected-warning {{'y' used as the name of the previous parameter rather than as part of the selector}} \
(int)y: // expected-warning {{'y' used as the name of the previous parameter rather than as part of the selector}} \
// expected-note {{introduce a parameter name to make 'y' part of the selector}} \
// expected-note {{or insert whitespace before ':' to use 'y' as parameter name and have an empty entry in the selector}}
(int) __attribute__((unused))z { return x; }
Expand Down

0 comments on commit 8cd01e6

Please sign in to comment.