$ g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/home/software/gcc-4.6.0/libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../configure --prefix=/home/software/gcc-4.6.0 --with-gmp=/home/jhand/inst --with-mpfr=/home/jhand/inst Thread model: posix gcc version 4.6.0 (GCC) $ cat typeof.cpp template <typename Container> class A { public: A(Container& container) {} }; class B { protected: int member; }; class C: public B { public: int method() const; }; int C::method() const { A<typeof((B::member))> iter(B::member); return 0; } int main() { return 0; } $ g++ -o typeof typeof.cpp typeof3.cpp: In member function 'int C::method() const': typeof3.cpp:19:42: error: no matching function for call to 'A<int>::A(const int&)' typeof3.cpp:19:42: note: candidates are: typeof3.cpp:5:5: note: A<Container>::A(Container&) [with Container = int] typeof3.cpp:5:5: note: no known conversion for argument 1 from 'const int' to 'int&' typeof3.cpp:2:7: note: A<int>::A(const A<int>&) typeof3.cpp:2:7: note: no known conversion for argument 1 from 'const int' to 'const A<int>&' A couple of additional notes. I get the same error with gcc 4.4.3, 4.5.1, and 4.6.0. I get the same error if I use decltype instead of typeof. I can get it to compile if I do not use the fully qualified name (B::member), however in my real application I must use the fully qualified name.
can you use typeof(this->B::member) instead?
(In reply to comment #1) > can you use typeof(this->B::member) instead? Yes this works for my application, thanks for the suggestion. Surely this is still a bug though correct?
(In reply to comment #2) > (In reply to comment #1) > > can you use typeof(this->B::member) instead? > > Yes this works for my application, thanks for the suggestion. Surely this is > still a bug though correct? I think so, but I'm not sure which is why I left it UNCONFIRMED Jason?
Yes, this is a bug. build_base_path is failing to preserve the cv-quals on this when converting to a pointer to B.
Author: jason Date: Tue Jun 14 18:15:51 2011 New Revision: 175042 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175042 Log: PR c++/49369 * class.c (build_base_path): Fix cv-quals in unevaluated context. Added: trunk/gcc/testsuite/g++.dg/cpp0x/decltype30.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/class.c trunk/gcc/testsuite/ChangeLog
Author: jason Date: Tue Jun 14 22:13:29 2011 New Revision: 175059 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175059 Log: PR c++/49369 * class.c (build_base_path): Fix cv-quals in unevaluated context. Added: branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/decltype30.C Modified: branches/gcc-4_6-branch/gcc/cp/ChangeLog branches/gcc-4_6-branch/gcc/cp/class.c branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Fixed for 4.6.1.