]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Enable -Walloc-size and -Wcalloc-transposed-args warnings for C++
authorJakub Jelinek <jakub@redhat.com>
Thu, 21 Dec 2023 10:17:08 +0000 (11:17 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 21 Dec 2023 10:17:08 +0000 (11:17 +0100)
commitb9dc16cbe2222bf1006a6266ba89da460165f3cb
treedc9ea403efb11e0111bff4f30284df4dfece98cb
parent0e7f5039c52a020c3ed5f18a2b3ee1fb42b78f62
c++: Enable -Walloc-size and -Wcalloc-transposed-args warnings for C++

The following patch enables the -Walloc-size and -Wcalloc-transposed-args
warnings for C++ as well.

Tracking just 6 arguments for SIZEOF_EXPR for the calloc purposes
is because I see alloc_size 1,2, 2,3 and 3,4 pairs used in the wild,
so we need at least 5 to cover that rather than 3, and don't want to waste
too much compile time/memory for that.

2023-12-21  Jakub Jelinek  <jakub@redhat.com>

gcc/c-family/
* c.opt (Walloc-size): Enable also for C++ and ObjC++.
gcc/cp/
* cp-gimplify.cc (cp_genericize_r): If warn_alloc_size, call
warn_for_alloc_size for -Walloc-size diagnostics.
* semantics.cc (finish_call_expr): If warn_calloc_transposed_args,
call warn_for_calloc for -Wcalloc-transposed-args diagnostics.
gcc/testsuite/
* g++.dg/warn/Walloc-size-1.C: New test.
* g++.dg/warn/Wcalloc-transposed-args-1.C: New test.
gcc/c-family/c.opt
gcc/cp/cp-gimplify.cc
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/warn/Walloc-size-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wcalloc-transposed-args-1.C [new file with mode: 0644]