Example:
int * const my_var = my_initializer;
Currently when transforming my_var to std::span the fixits:
- replace "int * const my_var = " with "std::span<int> const my_var {"
- add ", SIZE}" after "my_initializer" where SIZE is either inferred or
a placeholder
This patch makes that behavior less intrusive by not modifying variable
cv-qualifiers and initialization syntax.
The new behavior is:
- replace "int *" with "std::span<int>"
- add "{" before "my_initializer"
- add ", SIZE}" after "my_initializer"
This is an improvement on its own - since we don't touch the identifier,
we automatically can handle macros in them.
It also simplifies future work on initializer fixits.
19 lines
870 B
C++
19 lines
870 B
C++
// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
|
|
// RUN: -fsafe-buffer-usage-suggestions \
|
|
// RUN: -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
|
|
|
|
// TODO cases where we don't want fixits
|
|
|
|
// The Fix-It for unsafe operation is trivially empty.
|
|
// In order to test that our machinery recognizes that we can test if the variable declaration gets a Fix-It.
|
|
// If the operation wasn't handled propertly the declaration won't get Fix-It.
|
|
// By testing presence of the declaration Fix-It we indirectly test presence of the trivial Fix-It for its operations.
|
|
void test() {
|
|
int *p = new int[10];
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int> "
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
|
|
p[5] = 1;
|
|
// CHECK-NOT: fix-it:
|
|
}
|