Issue 64646
Summary Unsafe buffer usage: false positive
Labels new issue
Assignees
Reporter andrew-aitchison
    // Ubuntu clang version 16.0.0 (1~exp5ubuntu3)
// clang++-16 -Wunsafe-buffer-usage -c -o unsafe.o unsafe.cpp

```
int f(const int a[10])
{
    return a[1];
}

```

unsafe.cpp:8:17: warning: 'a' is an unsafe pointer used for buffer access [-Wunsafe-buffer-usage]
int f(const int a[10])
      ~~~~~~~~~~^~~~~
unsafe.cpp:10:12: note: used in buffer access here
    return a[1];
           ^
1 warning generated.

Since the size of array 'a' is known, and known to be fixed, at compile-time, the access is safe *and* the compiler can determine this, so the warning is a false positive.

While I appreciate that `std::span` would be better, there is much code out there that is not ready for C++20.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to