Unspecified Condition

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Unspecified Condition

Vassil Vassilev via cfe-dev
Hello Team,
I just wanted to understand, If any condition is unspecified (for example comparison between fixed point and floating point), do we need to handle unspecified cases in code OR we should not keep such cases in our program?

Regards,
Nadaf.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Unspecified Condition

Vassil Vassilev via cfe-dev
Your program's behavior probably shouldn't depend on any specific
unspecified behavior.
Sometimes it's not possible to avoid invoking unspecified behavior.
For instance - the evaluation order for function arguments is
unspecified, so in "f1(f2(), f3())" it's unspecified whether f2() or
f3() is run first - you can't really /avoid/ that unspecified behavior
if you're writing C++ (maybe you could write "auto &&x = f2(); auto
&&y = f3(); f1(std::move(x), std::move(y)); but implicit conversions,
by-value copies/moves, etc, would still trip this up) - the only thing
to do is ensure that your program does what you want/produces the same
result no matter whether f2 or f3 is run first.

On Sun, Jun 14, 2020 at 11:16 AM Gousemoodhin Nadaf via cfe-dev
<[hidden email]> wrote:

>
> Hello Team,
> I just wanted to understand, If any condition is unspecified (for example comparison between fixed point and floating point), do we need to handle unspecified cases in code OR we should not keep such cases in our program?
>
> Regards,
> Nadaf.
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Unspecified Condition

Vassil Vassilev via cfe-dev
In the context of the question (or at least, the OP's original intent for the question😊 ):

A compiler crashing is not a valid unspecified behavior.  We should be properly handling it, but it DOES mean that the result we give isn't guaranteed by the standard.  We don't have a way in the compiler of saying "the result of this expression is unspecified", it just means we have a little more freedom with what the behavior IS!

So yes, we do need to handle this in the compiler, we shouldn't allow it to continue crashing, and we can choose among a number of behaviors permitted by the standard.

-----Original Message-----
From: cfe-dev <[hidden email]> On Behalf Of David Blaikie via cfe-dev
Sent: Sunday, June 14, 2020 2:12 PM
To: Gousemoodhin Nadaf <[hidden email]>
Cc: Clang Dev <[hidden email]>
Subject: Re: [cfe-dev] Unspecified Condition

Your program's behavior probably shouldn't depend on any specific unspecified behavior.
Sometimes it's not possible to avoid invoking unspecified behavior.
For instance - the evaluation order for function arguments is unspecified, so in "f1(f2(), f3())" it's unspecified whether f2() or
f3() is run first - you can't really /avoid/ that unspecified behavior if you're writing C++ (maybe you could write "auto &&x = f2(); auto &&y = f3(); f1(std::move(x), std::move(y)); but implicit conversions, by-value copies/moves, etc, would still trip this up) - the only thing to do is ensure that your program does what you want/produces the same result no matter whether f2 or f3 is run first.

On Sun, Jun 14, 2020 at 11:16 AM Gousemoodhin Nadaf via cfe-dev <[hidden email]> wrote:

>
> Hello Team,
> I just wanted to understand, If any condition is unspecified (for example comparison between fixed point and floating point), do we need to handle unspecified cases in code OR we should not keep such cases in our program?
>
> Regards,
> Nadaf.
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev