[LLVMbugs] [Bug 16243] New: this pointer isn't qualified within decltype() when used in member function declaration with late specified return type
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Jun 6 04:30:39 PDT 2013
http://llvm.org/bugs/show_bug.cgi?id=16243
Bug ID: 16243
Summary: this pointer isn't qualified within decltype() when
used in member function declaration with late
specified return type
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++11
Assignee: unassignedclangbugs at nondot.org
Reporter: mitchnull+llvm at gmail.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
Created attachment 10636
--> http://llvm.org/bugs/attachment.cgi?id=10636&action=edit
test program showing the failure
The explicit 'this' pointer in member function declaration with late specified
return type using decltype is not const-qualified if the member function is
declared 'const' resulting in wrong return type.
Example:
template <typename T>
struct DecltypeConstThis {
void f() {}
T f() const { return T{}; }
auto g() -> decltype(this->f()) { return f(); }
auto g() const -> decltype(this->f()) { return f(); } // apparently
'this' is not const within the decltype() here
};
int main() {
DecltypeConstThis<int> d;
const DecltypeConstThis<int> &cd = d;
d.g();
cd.g(); // fails
return 0;
}
compilation error:
[mitch at deneb src]$ clang++ -std=c++11 -o decltype-const-this
decltype-const-this.cpp
decltype-const-this.cpp:8:47: error: void function 'g' should not return a
value
[-Wreturn-type]
auto g() const -> decltype(this->f()) { return f(); } // apparently
'this' is...
^ ~~~
decltype-const-this.cpp:17:8: note: in instantiation of member function
'DecltypeConstThis<int>::g' requested here
cd.g(); // fails
The same code works as expected with implicit 'this':
template <typename T>
struct DecltypeConstThis {
void f() {}
T f() const { return T{}; }
auto g() -> decltype(f()) { return f(); }
auto g() const -> decltype(f()) { return f(); } // decltype() correctly
picks 'f() const' here
};
int main() {
DecltypeConstThis<int> d;
const DecltypeConstThis<int> &cd = d;
d.g();
cd.g();
return 0;
}
(ps: gcc-4.8 requires the explicit this-> here, filing a bug report that way,
too)
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130606/468973e5/attachment.html>
More information about the llvm-bugs
mailing list