| Issue |
174315
|
| Summary |
[libc++] Tricky results of `std::any_cast<const T&>(ptr)`/`std::any_cast<T&&>(ptr)`
|
| Labels |
libc++
|
| Assignees |
|
| Reporter |
frederick-vs-ja
|
When using `std::any_cast<const T&>(arg)` or `std::any_cast<T&&>(arg)`, other implementations will exclude the overloads taking `any*`/`const any*`, while libc++ possibly triggers hard errors via `static_assert` in these overloads.
E.g. the following program is rejected with libc++ ([Godbolt link](https://godbolt.org/z/oevndTvqe)):
```C++
#include <cassert>
#include <any>
int main() {
std::any a;
assert(&a == std::any_cast<std::any*&&>(&a));
}
```
It seems that other implementations are conforming as the standard wording use `T*` and `const T*` in [[any.nonmembers]](https://eel.is/c++draft/any.nonmembers). But this also means that `std::any_cast<const T&>(ptr)`/`std::any_cast<T&&>(ptr)` need to create `any` temporary objects and return easy-to-dangling references (if not throw). Not sure whether an LWG issue is wanted.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs