[Bug c++/57543] New: decltype needs eplicity 'this' pointer in member function declaration of template class with trailing return type
mitchnull+gcc at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Jun 6 11:53:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57543
Bug ID: 57543
Summary: decltype needs eplicity 'this' pointer in member
function declaration of template class with trailing
return type
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mitchnull+gcc at gmail dot com
Created attachment 30268
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30268&action=edit
decltype-implicit-this.cpp
When using trailing return-type for member functions of a template class, the
'this' pointer must be explicitly mentioned. This should not be necessary (The
implicit 'this' works with a non-template class).
Example:
emplate <typename T>
struct DecltypeConstThis {
T f() const { return T{}; }
auto g() -> decltype(this->f()) { return this->f(); }
auto h() const -> decltype(f()) { return f(); } // this should work the
same as g() above (with implicit 'this')
};
struct Working {
int f() const { return 0; }
auto h() const -> decltype(f()) { return 0; }
};
int main() {
Working w;
w.h();
DecltypeConstThis<int> d;
d.g();
d.h();
return 0;
}
compiler output:
[mitch@deneb src]$ g++ -std=c++11 -o decltype-implicit-this
decltype-implicit-this.cpp
decltype-implicit-this.cpp: In instantiation of ‘struct
DecltypeConstThis<int>’:
decltype-implicit-this.cpp:22:28: required from here
decltype-implicit-this.cpp:7:36: error: cannot call member function ‘T
DecltypeConstThis<T>::f() const [with T = int]’ without object
auto h() const -> decltype(f()) { return f(); } // this should work the
same as g() above (with implicit 'this')
^
decltype-implicit-this.cpp: In function ‘int main()’:
decltype-implicit-this.cpp:24:7: error: ‘struct DecltypeConstThis<int>’ has no
member named ‘h’
d.h();
^
ps: possibly related to bug #54359
More information about the Gcc-bugs
mailing list