7

I am getting "unused parameter 'testString'" warning from following code. But I am using testString to log. So how come it is unused ?

- (void)getString:(NSString *)testString {
          ICELogInfo(@"%@", testString);
}

ICELogInfo is a macro for NSLog.

#define ICELogInfo(fmt, ...) LOG_FORMAT(fmt, @"INFO", ##__VA_ARGS__)
#define LOG_FORMAT(fmt, lvl, ...) LOG_FORMAT_NO_LOCATION(fmt, lvl, ##__VA_ARGS__)
#define LOG_FORMAT_NO_LOCATION(fmt, lvl, ...) NSLog((@"%@ " fmt), lvl, ##__VA_ARGS__)

What I am doing wrong ?

AAV
  • 3,785
  • 8
  • 32
  • 59
  • What does it log when you run it with the warning? – Andrew Jul 09 '13 at 18:54
  • It will log " INFO <--testString-->". Logging part is working fine. I don't have any problem with the output. Just that warning. – AAV Jul 09 '13 at 18:58
  • 1
    Could it be that ICELogInfo is defined as "nothing" in the non-DEBUG case? – Martin R Jul 09 '13 at 21:09
  • 1
    @AmitVyawahare: It could be that the above definition is only used in the `#ifdef DEBUG` case and otherwise ICELogInfo is defined as an empty macro. – Martin R Jul 10 '13 at 16:19

3 Answers3

6

You aren't doing something wrong. This is a common problem when using macros.

As a workaround if you want to get rid of the warning, you can use this code:

- (void)getString:(NSSTring*) __unused testString {
          ICELogInfo(@"%@", testString);
}
gsach
  • 5,715
  • 7
  • 27
  • 42
2

I've run into the same "problem" before. Solved it by using the unused flag as e.g.

- (void)getString:(NSString *)testString {
    ICELogInfo(@"%@", testString);
    #pragma unused (testString)
}
Groot
  • 13,943
  • 6
  • 61
  • 72
1

What version of Xcode are you using? This looks like a lambda capture bug in LLVM from over a year ago now:

[LLVMbugs] [Bug 12153] New: Incorrect warning about unused parameter when using capturing variadic parameter in lambda

as the VA_ARGS in those macros can be expected to work out to the same problem described in that bug report; but it should be resolved in recent Xcodes. Definitely is in Xcode 5 DP 3 that I'm running right now, your code gives me no warnings.

Alex Curylo
  • 4,744
  • 1
  • 27
  • 37