C++ Logo

std-proposals

Advanced search

Re: std::error magic function

From: connor horman <chorman64_at_[hidden]>
Date: Thu, 26 Mar 2020 12:43:19 -0400
static_assert also doesn't allow conditional checks where the condition may
not be a constant expression (parameter to constexpr functions).

I've also added a motivating example to the document

On Thu, 26 Mar 2020 at 04:24, Garrett May via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> static_assert can allow constant expressions to report errors. However,
> the message that can be passed to it must be a string literal. It can't
> even be a string evaluated at compile time - which results in the error
> messages not being as helpful as they could be.
>
>
>
> On Thu, 26 Mar 2020, 8:14 am Michał Policht via Std-Proposals, <
> std-proposals_at_[hidden]> wrote:
>
>> From your paper:
>> > However, a general issue is that constant expressions cannot report
>> errors when failure would occur
>>
>> Isn't `static_assert` a mechanism, which allows constant expressions to
>> report errors?
>>
>> Regards,
>> Michał
>>
>>
>> > I've done some work on this, and wrote a draft paper
>> > <
>> https://github.com/chorman0773/CXX-Papers/blob/master/std_error_function.md
>> >.
>> > I am interested in any feedback.
>> > I decided on a similar function, std::compiler_error, which has the same
>> > compile time behavior, but its UB at runtime. This would allow users to
>> > write std::error, with whatever runtime behavior they wish.
>> > I would be interested in any feedback people have, both on the
>> > semantics, and in the structure of the paper itself.
>> > Thank you to the great people on the std-proposals mailing list.
>> >
>> > On Fri, 6 Mar 2020 at 11:07, connor horman <chorman64_at_[hidden]
>> > <mailto:chorman64_at_[hidden]>> wrote:
>> >
>> > constinit won't downgrade (as the standard requires a constant
>> > expression initializer). I did forget about that.
>> >
>> > On Fri, 6 Mar 2020 at 10:13, Thiago Macieira via Std-Proposals
>> > <std-proposals_at_[hidden]
>> > <mailto:std-proposals_at_[hidden]>> wrote:
>> >
>> > On Friday, 6 March 2020 06:46:56 PST connor horman via
>> > Std-Proposals wrote:
>> > > Currently it is not possible to implement std::error in a way
>> > that it will
>> > > work with initializing non-constexpr variables. Throwing an
>> > exception
>> > > simply downgrades to runtime, only erroring if the result is
>> > needed at
>> > > compile time.
>> >
>> > Does that also apply to constinit variables?
>> >
>> > --
>> > Thiago Macieira - thiago (AT) macieira.info
>> > <http://macieira.info> - thiago (AT) kde.org <http://kde.org>
>> > Software Architect - Intel System Software Products
>> >
>> >
>> >
>> > --
>> > Std-Proposals mailing list
>> > Std-Proposals_at_[hidden]
>> > <mailto:Std-Proposals_at_[hidden]>
>> > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>> >
>> >
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2020-03-26 11:46:22