http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50224
Bug #: 50224 Summary: [c++0x]g++ complains unused parameter but it is referenced in lambda Classification: Unclassified Product: gcc Version: 4.6.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: len...@gmail.com #include <vector> #include <algorithm> #include <memory> struct T; struct S { void m(T& t); }; struct C { std::vector<std::unique_ptr<S>> _s; void m(T& t) // ERROR here { std::for_each(_s.begin() , _s.end() , [&](std::unique_ptr<S> const& s) { s->m(t); // ``t`` is referenced here }); } }; Compile that codes with $ g++ test.cpp -c -Wunused-parameter -std=c++0x -Werror and g++ will complain test.cpp:14:10: error: unused parameter âtâ [-Werror=unused-parameter] But if the parameter type changed to built in primitives, the error won't occur, say, like #include <vector> #include <algorithm> #include <memory> struct S { void m(int t); // changed to int }; struct C { std::vector<std::unique_ptr<S>> _s; void m(int t) // changed to int { std::for_each(_s.begin() , _s.end() , [&](std::unique_ptr<S> const& s) { s->m(t); }); } }; My compiler and system info: Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /build/src/gcc-4.6-20110819/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 --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --enable-gnu-unique-object --enable-linker-build-id --with-ppl --enable-cloog-backend=isl --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --disable-multilib --disable-libssp --disable-libstdcxx-pch --enable-checking=release Thread model: posix gcc version 4.6.1 20110819 (prerelease) (GCC) There is a similar bug I've reported before http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49339 marked as duplicated of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49251 Hope that will help.