Hi,

Changes in v4:

-  Fix accident from conflict resolution I introduced in v3.  I had
   accidentally removed a line from the documentation.  This showed up
   while testing, but I should have been able to see it in the
   range-diff in v3.

-  Use _Static_assert(3) instead of defining must_be() in the tests, as
   _Static_assert(3) can now be used within an expression.

This passes regression testing on my computer:

        alx@devuan:~/src/gnu/gcc/countof_ap$ git log --oneline gnu/master^..cap4
        a778f22f412f (HEAD -> countof_ap, tag: cap4) c: Add support for array 
parameters in _Countof
        0dfe0f263bd8 (gnu/trunk, gnu/master, gnu/HEAD, master) c++/reflection: 
enable more testing
        alx@devuan:~/src/gnu/gcc/countof_ap$ git reset gnu/master --h
        HEAD is now at 0dfe0f263bd8 c++/reflection: enable more testing
        alx@devuan:~/src/gnu/gcc/countof_ap$ mkdir ../cap4
        alx@devuan:~/src/gnu/gcc/countof_ap$ cd ../cap4/
        alx@devuan:~/src/gnu/gcc/cap4$ set -o pipefail
        alx@devuan:~/src/gnu/gcc/cap4$ ../countof_ap/configure 
--disable-multilib --prefix=/opt/local/gnu/gcc/cap4 |& ts -s | tail -n1; echo 
$?; make -j24 bootstrap |& ts -s | tail -n1; echo $?; make -j24 check |& ts -s 
| tail -n1; echo $?;
        00:00:02 config.status: creating Makefile
        0
        00:24:32 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/cap4'
        0
        00:40:27 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/cap4'
        0
        alx@devuan:~/src/gnu/gcc/cap4$ cd ../countof_ap/
        alx@devuan:~/src/gnu/gcc/countof_ap$ git merge --ff-only cap4
        Updating 0dfe0f263bd8..a778f22f412f
        Fast-forward
         gcc/c/c-typeck.cc                             | 50 +++++++++++---
         gcc/doc/extend.texi                           | 11 ++++
         gcc/testsuite/gcc.dg/countof-compile.c        |  8 +--
         gcc/testsuite/gcc.dg/countof-param-compile.c  | 66 +++++++++++++++++++
         gcc/testsuite/gcc.dg/countof-param-pedantic.c | 11 ++++
         gcc/testsuite/gcc.dg/countof-param.c          | 25 +++++++
         6 files changed, 156 insertions(+), 15 deletions(-)
         create mode 100644 gcc/testsuite/gcc.dg/countof-param-compile.c
         create mode 100644 gcc/testsuite/gcc.dg/countof-param-pedantic.c
         create mode 100644 gcc/testsuite/gcc.dg/countof-param.c
        alx@devuan:~/src/gnu/gcc/countof_ap$ cd ../
        alx@devuan:~/src/gnu/gcc$ mv cap4/ cap4_b4
        alx@devuan:~/src/gnu/gcc$ mkdir cap4
        alx@devuan:~/src/gnu/gcc$ cd cap4
        alx@devuan:~/src/gnu/gcc/cap4$ ../countof_ap/configure 
--disable-multilib --prefix=/opt/local/gnu/gcc/cap4 |& ts -s | tail -n1; echo 
$?; make -j24 bootstrap |& ts -s | tail -n1; echo $?; make -j24 check |& ts -s 
| tail -n1; echo $?;
        00:00:01 config.status: creating Makefile
        0
        00:24:12 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/cap4'
        0
        00:41:05 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/cap4'
        0
        alx@devuan:~/src/gnu/gcc/cap4$ find -type f | grep '\.sum$' | while 
read f; do diff -u "../cap4_b4/$f" "$f"; done;
        --- ../cap4_b4/./x86_64-pc-linux-gnu/libitm/testsuite/libitm.sum        
2026-01-19 00:27:08.910102082 +0100
        +++ ./x86_64-pc-linux-gnu/libitm/testsuite/libitm.sum   2026-01-19 
14:36:03.991144437 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Mon Jan 19 00:27:05 2026
        +Test run by alx on Mon Jan 19 14:36:00 2026
         Native configuration is x86_64-pc-linux-gnu
         
                        === libitm tests ===
        --- ../cap4_b4/./x86_64-pc-linux-gnu/libatomic/testsuite/libatomic.sum  
2026-01-19 00:27:07.708143963 +0100
        +++ ./x86_64-pc-linux-gnu/libatomic/testsuite/libatomic.sum     
2026-01-19 14:36:02.234565567 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Mon Jan 19 00:27:05 2026
        +Test run by alx on Mon Jan 19 14:36:00 2026
         Native configuration is x86_64-pc-linux-gnu
         
                        === libatomic tests ===
        --- ../cap4_b4/./x86_64-pc-linux-gnu/libgomp/testsuite/libgomp.sum      
2026-01-19 00:29:50.063018848 +0100
        +++ ./x86_64-pc-linux-gnu/libgomp/testsuite/libgomp.sum 2026-01-19 
