www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - assert

reply f <f abc.com> writes:
void main()
{
assert(false);
}

dmd -release a.d

dmd version 2.109.1
debian bookworm x64

illegal instruction

thanks
Sep 10
parent reply f <f abc.com> writes:
i mean , is this a bug?
Sep 10
next sibling parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
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
Sep 10
parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
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
Sep 11
next sibling parent reply Nick Treleaven <nick geany.org> writes:
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
Sep 11
parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
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
Sep 11
next sibling parent Kapendev <alexandroskapretsos gmail.com> writes:
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.
Sep 11
prev sibling parent reply user1234 <user1234 12.de> writes:
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:
[...] 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
Oh no please stay, your unrecognisable passive aggressive style is so useful.
Sep 12
parent Andy Valencia <dont spam.me> writes:
On Thursday, 12 September 2024 at 22:34:04 UTC, user1234 wrote:
 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:
[...] 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
Oh no please stay, your unrecognisable passive aggressive style is so useful.
To put it more gently, ryuukk--and following the generally congenial and informative flavor of communications here--you may not realize that your messages have an abrasive feel to them. It really does make a difference to be polite and even respectful when people seek to help you by answering your questions. Showing gratitude makes it much more likely that these valuable contributors stay around and answer newbie questions in the future. Andy
Sep 12
prev sibling parent reply Fox <linuxl4 sohu.com> writes:
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?
Sep 11
parent reply Bradley Chatha <sealabjaster gmail.com> writes:
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
Sep 11
parent Fox <linuxl4 sohu.com> writes:
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.
Sep 11
prev sibling parent Salih Dincer <salihdb hotmail.com> writes:
On Wednesday, 11 September 2024 at 04:01:53 UTC, f wrote:
 i mean , is this a bug?
This is not a bug. The problem is due to a misunderstanding of the -release parameter. The following related topic opened by Steven and the answers given by Walter are really valuable: https://forum.dlang.org/thread/pkeasakdbugctqdyetnw forum.dlang.org SDB 79
Sep 12