https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112347

--- Comment #13 from David Binderman <dcb314 at hotmail dot com> ---
I have been trying to get this C++ code to produce the new warning:

#include <cstdlib>

struct S
{
        int a[ 10];
        float * b[ 20];
};

extern void g( S * ps);

void f( int n)
{
        S * ps = (S *) calloc( sizeof( S), 1);
        g( ps);

        S * ps2 = (S *) calloc( 1, sizeof( S));
        g( ps2);

        S * ps3 = (S *) calloc( 1, sizeof( S) / 2);
        g( ps3);
}

$ ~/gcc/results/bin/g++ -g -O2 -Wall -Wextra -Walloc-size -c nov2b.cc
cc1plus: warning: command-line option ‘-Walloc-size’ is valid for C/ObjC but
not for C++
nov2b.cc: In function ‘void f(int)’:
nov2b.cc:12:13: warning: unused parameter ‘n’ [-Wunused-parameter]
   12 | void f( int n)
      |         ~~~~^
$ ~/gcc/results/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/home/dcb38/gcc/results/bin/g++
COLLECT_LTO_WRAPPER=/home/dcb38/gcc/results.20231102.asan.ubsan/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../trunk.year/configure
--prefix=/home/dcb38/gcc/results.20231102.asan.ubsan --disable-multilib
--disable-bootstrap --with-build-config=bootstrap-asan
--with-build-config=bootstrap-ubsan --with-pkgversion=01c18f58d37865d5
--enable-checking=df,extra,fold,rtl,yes --enable-languages=c,c++,fortran
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.0 20231102 (experimental) (01c18f58d37865d5) 
$ 

I think calloc is available in C++, so the warning is wrong.

Reply via email to