Skip to content

Bogus warning: 'memset' will always overflow; destination buffer has size 1, but size argument is 2 [-Wfortify-source] #124513

Closed
@stbergmann

Description

@stbergmann

On recent LLVM trunk (towards LLVM 20), bisecting shows that 0a9c08c "[Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (#95474)" started to cause

$ cat test.cc
#include <cstring>
struct S { char m1, m2; };
void f(S & x) { std::memset(&x, 0, sizeof (S)); }
$ clang++ -std=c++23 -fsyntax-only test.cc
test.cc:3:17: warning: 'memset' will always overflow; destination buffer has size 1, but size argument is 2 [-Wfortify-source]
    3 | void f(S & x) { std::memset(&x, 0, sizeof (S)); }
      |                 ^
1 warning generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions