Hi,
Here's an implementation of _Maxof & _Minof, as proposed in n3628. It
has not yet been accepted into C2y, but I wanted to have the
implementation ready before the next meeting, and possibly even merge it
before as a GNU extension.
I have some doubts about some code I copied from the sizeof
implementation (grep 'XXX' in the patch).
Joseph, would you mind reviewing? I guess you want to wait until the
next meeting before deciding if we want it as an extension or not.
Have a lovely night!
Alex
The patch set has passed regression testing, and also the tests I added
for the new feature:
alx@devuan:~/src/gnu/gcc/maxof$ git log --oneline gnu/master..maxof1
11d4b9b554d5 (HEAD -> maxof, tag: maxof1) c: Add _Maxof and _Minof
operators
a54651f69765 doc: Move _Countof under 'Other Extensions to C Syntax'
alx@devuan:~/src/gnu/gcc/maxof$ git reset gnu/master --h
HEAD is now at 65acf3665ea9 PR modula2/122241: Lack of spellng hints
with simple errors
alx@devuan:~/src/gnu/gcc/maxof$ mkdir ../maxof1
alx@devuan:~/src/gnu/gcc/maxof$ cd ../maxof1
alx@devuan:~/src/gnu/gcc/maxof1$ set -o pipefail
alx@devuan:~/src/gnu/gcc/maxof1$ /bin/time ../maxof/configure
--disable-multilib --prefix=/opt/local/gnu/gcc/maxof |& ts -s | tail -n3; echo
$?
00:00:01 config.status: creating Makefile
00:00:02 1.81user 0.53system 0:01.99elapsed 117%CPU (0avgtext+0avgdata
57440maxresident)k
00:00:02 6280inputs+9600outputs (2major+310789minor)pagefaults 0swaps
0
alx@devuan:~/src/gnu/gcc/maxof1$ /bin/time make -j12 bootstrap |& ts -s
| tail -n3; echo $?
00:28:11 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/maxof1'
00:28:11 14084.90user 342.32system 28:11.30elapsed 853%CPU
(0avgtext+0avgdata 1491644maxresident)k
00:28:11 355872inputs+49462768outputs
(6912major+131077539minor)pagefaults 0swaps
0
alx@devuan:~/src/gnu/gcc/maxof1$ /bin/time make -j12 check |& ts -s |
tail -n3; echo $?
00:48:39 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/maxof1'
00:48:39 31924.75user 2995.54system 48:39.69elapsed 1196%CPU
(0avgtext+0avgdata 1333016maxresident)k
00:48:39 520inputs+52283672outputs
(9324major+1206405254minor)pagefaults 0swaps
0
alx@devuan:~/src/gnu/gcc/maxof1$ cd ../maxof
alx@devuan:~/src/gnu/gcc/maxof$ git merge --ff-only maxof1
Updating 65acf3665ea9..11d4b9b554d5
Fast-forward
gcc/c-family/c-common.cc | 42 ++++++++++
gcc/c-family/c-common.def | 6 ++
gcc/c-family/c-common.h | 4 +-
gcc/c/c-parser.cc | 113
++++++++++++++++++++++++++-
gcc/c/c-tree.h | 2 +
gcc/c/c-typeck.cc | 54 +++++++++++++
gcc/doc/extend.texi | 81 +++++++++++--------
gcc/testsuite/gcc.dg/maxof-compat.c | 5 ++
gcc/testsuite/gcc.dg/maxof-compile.c | 110
++++++++++++++++++++++++++
gcc/testsuite/gcc.dg/maxof-no-compat.c | 5 ++
gcc/testsuite/gcc.dg/maxof-pedantic-errors.c | 5 ++
gcc/testsuite/gcc.dg/maxof-pedantic.c | 5 ++
12 files changed, 399 insertions(+), 33 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/maxof-compat.c
create mode 100644 gcc/testsuite/gcc.dg/maxof-compile.c
create mode 100644 gcc/testsuite/gcc.dg/maxof-no-compat.c
create mode 100644 gcc/testsuite/gcc.dg/maxof-pedantic-errors.c
create mode 100644 gcc/testsuite/gcc.dg/maxof-pedantic.c
alx@devuan:~/src/gnu/gcc/maxof$ cd ../
alx@devuan:~/src/gnu/gcc$ mv maxof1/ maxof1_b4
alx@devuan:~/src/gnu/gcc$ mkdir maxof1
alx@devuan:~/src/gnu/gcc$ cd maxof1
alx@devuan:~/src/gnu/gcc/maxof1$ /bin/time ../maxof/configure
--disable-multilib --prefix=/opt/local/gnu/gcc/maxof |& ts -s | tail -n3; echo
$?
00:00:01 config.status: creating Makefile
00:00:01 1.69user 0.45system 0:01.79elapsed 119%CPU (0avgtext+0avgdata
57448maxresident)k
00:00:01 5848inputs+9600outputs (0major+313627minor)pagefaults 0swaps
0
alx@devuan:~/src/gnu/gcc/maxof1$ /bin/time make -j12 bootstrap |& ts -s
| tail -n3; echo $?
00:28:15 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/maxof1'
00:28:15 14104.89user 388.76system 28:15.50elapsed 854%CPU
(0avgtext+0avgdata 1491644maxresident)k
00:28:15 1311184inputs+49461056outputs
(2153major+172379283minor)pagefaults 0swaps
0
alx@devuan:~/src/gnu/gcc/maxof1$ /bin/time make -j12 check |& ts -s |
tail -n3; echo $?
00:49:39 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/maxof1'
00:49:39 32347.97user 3269.62system 49:38.98elapsed 1195%CPU
(0avgtext+0avgdata 1332280maxresident)k
00:49:39 115240inputs+52484872outputs
(10191major+1584403142minor)pagefaults 0swaps
0
alx@devuan:~/src/gnu/gcc/maxof1$ find -type f | grep '\.sum$' | while
read f; do diff -u ../maxof1_b4/$f $f; done
--- ../maxof1_b4/./x86_64-pc-linux-gnu/libitm/testsuite/libitm.sum
2025-10-13 21:23:42.929590873 +0200
+++ ./x86_64-pc-linux-gnu/libitm/testsuite/libitm.sum 2025-10-13
22:55:18.687371458 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Mon Oct 13 21:23:40 2025
+Test run by alx on Mon Oct 13 22:55:16 2025
Native configuration is x86_64-pc-linux-gnu
=== libitm tests ===
---
../maxof1_b4/./x86_64-pc-linux-gnu/libatomic/testsuite/libatomic.sum
2025-10-13 21:23:42.342540543 +0200
+++ ./x86_64-pc-linux-gnu/libatomic/testsuite/libatomic.sum
2025-10-13 22:55:17.959695677 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Mon Oct 13 21:23:40 2025
+Test run by alx on Mon Oct 13 22:55:16 2025
Native configuration is x86_64-pc-linux-gnu
=== libatomic tests ===
--- ../maxof1_b4/./x86_64-pc-linux-gnu/libgomp/testsuite/libgomp.sum
2025-10-13 21:30:41.937612065 +0200
+++ ./x86_64-pc-linux-gnu/libgomp/testsuite/libgomp.sum 2025-10-13
22:59:04.188054815 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Mon Oct 13 21:23:41 2025
+Test run by alx on Mon Oct 13 22:55:16 2025
Native configuration is x86_64-pc-linux-gnu
=== libgomp tests ===
---
../maxof1_b4/./x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum
2025-10-13 22:12:19.789208443 +0200
+++ ./x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum
2025-10-13 23:44:54.778690064 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Mon Oct 13 21:23:41 2025
+Test run by alx on Mon Oct 13 22:55:17 2025
Native configuration is x86_64-pc-linux-gnu
=== libstdc++ tests ===
--- ../maxof1_b4/./gcc/testsuite/objc/objc.sum 2025-10-13
21:24:39.827103989 +0200
+++ ./gcc/testsuite/objc/objc.sum 2025-10-13 23:09:47.613172588
+0200
@@ -1,4 +1,4 @@
-Test run by alx on Mon Oct 13 21:23:41 2025
+Test run by alx on Mon Oct 13 23:08:42 2025
Native configuration is x86_64-pc-linux-gnu
=== objc tests ===
--- ../maxof1_b4/./gcc/testsuite/g++/g++.sum 2025-10-13
21:45:24.573888891 +0200
+++ ./gcc/testsuite/g++/g++.sum 2025-10-13 23:08:44.504307902 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Mon Oct 13 21:23:41 2025
+Test run by alx on Mon Oct 13 22:55:19 2025
Native configuration is x86_64-pc-linux-gnu
=== g++ tests ===
--- ../maxof1_b4/./gcc/testsuite/gcc/gcc.sum 2025-10-13
22:03:10.307987898 +0200
+++ ./gcc/testsuite/gcc/gcc.sum 2025-10-13 23:17:22.336798317 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Mon Oct 13 21:23:41 2025
+Test run by alx on Mon Oct 13 22:55:17 2025
Native configuration is x86_64-pc-linux-gnu
=== gcc tests ===
@@ -93948,6 +93948,37 @@
PASS: gcc.dg/max-1.c execution test
PASS: gcc.dg/max.c (test for excess errors)
PASS: gcc.dg/max.c scan-tree-dump-not optimized "MAX_EXPR"
+PASS: gcc.dg/maxof-compat.c (test for warnings, line 4)
+PASS: gcc.dg/maxof-compat.c (test for warnings, line 5)
+PASS: gcc.dg/maxof-compat.c (test for excess errors)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 100)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 106)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 107)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 108)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 109)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 77)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 78)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 79)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 80)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 81)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 82)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 83)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 84)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 93)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 94)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 95)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 96)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 97)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 98)
+PASS: gcc.dg/maxof-compile.c (test for errors, line 99)
+PASS: gcc.dg/maxof-compile.c (test for excess errors)
+PASS: gcc.dg/maxof-no-compat.c (test for excess errors)
+PASS: gcc.dg/maxof-pedantic-errors.c (test for errors, line 4)
+PASS: gcc.dg/maxof-pedantic-errors.c (test for errors, line 5)
+PASS: gcc.dg/maxof-pedantic-errors.c (test for excess errors)
+PASS: gcc.dg/maxof-pedantic.c (test for warnings, line 4)
+PASS: gcc.dg/maxof-pedantic.c (test for warnings, line 5)
+PASS: gcc.dg/maxof-pedantic.c (test for excess errors)
PASS: gcc.dg/memchr-2.c (test for excess errors)
PASS: gcc.dg/memchr-2.c scan-tree-dump-not optimized "abort"
PASS: gcc.dg/memchr-2.c scan-tree-dump-not optimized "memcmp \\("
@@ -220279,7 +220310,7 @@
=== gcc Summary ===
-# of expected passes 214228
+# of expected passes 214259
# of unexpected failures 527
# of unexpected successes 2
# of expected failures 1481
--- ../maxof1_b4/./gcc/testsuite/gfortran/gfortran.sum 2025-10-13
21:49:53.980429032 +0200
+++ ./gcc/testsuite/gfortran/gfortran.sum 2025-10-13
23:24:46.371044649 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Mon Oct 13 21:23:41 2025
+Test run by alx on Mon Oct 13 23:08:40 2025
Native configuration is x86_64-pc-linux-gnu
=== gfortran tests ===
Alejandro Colomar (2):
doc: Move _Countof under 'Other Extensions to C Syntax'
c: Add _Maxof and _Minof operators
gcc/c-family/c-common.cc | 42 +++++++
gcc/c-family/c-common.def | 6 +
gcc/c-family/c-common.h | 4 +-
gcc/c/c-parser.cc | 113 ++++++++++++++++++-
gcc/c/c-tree.h | 2 +
gcc/c/c-typeck.cc | 54 +++++++++
gcc/doc/extend.texi | 81 ++++++++-----
gcc/testsuite/gcc.dg/maxof-compat.c | 5 +
gcc/testsuite/gcc.dg/maxof-compile.c | 110 ++++++++++++++++++
gcc/testsuite/gcc.dg/maxof-no-compat.c | 5 +
gcc/testsuite/gcc.dg/maxof-pedantic-errors.c | 5 +
gcc/testsuite/gcc.dg/maxof-pedantic.c | 5 +
12 files changed, 399 insertions(+), 33 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/maxof-compat.c
create mode 100644 gcc/testsuite/gcc.dg/maxof-compile.c
create mode 100644 gcc/testsuite/gcc.dg/maxof-no-compat.c
create mode 100644 gcc/testsuite/gcc.dg/maxof-pedantic-errors.c
create mode 100644 gcc/testsuite/gcc.dg/maxof-pedantic.c
Range-diff against v0:
-: ------------ > 1: a54651f69765 doc: Move _Countof under 'Other Extensions
to C Syntax'
-: ------------ > 2: 11d4b9b554d5 c: Add _Maxof and _Minof operators
--
2.51.0