C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Can static_assert(false) be ignored in if constexpr?
From: Brian Bi (bbi5291_at_[hidden])
Date: 2021-01-13 13:27:21


It was previously suggested (on the old list) to write a proposal to
special-case static_assert:
https://groups.google.com/a/isocpp.org/g/std-proposals/c/d2ADcbygYn4/m/jNtpL2GpBgAJ

There was support for this idea, but it seems no one ever got around to
doing it.

On Wed, Jan 13, 2021 at 2:00 PM Andrew Schepler via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> A core language proposal to just make the original
> static_assert(false, "msg") work as intended, only causing an error if
> instantiated, would seem reasonable to me. I think it would just need
> to call for a modification to the two rules in [temp.res.general]/6
> which say that the program is ill-formed if no valid specialization
> can exist or if instantiating a construct not depending on template
> parameters would be ill-formed. As the one exception, a
> static_assert-declaration appearing within a constexpr if substatement
> is not considered ill-formed for these purposes if the
> constant-expression is well-formed but its value is false. But if the
> smallest enclosing constexpr if substatement is instantiated, that
> does make the program ill-formed.
>
> Often a narrow exception to a general rule is a bad idea and cause for
> confusion, but this seems to be a common enough wanted use case to
> consider it.
>
>
> -- Andrew Schepler
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>

-- 
*Brian Bi*


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups