Checks
Commit Message
Hi!
The following patch (on top of the stdckdint.h patch and _BitInt patch
series) adds a test for _BitInt diagnostics of ckd_{add,sub,mul} macros.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2023-08-10 Jakub Jelinek <jakub@redhat.com>
* gcc.dg/stdckdint-3.c: New test.
Jakub
Comments
On Thu, 10 Aug 2023, Jakub Jelinek via Gcc-patches wrote:
> Hi!
>
> The following patch (on top of the stdckdint.h patch and _BitInt patch
> series) adds a test for _BitInt diagnostics of ckd_{add,sub,mul} macros.
I remain unconvinced that diagnosing use with types where it's clear what
the right semantics for the operation are is a good idea (given, in the
_BitInt case, that you've already implemented the built-in functions for
_BitInt types). (Diagnosing for bool results *is* a good idea, since it's
not clear what the semantics should be. Likewise for enums with fixed
underlying type bool, whether or not it's diagnosed for other enums.)
@@ -0,0 +1,21 @@
+/* Test C23 Checked Integer Arithmetic macros in <stdckdint.h>. */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c2x" } */
+
+#include <stdckdint.h>
+
+int
+main ()
+{
+ _BitInt(32) a;
+ int b;
+ ckd_add (&a, 1, 1); /* { dg-error "types used in ckd_add should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+ ckd_sub (&a, 1, 1); /* { dg-error "types used in ckd_sub should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+ ckd_mul (&a, 1, 1); /* { dg-error "types used in ckd_mul should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+ ckd_add (&b, 1wb, 1); /* { dg-error "types used in ckd_add should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+ ckd_sub (&b, 1wb, 1); /* { dg-error "types used in ckd_sub should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+ ckd_mul (&b, 1wb, 1); /* { dg-error "types used in ckd_mul should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+ ckd_add (&b, 1, 1wb); /* { dg-error "types used in ckd_add should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+ ckd_sub (&b, 1, 1wb); /* { dg-error "types used in ckd_sub should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+ ckd_mul (&b, 1, 1wb); /* { dg-error "types used in ckd_mul should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+}