[Bug c++/88804] New: Inconsistently diagnosed unused but set static variable in lambda

m101010a at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Jan 11 15:00:00 GMT 2019


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

            Bug ID: 88804
           Summary: Inconsistently diagnosed unused but set static
                    variable in lambda
           Product: gcc
           Version: 8.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: m101010a at gmail dot com
  Target Milestone: ---

$ cat x.cpp
void foo(int);
template <class T> void call(T t) {
    t(0);
}
void bar() {
        static int x=3;
        call([](auto){
                foo(x);
        });
}
$ cat y.cpp
void foo(int);
template <class T> void call(T t) {
    t(0);
}
void bar() {
        static int x=3;
        call([](int){
                foo(x);
        });
}
$ g++ -fsyntax-only -Wunused-but-set-variable x.cpp
x.cpp: In function ‘void bar()’:
x.cpp:6:13: warning: variable ‘x’ set but not used [-Wunused-but-set-variable]
  static int x=3;
             ^
$ g++ -fsyntax-only -Wunused-but-set-variable y.cpp
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --enable-libmpx --with-system-zlib --with-isl
--enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu
--disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object
--enable-linker-build-id --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu
--enable-gnu-indirect-function --enable-multilib --disable-werror
--enable-checking=release --enable-default-pie --enable-default-ssp
--enable-cet=auto
Thread model: posix
gcc version 8.2.1 20181127 (GCC) 

x is incorrectly diagnosed as unused when used in a lambda with an auto
parameter, but not in a lambda with a type parameter (or no parameter).  This
happens even if the lambda isn't called, but does not happen if the lambda is
called in the same function where it is declared.


More information about the Gcc-bugs mailing list