14:38:49.774302647 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Mon Jan 19 00:27:06 2026
        +Test run by alx on Mon Jan 19 14:36:00 2026
         Native configuration is x86_64-pc-linux-gnu
         
                        === libgomp tests ===
        --- 
../cap4_b4/./x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum       
2026-01-19 01:07:32.287692931 +0100
        +++ ./x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum  
2026-01-19 15:17:05.209583849 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Mon Jan 19 00:27:07 2026
        +Test run by alx on Mon Jan 19 14:36:01 2026
         Native configuration is x86_64-pc-linux-gnu
         
                        === libstdc++ tests ===
        --- ../cap4_b4/./gcc/testsuite/objc/objc.sum    2026-01-19 
00:28:22.913048499 +0100
        +++ ./gcc/testsuite/objc/objc.sum       2026-01-19 14:37:17.539158089 
+0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Mon Jan 19 00:27:06 2026
        +Test run by alx on Mon Jan 19 14:36:01 2026
         Native configuration is x86_64-pc-linux-gnu
         
                        === objc tests ===
        --- ../cap4_b4/./gcc/testsuite/g++/g++.sum      2026-01-19 
00:41:33.544392776 +0100
        +++ ./gcc/testsuite/g++/g++.sum 2026-01-19 14:55:10.737332886 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Mon Jan 19 00:27:06 2026
        +Test run by alx on Mon Jan 19 14:36:01 2026
         Native configuration is x86_64-pc-linux-gnu
         
                        === g++ tests ===
        --- ../cap4_b4/./gcc/testsuite/gcc/gcc.sum      2026-01-19 
00:53:43.080199886 +0100
        +++ ./gcc/testsuite/gcc/gcc.sum 2026-01-19 15:05:32.767784479 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Mon Jan 19 00:27:06 2026
        +Test run by alx on Mon Jan 19 14:36:01 2026
         Native configuration is x86_64-pc-linux-gnu
         
                        === gcc tests ===
        @@ -90189,27 +90189,53 @@
         PASS: gcc.dg/counted-by-anonymous.c (test for excess errors)
         PASS: gcc.dg/countof-compat.c  (test for warnings, line 8)
         PASS: gcc.dg/countof-compat.c (test for excess errors)
        -PASS: gcc.dg/countof-compile.c  (test for errors, line 114)
        -PASS: gcc.dg/countof-compile.c  (test for errors, line 123)
        +PASS: gcc.dg/countof-compile.c  (test for errors, line 108)
        +PASS: gcc.dg/countof-compile.c  (test for errors, line 117)
         PASS: gcc.dg/countof-compile.c  (test for errors, line 23)
        -PASS: gcc.dg/countof-compile.c  (test for errors, line 27)
        -PASS: gcc.dg/countof-compile.c  (test for errors, line 38)
        -PASS: gcc.dg/countof-compile.c  (test for errors, line 46)
        +PASS: gcc.dg/countof-compile.c  (test for errors, line 34)
        +PASS: gcc.dg/countof-compile.c  (test for errors, line 40)
        +PASS: gcc.dg/countof-compile.c  (test for errors, line 58)
        +PASS: gcc.dg/countof-compile.c  (test for errors, line 61)
         PASS: gcc.dg/countof-compile.c  (test for errors, line 64)
        -PASS: gcc.dg/countof-compile.c  (test for errors, line 67)
        -PASS: gcc.dg/countof-compile.c  (test for errors, line 70)
        +PASS: gcc.dg/countof-compile.c  (test for errors, line 76)
        +PASS: gcc.dg/countof-compile.c  (test for errors, line 77)
        +PASS: gcc.dg/countof-compile.c  (test for errors, line 78)
        +PASS: gcc.dg/countof-compile.c  (test for errors, line 79)
        +PASS: gcc.dg/countof-compile.c  (test for errors, line 80)
        +PASS: gcc.dg/countof-compile.c  (test for errors, line 81)
         PASS: gcc.dg/countof-compile.c  (test for errors, line 82)
         PASS: gcc.dg/countof-compile.c  (test for errors, line 83)
         PASS: gcc.dg/countof-compile.c  (test for errors, line 84)
        -PASS: gcc.dg/countof-compile.c  (test for errors, line 85)
        -PASS: gcc.dg/countof-compile.c  (test for errors, line 86)
        -PASS: gcc.dg/countof-compile.c  (test for errors, line 87)
         PASS: gcc.dg/countof-compile.c  (test for errors, line 88)
        -PASS: gcc.dg/countof-compile.c  (test for errors, line 89)
        -PASS: gcc.dg/countof-compile.c  (test for errors, line 90)
        -PASS: gcc.dg/countof-compile.c  (test for errors, line 94)
         PASS: gcc.dg/countof-compile.c (test for excess errors)
         PASS: gcc.dg/countof-no-compat.c (test for excess errors)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 10)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 18)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 21)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 22)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 27)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 28)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 29)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 30)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 31)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 32)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 33)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 34)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 38)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 42)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 57)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 8)
        +PASS: gcc.dg/countof-param-compile.c  (test for errors, line 9)
        +PASS: gcc.dg/countof-param-compile.c (test for excess errors)
        +PASS: gcc.dg/countof-param-pedantic.c  (test for warnings, line 10)
        +PASS: gcc.dg/countof-param-pedantic.c  (test for warnings, line 9)
        +PASS: gcc.dg/countof-param-pedantic.c (test for excess errors)
        +PASS: gcc.dg/countof-param.c  (test for warnings, line 10)
        +PASS: gcc.dg/countof-param.c  (test for warnings, line 15)
        +PASS: gcc.dg/countof-param.c  (test for warnings, line 16)
        +PASS: gcc.dg/countof-param.c  (test for warnings, line 9)
        +PASS: gcc.dg/countof-param.c (test for excess errors)
        +PASS: gcc.dg/countof-param.c execution test
         PASS: gcc.dg/countof-pedantic-errors.c  (test for errors, line 8)
         PASS: gcc.dg/countof-pedantic-errors.c (test for excess errors)
         PASS: gcc.dg/countof-pedantic.c  (test for warnings, line 8)
        @@ -222443,7 +222469,7 @@
         
                        === gcc Summary ===
         
        -# of expected passes           216291
        +# of expected passes           216317
         # of unexpected failures       527
         # of unexpected successes      6
         # of expected failures         1537
        --- ../cap4_b4/./gcc/testsuite/gfortran/gfortran.sum    2026-01-19 
