llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.06k stars 11.59k forks source link

`std::any_cast` may throw even when type seems to be right #37833

Open llvmbot opened 6 years ago

llvmbot commented 6 years ago
Bugzilla Link 38485
Version 6.0
OS Linux
Attachments example
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@scpeters

Extended Description

I've prepared a single example which throws std::bad_any_cast.

At first glance it should work (no problems with gcc).

dda69560-af4f-4ad0-89b5-ff572eb0ddd9 commented 3 years ago

I just tested again with Apple clang version 11.0.3 (clang-1103.0.32.62) on macOS 10.15.7, and I'm not able to reproduce the problem. So, I guess it has been fixed?

dda69560-af4f-4ad0-89b5-ff572eb0ddd9 commented 5 years ago

I just reproduced this bug with the Xcode 11 GM on macOS Catalina beta.

dda69560-af4f-4ad0-89b5-ff572eb0ddd9 commented 5 years ago

Should the Component be re-categorized as C++17?

dda69560-af4f-4ad0-89b5-ff572eb0ddd9 commented 6 years ago

Here's the issue report for my downstream code affected by this bug: https://bitbucket.org/osrf/sdformat/issues/202/bad_any_cast-after-element-getany-with

dda69560-af4f-4ad0-89b5-ff572eb0ddd9 commented 6 years ago

I've run into this same problem; thanks for reporting it and providing the reproducible example. I've tested the example with clang6 and gcc8 on bionic, and only clang exhibits the problem. Furthermore, if I modify the example to use boost::any instead of std::any, then it still works with clang. It seems to be an issue with clang std::any.