[Bug c++/50224] New: [c++0x]g++ complains unused parameter but it is referenced in lambda

2011-08-29 Thread lene13 at gmail dot com
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 
#include 
#include 

struct T;

struct S {
void m(T& t);
};

struct C {
std::vector> _s;

void m(T& t) // ERROR here
{
std::for_each(_s.begin()
, _s.end()
, [&](std::unique_ptr 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 
#include 
#include 

struct S {
void m(int t); // changed to int
};

struct C {
std::vector> _s;

void m(int t) // changed to int
{
std::for_each(_s.begin()
, _s.end()
, [&](std::unique_ptr 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.


[Bug c++/49339] New: [C++0x][lambda][unused-parameter]g++ reports unused parameter even it's referenced in function

2011-06-09 Thread lene13 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49339

   Summary: [C++0x][lambda][unused-parameter]g++ reports unused
parameter even it's referenced in function
   Product: gcc
   Version: 4.6.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: len...@gmail.com


I'm using ArchLinux with GCC 4.6.0 (20110603).
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-linux-gnu/4.6.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: /build/src/gcc-4.6-20110603/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-libstdcxx-pch --enable-checking=release
Thread model: posix
gcc version 4.6.0 20110603 (prerelease) (GCC)

When compiling following codes

#include 
#include 
#include 
#include 

template 
void append(std::vector<_RawType>& former, std::vector<_RawType>&& latter)
{
std::for_each(latter.begin()
, latter.end()
, [&](_RawType& x)
  {
  former.push_back(std::move(x));
  });
}

int main(void)
{
std::vector aa;
append(aa, std::vector());
return 0;
}

with

g++ % -Wunused-parameter -std=c++0x

g++ prints

unused-param.cpp: In instantiation of ‘append(std::vector<_RealType>&,
std::vector<_RealType>&&) [with _RawType = int]::’:
unused-param.cpp:9:5:   instantiated from ‘void append(std::vector<_RealType>&,
std::vector<_RealType>&&) [with _RawType = int]’
unused-param.cpp:20:34:   instantiated from here
unused-param.cpp:11:34: warning: unused parameter ‘x’ [-Wunused-parameter]

but `x` is referenced in line 13 ("former.push_back(std::move(x));").