void main()
{
assert(false);
}
dmd -release a.d
dmd version 2.109.1
debian bookworm x64
illegal instruction
thanks
Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 11 assert | ||||
---|---|---|---|---|
| ||||
void main() dmd -release a.d dmd version 2.109.1 illegal instruction thanks |
September 11 Re: assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to f | i mean , is this a bug? |
September 11 Re: assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to f | On Tuesday, September 10, 2024 10:01:53 PM MDT f via Digitalmars-d-learn wrote:
> i mean , is this a bug?
No, it's not a bug. Assertions with an expression that is known to be false at compile time are treated as special. They are always left in the generated code so that they will kill your program if you ever hit that line of code.
So, assertions which actually need to be validated at runtime will be compiled out with -release, but assert(false) is always there, and with -release, instead of throwing an AssertError, it immediately terminates the program.
One common use case for this would be something like
auto foo(int i) nothrow
{
try
{
...
}
catch(Exception)
{
assert(false, "It should be impossible for this code to throw.");
}
}
where you have code that you know will never throw given the input that you're giving it, but it's not nothrow, because it could throw under other circumstances. And so in order to call that code within a nothrow function, you wrap it in a try-catch block, and then just in case you screwed up, and it does somehow throw, the assertion is triggered even with -release, and your program is terminated instead of continuing in an invalid state.
- Jonathan M Davis
|
September 11 Re: assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Wednesday, 11 September 2024 at 06:07:26 UTC, Jonathan M Davis wrote:
> On Tuesday, September 10, 2024 10:01:53 PM MDT f via Digitalmars-d-learn wrote:
>> i mean , is this a bug?
>
> No, it's not a bug.
It is a bug, don't claim it is not, the compiler gives the wrong information, wich lead to a confused user
You don't want confused users, you want compiler say what's up, if i type assert, it should assert, end of the story
|
September 11 Re: assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to ryuukk_ | On Wednesday, 11 September 2024 at 08:08:45 UTC, ryuukk_ wrote: > It is a bug, don't claim it is not, the compiler gives the wrong information, wich lead to a confused user > > You don't want confused users, you want compiler say what's up, if i type assert, it should assert, end of the story The behaviour is by design, it is not a bug, it is documented in the spec: https://dlang.org/spec/expression.html#assert-ct |
September 11 Re: assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Treleaven | On Wednesday, 11 September 2024 at 09:14:39 UTC, Nick Treleaven wrote:
> On Wednesday, 11 September 2024 at 08:08:45 UTC, ryuukk_ wrote:
>> It is a bug, don't claim it is not, the compiler gives the wrong information, wich lead to a confused user
>>
>> You don't want confused users, you want compiler say what's up, if i type assert, it should assert, end of the story
>
> The behaviour is by design, it is not a bug, it is documented in the spec:
> https://dlang.org/spec/expression.html#assert-ct
Oh right, "illegal instruction" is what users should read in order to "fix" their code
I again apologies for being wrong and i apologies again for trying to improve things, i didn't meant to do that, i now may leave again
|
September 11 Re: assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to ryuukk_ | On Wednesday, 11 September 2024 at 10:08:29 UTC, ryuukk_ wrote:
> On Wednesday, 11 September 2024 at 09:14:39 UTC, Nick Treleaven wrote:
>> On Wednesday, 11 September 2024 at 08:08:45 UTC, ryuukk_ wrote:
>>> It is a bug, don't claim it is not, the compiler gives the wrong information, wich lead to a confused user
>>>
>>> You don't want confused users, you want compiler say what's up, if i type assert, it should assert, end of the story
>>
>> The behaviour is by design, it is not a bug, it is documented in the spec:
>> https://dlang.org/spec/expression.html#assert-ct
>
>
> Oh right, "illegal instruction" is what users should read in order to "fix" their code
>
> I again apologies for being wrong and i apologies again for trying to improve things, i didn't meant to do that, i now may leave again
You can say that the error message is weird with -release, but it's not a bug.
|
September 11 Re: assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to ryuukk_ | I don't care about whether it's a bug or not, I just want to learn What illegal instructions did this "assert(false);" code create? |
September 11 Re: assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fox | On Wednesday, 11 September 2024 at 12:17:02 UTC, Fox wrote: > I don't care about whether it's a bug or not, I just want to learn What illegal instructions did this "assert(false);" code create? Fortunately Godbolt supports D, so it's easy to see that it generates `ud2` on x86(_64): https://godbolt.org/z/4zq67boMW |
September 12 Re: assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bradley Chatha | On Wednesday, 11 September 2024 at 16:40:05 UTC, Bradley Chatha wrote:
> On Wednesday, 11 September 2024 at 12:17:02 UTC, Fox wrote:
>> I don't care about whether it's a bug or not, I just want to learn What illegal instructions did this "assert(false);" code create?
>
> Fortunately Godbolt supports D, so it's easy to see that it generates `ud2` on x86(_64): https://godbolt.org/z/4zq67boMW
This is great, thanks.
|