Bug 49369 - typeof() strips const from member when used in const method
typeof() strips const from member when used in const method
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c++
4.6.0
: P3 normal
: 4.6.1
Assigned To: Jason Merrill
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-06-10 18:51 UTC by shawn.bohrer
Modified: 2011-06-15 03:55 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-06-11 05:05:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description shawn.bohrer 2011-06-10 18:51:16 UTC
$ 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.
Comment 1 Jonathan Wakely 2011-06-10 19:22:43 UTC
can you use typeof(this->B::member) instead?
Comment 2 shawn.bohrer 2011-06-10 20:20:11 UTC
(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?
Comment 3 Jonathan Wakely 2011-06-10 21:11:53 UTC
(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?
Comment 4 Jason Merrill 2011-06-11 05:05:12 UTC
Yes, this is a bug.  build_base_path is failing to preserve the cv-quals on this when converting to a pointer to B.
Comment 5 Jason Merrill 2011-06-14 18:15:53 UTC
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
Comment 6 Jason Merrill 2011-06-14 22:13:32 UTC
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
Comment 7 Jason Merrill 2011-06-15 03:55:11 UTC
Fixed for 4.6.1.