http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57392
Bug ID: 57392
Summary: The result of a .* expression is rvalue in a function
template when its object expression is lvalue.
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: kyusic at gmail dot com
Created attachment 30178
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30178&action=edit
preprocessed source
g++ rejects the following program in c++11 mode:
-------------- begin -------------
struct A
{
int i;
};
void g(int& p) {}
template <typename T>
void f()
{
A a;
int A::*pm = &A::i;
g(a.*pm); // (*)
}
------------- end ----------------
It says the expression 'a.*pm' at the line marked with (*) is rvalue, which
should be lvalue because its object expression 'a' is lvalue.
It compiles fine when f() is not templated.
g++-4.8.0 has the same problem.
Following is the compiler message:
------------- begin ----------------
$ g++ -v -save-temps -c -std=c++11 a.cc
Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.7.3/configure --enable-languages=c++
--disable-multilib
Thread model: posix
gcc version 4.7.3 (GCC)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-std=c++11' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.7.3/cc1plus -E -quiet -v
-imultilib . -imultiarch x86_64-linux-gnu -D_GNU_SOURCE a.cc -mtune=generic
-march=x86-64 -std=c++11 -fpch-preprocess -o a.ii
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.3/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.3/../../../../include/c++/4.7.3
/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.3/../../../../include/c++/4.7.3/x86_64-unknown-linux-gnu/.
/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.3/../../../../include/c++/4.7.3/backward
/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.3/include
/usr/local/include
/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.3/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-std=c++11' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.7.3/cc1plus -fpreprocessed
a.ii -quiet -dumpbase a.cc -mtune=generic -march=x86-64 -auxbase a -std=c++11
-version -o a.s
GNU C++ (GCC) version 4.7.3 (x86_64-unknown-linux-gnu)
compiled by GNU C version 4.7.3, GMP version 5.0.5, MPFR version 3.1.1-p2,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (GCC) version 4.7.3 (x86_64-unknown-linux-gnu)
compiled by GNU C version 4.7.3, GMP version 5.0.5, MPFR version 3.1.1-p2,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: e27c3e349c650e830c6a08a9bf1d2e03
a.cc: In function ‘void f()’:
a.cc:13:12: error: invalid initialization of non-const reference of type ‘int&’
from an rvalue of type ‘int’
a.cc:6:6: error: in passing argument 1 of ‘void g(int&)’
---------------------- end ----------------------