Subject: Re: Can static_assert(false) be ignored in if constexpr?
From: Yongwei Wu (wuyongwei_at_[hidden])
Date: 2021-01-14 06:45:29
Thank you all for the replies. I see that there are workarounds, so no one
feels eager enough to pursue a core language change. A regret, but probably
acceptable, as the committee has a lot to do.
For the moment, I'll stick with the always_false<T> hack.
On Thu, 14 Jan 2021 at 03:27, Brian Bi via Std-Discussion <
> It was previously suggested (on the old list) to write a proposal to
> special-case static_assert:
> 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
> *Brian Bi*
> Std-Discussion mailing list
-- Yongwei Wu URL: http://wyw.dcweb.cn/
STD-DISCUSSION list run by email@example.com
Older Archives on Google Groups