C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Can static_assert(false) be ignored in if constexpr?
From: Andrew Schepler (aschepler_at_[hidden])
Date: 2021-01-13 12:59:32


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 list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups