Issue 109442
Summary -Wdangling-gsl does not work consistently with span across STL
Labels new issue
Assignees
Reporter marco-antognini-sonarsource
    I'm checking the behavior of Clang 19 vs 18 and I noticed that @hokein's https://github.com/llvm/llvm-project/pull/99622 introduces some nice warnings thanks to the added attributes on `std::span`.

However, it does not work with libc++.

Here is an example:
```cpp
#include <span>
#include <string>

struct SpanAggr {
  std::span<char const> sv;
};

void test() {
  // No issue raised in 18.1
  // Issue raised from 19.1 thanks to https://github.com/llvm/llvm-project/pull/99622
  // but not with libc++
  SpanAggr a1{std::span<char const>{std::string{}}};
}
```
https://godbolt.org/z/Yfe78nsdb

IIUC, the problem boils down to the fact `std::span` is defined with a template specialization for dynamic extent and the `ClassTemplatePartialSpecializationDecl` does not get the `PointerAttr`:

```cpp
namespace std {
inline constexpr size_t dynamic_extent = -1;
template <typename _Tp, size_t _Extent = dynamic_extent>
class span;

template <typename _Tp, size_t _Extent>
struct span {
  // Bla
};
template <typename _Tp>
struct span<_Tp, dynamic_extent> {
  // Bla
};
}  // namespace std
```


https://godbolt.org/z/nh1j4a7xE


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

Reply via email to