On Thu, 31 Mar 2022 at 16:51, Matthias Kretz via Libstdc++
<[email protected]> wrote:
>
> I like it. But I'd like it even more if we could have
>
> #elif defined _UBSAN
> __ubsan_invoke_ub("reached std::unreachable()");
>
> But to my knowledge UBSAN has no hooks for the library like this (yet).
As far as I know, that's correct.
> > +#ifdef _GLIBCXX_DEBUG
> > + std::__glibcxx_assert_fail("<utility>", 0, "std::unreachable()",
> > + "inconceivable!");
>
> Funny message, but it should be more helpful, IMHO. :)
We're currently limited to some string that can go inside "Assertion
'...' failed."
I also considered changing __glibcxx_assert_fail like so:
--- a/libstdc++-v3/src/c++11/debug.cc
+++ b/libstdc++-v3/src/c++11/debug.cc
@@ -55,6 +55,8 @@ namespace std
if (file && function && condition)
fprintf(stderr, "%s:%d: %s: Assertion '%s' failed.\n",
file, line, function, condition);
+ else if (function)
+ fprintf(stderr, "%s called.\n", function);
abort();
}
}
And then making std::unreachable() call __glibcxx_assert_fail(0, 0,
"std::unreachable()", 0).