Skip to content

[-Wunsafe-buffer-usage] Extra size arg in fixit for std::span initialization with constant size array #80925

Open
@jkorous-apple

Description

@jkorous-apple

Currently the fixit that transforms a local pointer initialized with constant size array uses 2-parameter std::span constructor to which it passes the array and it's size.

https://github.com/llvm/llvm-project/blob/main/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp#L52

void local_variable_qualifiers_specifiers() {
  int a[10];
...
  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:18}:"std::span<int const> p"
  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:19-[[@LINE-2]]:19}:"{"
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:20-[[@LINE-3]]:20}:", 10}"

Idiomatic fixit should not repeat the size and instead rely on single parameter std::span constructor that take const size array.
No. 4 here: https://en.cppreference.com/w/cpp/container/span/span

Example:

void foo() {
    int foo[5];
    std::span<int> sp = foo;
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions