why did g++-12 report "warning: value computed is not used [-Wunused-value]"

67 Views Asked by At

The code

#include <cstdint>
#include <cstring>

int main()
{
        int len = 10;
        uint8_t data[len] = {};
        uint8_t src[len] = { 1, 2, 3 };

        std::memcpy(data, src, len);

        return 0;
}

build with g++-12

➜  test g++ -Wall test.cpp
test.cpp: In function ‘int main()’:
test.cpp:7:30: warning: value computed is not used [-Wunused-value]
    7 |         uint8_t data[len] = {};
      |                              ^
test.cpp:8:38: warning: value computed is not used [-Wunused-value]
    8 |         uint8_t src[len] = { 1, 2, 3 };
      |                                      ^
➜  test g++ --version     
g++ (Ubuntu 12-20220319-1ubuntu1) 12.0.1 20220319 (experimental) [master r12-7719-g8ca61ad148f]
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

build with g++-11

➜  test g++-11 -Wall test.cpp # no errors, no warnings
➜  test g++-11 --version     
g++-11 (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The data and src is used, but why did the g++-12 report an "unused value" warning, and how should I fix the code so that g++-12 doesn't report "value computed is not used"

0

There are 0 best solutions below