Clang: strict-prototypes warning ignored, so bad code proliferates

Originator:me
Number:rdar://23116994 Date Originated:14-Oct-2015 03:33 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.0.1 (7A1001)
Classification:UI/Usability Reproducible:Always
 
Description:
The -Wstrict-prototypes warning from GCC is not implemented in Clang. In C and Objective-C code, many developers mistakenly use ‘()’ for a function or block parameters expecting it to mean “no arguments” where it actually means “unspecified arguments”. This has been an “obsolescent feature” since C89 and ANSI-C.

This leads to type mis-matches, where a block typed ‘void (^)()’ can be passed as a parameter to ‘void (^)(id obj, float f)’ without warning resulting in issues at runtime (unexpected values, EXC_BAD_ACCESS, etc.). There should be a diagnostic when first creating a variable of a function or block type with unspecified arguments.


Steps to reproduce:
Compile (with -Weverything) and run:

int main(int argc, const char *argv[]) {
    void (^block)() = ^(NSInteger arg) {
        printf(“arg = %ld\n”, arg);
    };
    block(42);
    block(-1);
    return 0;
}


Expected Results:
Warning at line 2 (example using GCC’s language; actual wording should be more effective):
  warning: block declaration isn’t a prototype [-Wstrict-prototypes]


Actual Results:
No warnings are generated; logged output is:
arg = 42
arg = 4294967295


Xcode Version/Build & OS X Version/Build:
Xcode 7.0.1 (7A1001)
OS X 10.10.5 (14F27)


Additional Notes:
See also https://llvm.org/bugs/show_bug.cgi?id=20796

Comments


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!