[Bug c++/42066] New: C++0x lambda captures are not understood as used by -Wunused and -Wunused-parameter

lloyd at randombit dot net gcc-bugzilla@gcc.gnu.org
Mon Nov 16 16:11:00 GMT 2009


GCC 4.5's -Wunused and -Wunused-parameter warnings don't understand that i and
n being used in the function below:

#include <functional>

std::function<int ()> foo(int i)
   {
   int n = 5;
   return [=]() { return i+n; };
   }

$ g++-4.5-20091112 -std=c++0x -Wall -Wextra -c lambda.cpp 
lambda.cpp: In function 'std::function<int()> foo(int)':
lambda.cpp:5:8: warning: unused variable 'n'
lambda.cpp: At global scope:
lambda.cpp:3:23: warning: unused parameter 'i'

Using optimizations doesn't seem to have an effect on this either way.

Workaround: Adding i and n explicitly to the capture list causes GCC to
understand that they are being used in this function.

$ g++-4.5-20091112 -v
Using built-in specs.
COLLECT_GCC=/usr/local/bin/g++-4.5-20091112
COLLECT_LTO_WRAPPER=/usr/local/gcc-4.5-20091112/libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.5-20091112/configure
--prefix=/usr/local/gcc-4.5-20091112 --program-suffix=-4.5-20091112
--enable-languages=c,c++
Thread model: posix
gcc version 4.5.0 20091112 (experimental) (GCC)


-- 
           Summary: C++0x lambda captures are not understood as used by -
                    Wunused and -Wunused-parameter
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: lloyd at randombit dot net
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42066



More information about the Gcc-bugs mailing list