[Cfp-interest 2250] Re: Usual arithmetic conversions on unordered (unmixable) types

Jim Thomas jaswthomas at sbcglobal.net
Mon Nov 1 14:45:34 PDT 2021


This might be a good idea, but as I understand it WG14’s window for new proposals for C23 has closed. 

- Jim Thomas

> On Oct 25, 2021, at 1:39 AM, Vincent Lefevre <vincent at vinc17.net> wrote:
> 
> In N2601 about X.4.2 "Usual arithmetic conversions":
> 
>  If both operands have floating types and neither of the sets
>  of values of their corresponding real types is a subset of
>  (or equivalent to) the other, the behavior is undefined.
> 
> Instead of basic undefined behavior, shouldn't the concept of
> ordered / mixable arithmetic types be introduced? The goal would
> be to get a constraint violation in case of unordered / unmixable
> arithmetic types (thus requiring a diagnostic), a bit like what
> one gets with pointers in conditional expressions.
> 
> Then text like
> 
>  both operands have arithmetic type
> 
> in constraints would be replaced by
> 
>  both operands have ordered/mixable arithmetic type
> 
> Thus
> 
>  i ? (double) 0 : (_Decimal64) 0
> 
> would yield a constraint violation, just like
> 
>  i ? (int *) 0 : (long *) 0
> 
> FYI, on the following C code
> 
> void foo (int i)
> {
>  (void) (i ? (int *) 0 : (long *) 0);
>  (void) (i ? (double) 0 : (_Decimal64) 0);
> }
> 
> GCC gives
> 
> tst.c: In function 'foo':
> tst.c:3:25: warning: pointer type mismatch in conditional expression
>    3 |   (void) (i ? (int *) 0 : (long *) 0);
>      |                         ^
> tst.c:4:3: error: cannot mix operands of decimal floating and other floating types
>    4 |   (void) (i ? (double) 0 : (_Decimal64) 0);
>      |   ^
> 
> -- 
> Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
> _______________________________________________
> Cfp-interest mailing list
> Cfp-interest at oakapple.net
> http://mailman.oakapple.net/mailman/listinfo/cfp-interest




More information about the Cfp-interest mailing list