gazebosim / gazebosim/sdformat

bad_any_cast after Element::GetAny with gz11 on homebrew

Open
#202 5 comments 0 reactions 1 assignee Claimed by @scpeters View on GitHub
bug macOS major
Dominant language
C++
Stars
216
Forks
125
Avg merge
1d 14h
Merged PRs (30d)
14

Description

**Original report ([archived issue](https://osrf-migration.github.io/sdformat-gh-pages/#!/osrf/sdformat/issues/202)) by Steve Peters (Bitbucket: [Steven Peters](https://bitbucket.org/%7B2ccfed09-18b8-4921-8d58-15ef01092802%7D/), GitHub: [scpeters](https://github.com/scpeters)).**

----------------------------------------
There are [two failing tests](https://build.osrfoundation.org/job/sdformat-ci-pr_any-homebrew-amd64-mojave/1/testReport/) for the `gz11` branch on macOS mojave.

* https://build.osrfoundation.org/job/sdformat-ci-pr_any-homebrew-amd64-mojave/1/testReport/(root)/SDF/UpdateElement/
* https://build.osrfoundation.org/job/sdformat-ci-pr_any-homebrew-amd64-mojave/1/testReport/(root)/SDF/GetAny/

I started by investigating the `GetAny` test failure from `UNIT_SDF_TEST`, which failed at [line 418](https://github.com/osrf/sdformat/blob/3826e3878b15598634df332d0c93f7186a506f49/src/SDF_TEST.cc#L418), which occurs when a `std::bad_any_cast` is thrown after calling `std::any_cast(anyValue)`. I added some print statements to confirm that `anyValue` should have the right type:

~~~
diff -r 3826e3878b15598634df332d0c93f7186a506f49 src/SDF_TEST.cc
--- a/src/SDF_TEST.cc Fri Sep 14 00:49:58 2018 +0000
+++ b/src/SDF_TEST.cc Thu Sep 13 17:59:35 2018 -0700
@@ -410,6 +410,13 @@
std::any anyValue = poseElem->GetAny();
try
{
+ using Pose = ignition::math::Pose3d;
+ std::cerr << typeid(Pose).name()
+ << ", " << typeid(Pose).hash_code()
+ << std::endl;
+ std::cerr << anyValue.type().name()
+ << ", " << anyValue.type().hash_code()
+ << std::endl;
EXPECT_EQ(std::any_cast(anyValue),
ignition::math::Pose3d(0, 1, 2, 0, 0, 0));
}
~~~

which gives the following output, showing that the types have matching names, but different `hash_code`s.

~~~
[ RUN ] SDF.GetAny
N8ignition4math2v65Pose3IdEE, 4381304960
N8ignition4math2v65Pose3IdEE, 4382335968
/Users/jenkins/workspace/sdformat-ci-pr_any-homebrew-amd64-mojave/sdformat/src/SDF_TEST.cc:425: Failure
Failed
[ FAILED ] SDF.GetAny (57 ms)
~~~

After some googling, I found an [issue with clang](https://bugs.llvm.org/show_bug.cgi?id=38485) with a reproducible test case (that was originally reported on [stackoverflow](https://stackoverflow.com/questions/51693605/clang-compiled-program-throws-stdbad-any-cast-during-stdany-cast)). I think it's an issue with `std::any` in clang, because the reproducible test case works with gcc or if you switch from `std::any` to `boost::any`.

I think we see the issue because `ignition::math::Pose3d` is a template type, and it may be seeing different versions of of that type from different shared libraries and not recognizing that they are the same. I have requested a llvm.org account so that I can comment on that issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.