-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmd.saferPrintf.dd
More file actions
29 lines (22 loc) · 848 Bytes
/
Copy pathdmd.saferPrintf.dd
File metadata and controls
29 lines (22 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Allow certain `pragma(printf)` function calls to be treated as `@safe`
`printf` function calls in general are unsafe. Many calls, however,
can be automatically checked for safety.
This change allows calling a $(DDSUBLINK spec/pragma, printf,
`pragma(printf)`) function from @safe code when:
- the callee is marked `@safe` or `@trusted`
- the format string passed is a literal
- no string format specifiers are used
- the callee has a `...` parameter after the format string
Note: `pragma(printf)` already enforces type safety for a C-style
variadic function.
For example:
```d
extern(C) pragma(printf)
void printf(const char* format, ...) @trusted;
@safe void func(int i, char* s)
{
printf("i is %d\n", i); // allowed
printf("s is %s\n", s); // Error: call is not safe
printf(s); // Error: call is not safe
}
```