]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Process C23 #elifdef and #elifndef
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 15 Jun 2024 15:24:05 +0000 (08:24 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 15 Jun 2024 15:27:03 +0000 (08:27 -0700)
Inspired by Collin Funk’s suggestion in:
https://lists.gnu.org/r/autoconf-patches/2024-06/msg00000.html
* bin/autom4te.in (handle_output):
* bin/autoscan.in, bin/ifnames.in (scan_c_file):
Also recognize #elifdef and #elifndef.
* tests/tools.at (ifnames): Test it for ifnames.

NEWS
bin/autom4te.in
bin/autoscan.in
bin/ifnames.in
doc/autoconf.texi
tests/tools.at

diff --git a/NEWS b/NEWS
index 521bbd3a3123b7adea54a53bf7afd4630a158ba9..bca113911c6b3241df9f72e9d204375b23ce6702 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,12 @@ GNU Autoconf NEWS - User visible changes.
   This reverts to Autoconf 2.69 behavior, and also fixes a bug where
   AC_PROG_CXX rejected C++20 compilers.
 
+** New features
+
+*** Programs now recognize #elifdef and #elifndef.
+  The autom4te, autoscan and ifnames programs now recognize the two
+  preprocessor directives, which were introduced in C23 and C++23.
+
 * Noteworthy changes in release 2.72 (2023-12-22) [release]
 
 ** Backward incompatibilities
index e9fa188638a23bf9e55075919241faf8fd34081f..48377cb91efd99b9f89020c774d2ea3dec981b77 100644 (file)
@@ -636,7 +636,7 @@ sub handle_output ($$)
       # Don't complain in comments.  Well, until we have something
       # better, don't consider '#include' etc. are comments.
       s/\#.*//
-       unless /^\#\s*(if|include|endif|ifdef|ifndef|define)\b/;
+       unless /^\#\s*(include|endif|(el)?if(n?def)?|define)\b/;
       foreach (split (/\W+/))
        {
          $prohibited{$_} = $.
@@ -673,7 +673,7 @@ sub handle_output ($$)
          # Don't complain in comments.  Well, until we have something
          # better, don't consider '#include' etc. to be comments.
          s/\#.*//
-           unless /^\#(if|include|endif|ifdef|ifndef|define)\b/;
+           unless /^\#(include|endif|(el)?if(n?def)?|define)\b/;
 
          # Complain once per word, but possibly several times per line.
          while (/$prohibited/)
index 5072f80c6577a5b160535de6905017631cb1301f..542865a997d9346752276ea49c62a0d2f4079a14 100644 (file)
@@ -276,7 +276,7 @@ sub scan_c_file ($)
            {
              used ('header', $1);
            }
-         if (s/^(if|ifdef|ifndef|elif)\s+//)
+         if (s/^(el)?if(n?def)?\s+//)
            {
              foreach my $word (split (/\W+/))
                {
index c0c5f61159cc3471e5439bd3ad7db3dbf5ec4880..59a3d13164067730fdd53e37f2f7d8e0d33a99e9 100644 (file)
@@ -55,9 +55,10 @@ $help = "Usage: $0 [OPTION]... [FILE]...
 
 Scan all of the C source FILES (or the standard input, if none are
 given) and write to the standard output a sorted list of all the
-identifiers that appear in those files in '#if', '#elif', '#ifdef', or
-'#ifndef' directives.  Print each identifier on a line, followed by a
-space-separated list of the files in which that identifier occurs.
+identifiers that appear in those files in '#if', '#ifdef', '#ifndef',
+'#elif', '#elifdef', or '#elifndef' directives.  Print each identifier
+on a line, followed by a space-separated list of the files in which
+that identifier occurs.
 
   -h, --help      print this help, then exit
   -V, --version   print version number, then exit
@@ -109,7 +110,7 @@ sub scan_file ($)
        while (s/\\$//);
 
       # Preprocessor directives.
-      if (s/^\s*\#\s*(if|ifdef|ifndef|elif)\s+//)
+      if (s/^\s*\#\s*(el)?if(n?def)?\s+//)
        {
          # Remove comments.  Not perfect, but close enough.
          s(/\*.*?\*/)();
index 9c05eceea57e58e770bed51dcb2cbab2ac03cc6f..832858cf4a52b25e6913035fbad83c3416ffd23f 100644 (file)
@@ -1478,8 +1478,9 @@ Invocation}).
 @command{ifnames} scans all of the C source files named on the command line
 (or the standard input, if none are given) and writes to the standard
 output a sorted list of all the identifiers that appear in those files
-in @code{#if}, @code{#elif}, @code{#ifdef}, or @code{#ifndef}
-directives.  It prints each identifier on a line, followed by a
+in @code{#if}, @code{#ifdef}, @code{#ifndef}, @code{#elif},
+@code{#elifdef}, or @code{#elifndef} directives.
+It prints each identifier on a line, followed by a
 space-separated list of the files in which that identifier occurs.
 
 @noindent
index 37fe14660f31e0ab441a091af11c3fa3ca1ef3bd..867ecd68b63c448b84875922882140a96c017979 100644 (file)
@@ -732,6 +732,8 @@ LINE2
 
 AT_DATA([iftest2.c],
 [[#ifdef IFTEST2
+#elifdef IFTEST3
+#elifndef IFTEST4
 #if VAL1
 ]])
 
@@ -741,6 +743,8 @@ DEF2 iftest1.c
 DEF3 iftest1.c
 DEF4 iftest1.c
 IFTEST2 iftest2.c
+IFTEST3 iftest2.c
+IFTEST4 iftest2.c
 LINE1 iftest1.c
 LINE2 iftest1.c
 SPACES iftest1.c