[Foundation] Regression from rdar://23622446: passing format string for 'val' param in NSLocalizedStringWithDefaultValue() raises warning with upstream clang

Number:rdar://38143508 Date Originated:2018-03-05
Status: Resolved:
Product:Foundation Product Version:
Classification: Reproducible:Always


Passing a format string for the 'val' parameter to NSLocalizedStringWithDefaultValue() should work:

NSString *value = [NSString stringWithFormat:
  NSLocalizedStringWithDefaultValue(@"key", @"table", NSBundle.mainBundle, @"%d", @"comment"),

However, after the fix for rdar://23622446 , this no longer compiles with clang as of upstream revision https://reviews.llvm.org/D25820 / r284961 — it raises the warning -Wformat-extra-args:

error: data argument not used by format string [-Werror,-Wformat-extra-args]

Steps to Reproduce:

1) Install clang
1a) Either build from upstream: https://clang.llvm.org/get_started.html
1b) Or install from Homebrew: brew install --with-toolchain llvm

2) Download the attached file rd2362246_regression.m
3) Compile with the following command:

/path/to/clang -fsyntax-only -Werror rd2362246_regression.m && echo OK || echo NOT OK

Expected Results:

OK with both Xcode clang and upstream clang

Actual Results:

Fails to compile with upstream clang:

error: data argument not used by format string [-Werror,-Wformat-extra-args]
1 error generated.

Repro: https://reviews.llvm.org/P8066


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!