C++ Logo

std-proposals

Advanced search

Re: Relax static_assert message restriction

From: Jake Arkinstall <jake.arkinstall_at_[hidden]>
Date: Thu, 4 Jul 2019 23:44:31 +0100
Related:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0596r0.html

But it doesn't seem to have made any progress in a couple of years. I've
CC'd the author -Daveed, do you have an update on this proposal?

Im definitely in agreement that compile time debug is becoming more and
more of an issue as more and more compile time features are added.
Requiring hardcoded strings just doesn't make sense when dealing with e.g.
templated functions. Granted, concepts will help with friendlier output,
but that doesn't negate the fact that a library developer might find it
necessary to provide custom information upon compilation error.



On Thu, 4 Jul 2019, 21:57 Garrett May via Std-Proposals, <
std-proposals_at_[hidden]> wrote:

>
> Hi,
>
> C++20 will bring about constraints and concepts, which will provide more
> useful messages for diagnosing errors. However, as far as I know, it is
> still not possible to throw at compile-time custom error messages built
> from compile-time information.
>
> Our current mechanism for doing something along those lines is to use
> static_assert, but that requires the provided message to be a string
> literal. My suggestion here is to relax this restriction to allow messages
> to be a constexpr static char const* type.
>
> With the ability to handle compile-time strings (char const*) much more
> easily in C++20, it would then be feasible to do something like the
> following:
>
> template<typename T, typename S>
> constexpr void foo(){
> constexpr auto t_size = sizeof(T);
> constexpr auto s_size = sizeof(S);
> constexpr bool same = (t_size == s_size);
> constexpr static char const* msg = str_lit<"These are not the same",
> t_size, s_size>{}; // Build a constexpr static char const* with the
> embedded compile-time sizes
> static_assert(!same, msg);
> }
>
> Is something like this already possible, and if not, does this idea
> interest anyone?
>
> Thanks,
>
> Garrett
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> http://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2019-07-04 17:46:34