00:35:03.196383237 +0100
        +++ ./gcc/testsuite/gfortran/gfortran.sum       2026-01-19 
14:46:37.349486800 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Mon Jan 19 00:27:06 2026
        +Test run by alx on Mon Jan 19 14:36:01 2026
         Native configuration is x86_64-pc-linux-gnu
         
                        === gfortran tests ===

Have a lovely day!
Alex


Alejandro Colomar (1):
  c: Add support for array parameters in _Countof

 gcc/c/c-typeck.cc                             | 50 +++++++++++---
 gcc/doc/extend.texi                           | 11 ++++
 gcc/testsuite/gcc.dg/countof-compile.c        |  8 +--
 gcc/testsuite/gcc.dg/countof-param-compile.c  | 66 +++++++++++++++++++
 gcc/testsuite/gcc.dg/countof-param-pedantic.c | 11 ++++
 gcc/testsuite/gcc.dg/countof-param.c          | 25 +++++++
 6 files changed, 156 insertions(+), 15 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/countof-param-compile.c
 create mode 100644 gcc/testsuite/gcc.dg/countof-param-pedantic.c
 create mode 100644 gcc/testsuite/gcc.dg/countof-param.c

Range-diff against v3:
1:  345284f5de11 ! 1:  a778f22f412f c: Add support for array parameters in 
_Countof
    @@ gcc/doc/extend.texi: _Countof (int [7][n++]);  // integer constant 
expression
     +@{
     +  assert(n == _Countof(a));
     +@}
    ++@end smallexample
     +
      @node _Maxof and _Minof
      @subsection The maximum and minimum representable values of a type
    @@ gcc/testsuite/gcc.dg/countof-param-compile.c (new)
     +
     +#define NULL ((void *) 0)
     +
    -+#define must_be(e)                                                    \
    -+(                                                                     \
    -+  0 * (int) sizeof                                                    \
    -+    (                                                                 \
    -+      struct must_be                                                  \
    -+        {                                                             \
    -+          _Static_assert (e, "");                                     \
    -+          int ISO_C_forbids_a_struct_with_no_members;                 \
    -+        }                                                             \
    -+    )                                                                 \
    -+)
    -+
     +int f1 (int  , int a[2]) { return _Countof (a); }
     +int f2 (int n, int a[n]) { return _Countof (a); }
     +int f3 (int  , int a[*]) { return _Countof (a); }  /* { dg-error "not 
allowed in other than function prototype scope" } */
    @@ gcc/testsuite/gcc.dg/countof-param-compile.c (new)
     +int g2 (int n, int a[n], int b[_Countof (a)]) { return _Countof (b); }
     +int g3 (int  , int a[*], int b[_Countof (a)]) { return _Countof (b); }  
/* { dg-error "not allowed in other than function prototype scope" } */
     +
    -+int h1 (int  , int a[2], int b[7 + must_be (_Countof (a) == 2)]);
    -+int h2 (int n, int a[n], int b[7 + must_be (_Countof (a) == 2)]);  /* { 
dg-error "expression in static assertion is not constant" } */
    -+int h3 (int  , int a[*], int b[7 + must_be (_Countof (a) == 2)]);  /* { 
dg-error "expression in static assertion is not constant" } */
    ++int h1 (int  , int a[2], int b[(_Static_assert (_Countof (a) == 2), 7)]);
    ++int h2 (int n, int a[n], int b[(_Static_assert (_Countof (a) == 2), 7)]); 
 /* { dg-error "expression in static assertion is not constant" } */
    ++int h3 (int  , int a[*], int b[(_Static_assert (_Countof (a) == 2), 7)]); 
 /* { dg-error "expression in static assertion is not constant" } */
     +
     +void
     +decay_obvious (int a[2])

base-commit: a440b382e43203857de9195eb526c4a16f21ceb1
-- 
2.51.0

Reply via email to