http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49369
Summary: typeof() strips const from member when used in const method Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: shawn.boh...@gmail.com $ 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.