llvm/llvm-project

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

Open

#166,644 建立於 2025年11月5日

在 GitHub 查看
 (14 留言) (0 反應) (0 負責人)C++ (10,782 fork)batch import
clang:diagnosticsgood first issue

倉庫指標

Star
 (26,378 star)
PR 合併指標
 (平均合併 1天 2小時) (30 天內合併 1,000 個 PR)

描述

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.

貢獻者指南