Skip to content

Use gcc-trunk (20171123) and fail to compile: variable set but not used #3

@PXAHyLee

Description

@PXAHyLee

Hi, I watched the talk on CppCon2017 and tried to compile the piece of code with gcc-trunk but the compiler would say something like:

variable ‘b’ set but not used [-Werror=unused-but-set-variable]

My compiler version is

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/phi/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/8.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./../gcc-trunk/configure --prefix=/home/phi/gcc-trunk --enable-languages=c,c++ : (reconfigured) /media/phi/a60c856b-88ad-4199-ab95-a49fc0c9466a/codebase/gcc-infrastructure/objdir/../gcc-trunk/configure --prefix=/home/phi/gcc-trunk --enable-languages=c,c++
Thread model: posix
gcc version 8.0.0 20171123 (experimental) (GCC)

I use the command
cd build && cmake -D CMAKE_CXX_COMPILER=/home/phi/gcc-trunk/bin/g++ CMAKE_C_COMPILER=/home/phi/gcc-trunk/bin/gcc ../ to generate the Makefile.

The error message is like:

<dir>/src/test/algorithm.cpp: In function ‘void algo_tests_nonmod()’:
<dir>/src/test/algorithm.cpp:11:20: error: variable ‘b’ set but not used [-Werror=unused-but-set-variable]
     constexpr bool b = cx::all_of(std::cbegin(arr), std::cend(arr),
                    ^
<dir>/src/test/algorithm.cpp:18:20: error: variable ‘b’ set but not used [-Werror=unused-but-set-variable]
     constexpr bool b = cx::any_of(std::cbegin(arr), std::cend(arr),
                    ^
... (other variable unused error messages) ...

But when I checked the code these variables is used by static_assert like static_assert(b, "all_of fail");.

It seems so weird to me since these variables are used in the next line. Could anyone give me some insight or helps for how to go through this issue? (An obvious solution is turning off the -Werror option.)

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions