llvm/llvm-project

[-Wunsafe-buffer-usage] Warn about two-arg string view constructors

Open

#166 644 ouverte le 5 nov. 2025

Voir sur GitHub
 (14 commentaires) (0 réactions) (0 assignés)C++ (10 782 forks)batch import
clang:diagnosticsgood first issue

Métriques du dépôt

Stars
 (26 378 stars)
Métriques de merge PR
 (Merge moyen 1j 2h) (1 000 PRs mergées en 30 j)

Description

The two-arg form of std::span<> will currently produce a warning when used along with the -Wunsafe-buffer-usage-in-container option, subject to heuristics that try to determine suspicious arguments.

The string view types, (actually std::basic_string_view<>) have the same issues as does std::span<> when used with a two-argument constructor.

Since the name of the -W flag says "container", I humbly propose covering this case under the same warning, and produce the same waring when encountered.

A small task is removing the specific mention of std::span<> from the diagnostic, expanding it to imply other containers.

Guide contributeur