1 /* Test the -Wnonportable-cfstrings option, which should give
2 warnings if non-ASCII characters are embedded in constant
3 CFStrings. This will only work on MacOS X 10.2 and later. */
4 /* Developed by Ziemowit Laski <zlaski@apple.com>. */
6 /* So far, CFString is darwin-only. */
7 /* { dg-do compile { target *-*-darwin* } } */
8 /* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
9 /* { dg-options "-ftrack-macro-expansion=0 -mconstant-cfstrings -Wnonportable-cfstrings" } */
11 #import <Foundation/NSString.h>
12 #import <CoreFoundation/CFString.h>
14 #ifndef __CONSTANT_CFSTRINGS__
15 #error The -fconstant-cfstrings option is not functioning properly
19 NSString *s1 = @"Compile-time string literal";
20 CFStringRef s2 = CFSTR("Compile-time string literal");
21 NSString *s3 = @"Non-ASCII literal - \222"; /* { dg-warning "non-ASCII character in CFString literal" } */
22 CFStringRef s4 = CFSTR("\222 - Non-ASCII literal"); /* { dg-warning "non-ASCII character in CFString literal" } */
23 CFStringRef s5 = CFSTR("Non-ASCII (\222) literal"); /* { dg-warning "non-ASCII character in CFString literal" } */
24 NSString *s6 = @"\0Embedded NUL"; /* { dg-warning "embedded NUL in CFString literal" } */
25 CFStringRef s7 = CFSTR("Embedded \0NUL"); /* { dg-warning "embedded NUL in CFString literal" } */
26 CFStringRef s8 = CFSTR("Embedded NUL\0"); /* { dg-warning "embedded NUL in CFString literal" } */