annotate gcc/testsuite/gcc.dg/format/attr-3.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Test for format attributes: test bad uses of __attribute__. */
kono
parents:
diff changeset
2 /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
kono
parents:
diff changeset
3 /* { dg-do compile } */
kono
parents:
diff changeset
4 /* { dg-options "-std=gnu99 -Wformat" } */
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 #define DONT_GNU_PROTOTYPE
kono
parents:
diff changeset
7 #include "format.h"
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 /* Proper uses of the attributes. */
kono
parents:
diff changeset
10 extern void fa0 (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 2)));
kono
parents:
diff changeset
11 extern void fa1 (char *, ...) __attribute__((format(gnu_attr_printf, 1, 2)));
kono
parents:
diff changeset
12 extern char *fa2 (const char *) __attribute__((format_arg(1)));
kono
parents:
diff changeset
13 extern char *fa3 (char *) __attribute__((format_arg(1)));
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 /* Uses with too few or too many arguments. */
kono
parents:
diff changeset
16 extern void fb0 (const char *, ...) __attribute__((format)); /* { dg-error "wrong number of arguments" "bad format" } */
kono
parents:
diff changeset
17 extern void fb1 (const char *, ...) __attribute__((format())); /* { dg-error "wrong number of arguments" "bad format" } */
kono
parents:
diff changeset
18 extern void fb2 (const char *, ...) __attribute__((format(gnu_attr_printf))); /* { dg-error "wrong number of arguments" "bad format" } */
kono
parents:
diff changeset
19 extern void fb3 (const char *, ...) __attribute__((format(gnu_attr_printf, 1))); /* { dg-error "wrong number of arguments" "bad format" } */
kono
parents:
diff changeset
20 extern void fb4 (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 2, 3))); /* { dg-error "wrong number of arguments" "bad format" } */
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 extern void fc1 (const char *) __attribute__((format_arg)); /* { dg-error "wrong number of arguments" "bad format_arg" } */
kono
parents:
diff changeset
23 extern void fc2 (const char *) __attribute__((format_arg())); /* { dg-error "wrong number of arguments" "bad format_arg" } */
kono
parents:
diff changeset
24 extern void fc3 (const char *) __attribute__((format_arg(1, 2))); /* { dg-error "wrong number of arguments" "bad format_arg" } */
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 /* These attributes presently only apply to declarations, not to types.
kono
parents:
diff changeset
27 Eventually, they should be usable with declarators for function types
kono
parents:
diff changeset
28 anywhere, but still not with structure/union/enum types. */
kono
parents:
diff changeset
29 struct s0 { int i; } __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on struct" } */
kono
parents:
diff changeset
30 union u0 { int i; } __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on union" } */
kono
parents:
diff changeset
31 enum e0 { E0V0 } __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on enum" } */
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 struct s1 { int i; } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on struct" } */
kono
parents:
diff changeset
34 union u1 { int i; } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on union" } */
kono
parents:
diff changeset
35 enum e1 { E1V0 } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on enum" } */
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 /* The format type must be an identifier, one of those recognized. */
kono
parents:
diff changeset
38 extern void fe0 (const char *, ...) __attribute__((format(12345, 1, 2))); /* { dg-error "format specifier" "non-id format" } */
kono
parents:
diff changeset
39 extern void fe1 (const char *, ...) __attribute__((format(nosuch, 1, 2))); /* { dg-warning "format function type" "unknown format" } */
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 /* Both the numbers must be integer constant expressions. */
kono
parents:
diff changeset
42 extern void ff0 (const char *, ...) __attribute__((format(gnu_attr_printf, 3-2, (long long)(10/5))));
kono
parents:
diff changeset
43 int foo;
kono
parents:
diff changeset
44 extern void ff1 (const char *, ...) __attribute__((format(gnu_attr_printf, foo, 10/5))); /* { dg-error "invalid operand" "bad number" } */
kono
parents:
diff changeset
45 extern void ff2 (const char *, ...) __attribute__((format(gnu_attr_printf, 3-2, foo))); /* { dg-error "invalid operand" "bad number" } */
kono
parents:
diff changeset
46 extern char *ff3 (const char *) __attribute__((format_arg(3-2)));
kono
parents:
diff changeset
47 extern char *ff4 (const char *) __attribute__((format_arg(foo))); /* { dg-error "invalid operand" "bad format_arg number" } */
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 /* The format string argument must precede the arguments to be formatted.
kono
parents:
diff changeset
50 This includes if no parameter types are specified (which is not valid ISO
kono
parents:
diff changeset
51 C for variadic functions). */
kono
parents:
diff changeset
52 extern void fg0 () __attribute__((format(gnu_attr_printf, 1, 2)));
kono
parents:
diff changeset
53 extern void fg1 () __attribute__((format(gnu_attr_printf, 1, 0)));
kono
parents:
diff changeset
54 extern void fg2 () __attribute__((format(gnu_attr_printf, 1, 1))); /* { dg-error "follows" "bad number order" } */
kono
parents:
diff changeset
55 extern void fg3 () __attribute__((format(gnu_attr_printf, 2, 1))); /* { dg-error "follows" "bad number order" } */
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 /* The format string argument must be a string type, and the arguments to
kono
parents:
diff changeset
58 be formatted must be the "...". */
kono
parents:
diff changeset
59 extern void fh0 (int, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "not a string" "format int string" } */
kono
parents:
diff changeset
60 extern void fh1 (signed char *, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "not a string" "signed char string" } */
kono
parents:
diff changeset
61 extern void fh2 (unsigned char *, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "not a string" "unsigned char string" } */
kono
parents:
diff changeset
62 extern void fh3 (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 3))); /* { dg-error "is not" "not ..." } */
kono
parents:
diff changeset
63 extern void fh4 (const char *, int, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "is not" "not ..." } */
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 /* format_arg formats must take and return a string. */
kono
parents:
diff changeset
66 extern char *fi0 (int) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg int string" } */
kono
parents:
diff changeset
67 extern char *fi1 (signed char *) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg signed char string" } */
kono
parents:
diff changeset
68 extern char *fi2 (unsigned char *) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg unsigned char string" } */
kono
parents:
diff changeset
69 extern int fi3 (const char *) __attribute__((format_arg(1))); /* { dg-error "not return string" "format_arg ret int string" } */
kono
parents:
diff changeset
70 extern signed char *fi4 (const char *) __attribute__((format_arg(1))); /* { dg-error "not return string" "format_arg ret signed char string" } */
kono
parents:
diff changeset
71 extern unsigned char *fi5 (const char *) __attribute__((format_arg(1))); /* { dg-error "not return string" "format_arg ret unsigned char string" } */