Skip to content

-Wunsafe-buffer-usage erroneously warns on array accesses known to be in bounds, but only in function scope #92191

@pkasting

Description

@pkasting

Compiling the following code with -Wunsafe-buffer-usage unexpectedly emits a warning:

constexpr char kAbc[] = "abc"; static_assert(kAbc[3] == '\0'); // OK static_assert("abc"[3] == '\0'); // OK void f() { static_assert(kAbc[3] == '\0'); // OK static_assert("abc"[3] == '\0'); // WARNING } 

Live repro: https://godbolt.org/z/c6jhdvPTb

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-positiveWarning fires when it should not

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions