Inside a template function, calling another function that takes an rvalue
reference as argument with a temporary value incorrectly results in an error
when the -pedantic flag is used.


Reduced test case:

void foo(int&& data);

template <typename T>
void bar(T t)
{ foo(int()); }

void baz()
{ bar(0); }


Compilation command:

g++-4.5 -std=c++0x -c b.cpp -pedantic


Output from compilation command:

b.cpp: In function ‘void bar(T)’:
b.cpp:5:12: error: invalid initialization of reference of type ‘int&&’ from
expression of type ‘int’
b.cpp:1:6: error: in passing argument 1 of ‘void foo(int&&)’


Output of g++-4.5 -v:

Using built-in specs.
COLLECT_GCC=g++-4.5
COLLECT_LTO_WRAPPER=/home/eeyts/root/libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.5.0/configure --prefix=/home/eeyts/root
--disable-shared --enable-threads=posix --enable-__cxa_atexit --enable-libgomp
--disable-libunwind-exceptions --enable-languages=c,c++
--with-gmp=/home/eeyts/root --with-mpfr=/home/eeyts/root
--with-mpc=/home/eeyts/root --with-host-libstdcxx=/usr/lib64/libstdc++.so.6
--with-ppl=/home/eeyts/root --with-cloog=/home/eeyts/root
--with-libelf=/home/eeyts/root --program-suffix=-4.5
Thread model: posix
gcc version 4.5.0 (GCC)


-- 
           Summary: -pedantic causes error when calling function with rvalue
                    argument inside template
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tspiteri at ieee dot org


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

Reply via email to