1 // RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
2 // RUN: -fsafe-buffer-usage-suggestions \
3 // RUN: -fdiagnostics-parseable-fixits \
4 // RUN: -fsyntax-only %s 2>&1 | FileCheck %s
11 using size_t = __typeof(sizeof(int));
17 void uneval_context_fix_pointer_dereference() {
19 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> p"
20 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
21 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
25 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:15}:""
26 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"[0]"
27 _Generic(*p
, int: 2, float: 3);
28 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:12-[[@LINE-1]]:13}:""
29 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:14-[[@LINE-2]]:14}:"[0]"
32 void uneval_context_fix_pointer_array_access() {
34 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> p"
35 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
36 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
40 _Generic(p
[2], int: 2, float: 3);
43 void uneval_context_fix_pointer_reference() {
45 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> p"
46 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
47 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
51 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:15-[[@LINE-1]]:15}:".data()"
54 // The FixableGagdtes are not working in the following scenarios:
58 // 4. _Generic(expr, type_1: DRE, type_2:)
59 // 5. decltype(DRE) var = y;
61 // This is becauste the UPC and ULC context matchers do not handle these contexts
62 // and almost all FixableGagdets currently depend on these matchers.
64 // FIXME: Emit fixits for each of the below use.
65 void uneval_context_fix_pointer_dereference_not_handled() {
69 foo(sizeof(*p
), sizeof(decltype(*p
)));
71 int *q
= (int *)malloc(sizeof(*p
));
73 __is_pod(__typeof(*p
));
74 __is_trivially_constructible(__typeof(*p
), decltype(*p
));
75 _Generic(*p
, int: 2, float: 3);
76 _Generic(1, int: *p
, float: 3);
77 _Generic(1, int: 2, float: *p
);