xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/format-strings-0x.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -std=c++11 %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc extern "C" {
4*f4a2713aSLionel Sambuc extern int scanf(const char *restrict, ...);
5*f4a2713aSLionel Sambuc extern int printf(const char *restrict, ...);
6*f4a2713aSLionel Sambuc }
7*f4a2713aSLionel Sambuc 
f(char ** sp,float * fp)8*f4a2713aSLionel Sambuc void f(char **sp, float *fp) {
9*f4a2713aSLionel Sambuc   scanf("%as", sp); // expected-warning{{format specifies type 'float *' but the argument has type 'char **'}}
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc   printf("%a", 1.0);
12*f4a2713aSLionel Sambuc   scanf("%afoobar", fp);
13*f4a2713aSLionel Sambuc   printf(nullptr);
14*f4a2713aSLionel Sambuc   printf(*sp); // expected-warning {{not a string literal}}
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc   // PR13099
17*f4a2713aSLionel Sambuc   printf(
18*f4a2713aSLionel Sambuc     R"foobar(%)foobar"
19*f4a2713aSLionel Sambuc     R"bazquux(d)bazquux" // expected-warning {{more '%' conversions than data arguments}}
20*f4a2713aSLionel Sambuc     R"xyzzy()xyzzy");
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc   printf(u8"this is %d test", 0); // ok
23*f4a2713aSLionel Sambuc   printf(u8R"foo(
24*f4a2713aSLionel Sambuc       \u1234\U0010fffe
25*f4a2713aSLionel Sambuc       %d)foo" // expected-warning {{more '%' conversions than data arguments}}
26*f4a2713aSLionel Sambuc   );
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc   printf("init list: %d", { 0 }); // expected-error {{cannot pass initializer list to variadic function; expected type from format string was 'int'}}
29*f4a2713aSLionel Sambuc   printf("void: %d", f(sp, fp)); // expected-error {{cannot pass expression of type 'void' to variadic function; expected type from format string was 'int'}}
30*f4a2713aSLionel Sambuc   printf(0, { 0 }); // expected-error {{cannot pass initializer list to variadic function}}
31*f4a2713aSLionel Sambuc }
32