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: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
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@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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs