1 // RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fdiagnostics-parseable-fixits -fsafe-buffer-usage-suggestions %s 2>&1 | FileCheck %s
3 // We cannot deal with overload conflicts for now so NO fix-it to
4 // function parameters will be emitted if there are overloads for that
7 #include "warn-unsafe-buffer-usage-fixits-parm-span-overload.h"
9 void foo(int *p
, int * q
);
14 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
19 // an overload declaration of `bar(int *)` appears after it
21 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
28 // an overload declaration of `baz(int)` appears is in the included header
30 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
36 // `NS::foo` is a distinct function from `foo`, so it has no
37 // overload and shall be fixed.
39 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:12-[[@LINE-1]]:18}:"std::span<int> p"
43 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:4-[[@LINE-1]]:4}:"\n{{\[}}{{\[}}clang::unsafe_buffer_usage{{\]}}{{\]}} void foo(int *p) {return foo(std::span<int>(p, <# size #>));}\n"
45 // Similarly, `NS::bar` is distinct from `bar`:
47 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:3}:"{{\[}}{{\[}}clang::unsafe_buffer_usage{{\]}}{{\]}} "
48 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:19-[[@LINE-2]]:19}:";\nvoid bar(std::span<int> p)"
49 } // end of namespace NS
51 // This is the implementation of `NS::bar`, which shall be fixed.
52 void NS::bar(int *p
) {
53 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:20}:"std::span<int> p"
57 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:2-[[@LINE-1]]:2}:"\n{{\[}}{{\[}}clang::unsafe_buffer_usage{{\]}}{{\]}} void NS::bar(int *p) {return NS::bar(std::span<int>(p, <# size #>));}\n"
61 void beta(int *, int *);
64 // `NESTED::INNER::alpha` is distinct from `NESTED::alpha`, so it
65 // has no overload and shall be fixed.
67 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:22}:"std::span<int> p"
71 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:6-[[@LINE-1]]:6}:"\n{{\[}}{{\[}}clang::unsafe_buffer_usage{{\]}}{{\]}} void alpha(int *p) {return alpha(std::span<int>(p, <# size #>));}\n"
76 // There is an `NESTED::beta(int *, int *)` declared above, so this
77 // unsafe function will not be fixed.
79 // CHECK-NOT: fix-it:"{{.*}}":[[@LINE-1]]:
85 void delta(int); // No fix for `NESTED::INNER::delta`
90 // There is an `NESTED::beta(int *)` declared above, so this unsafe
91 // function will not be fixed.
92 void NESTED::beta(int *p
, int *q
) {
93 // CHECK-NOT: fix-it:"{{.*}}":[[@LINE-1]]:
99 void NESTED::INNER::delta(int * p
) {
100 // CHECK-NOT: fix-it:"{{.*}}":[[@LINE-1]]: