Now that C23 and C++23 have #elifdef and #elifndef shouldn't ifnames
check for them? It seems that recent versions of gcc and clang support
it, though I'm not sure how many actually use it.
I've attached a patch that should work. Code that doesn't use them
shouldn't notice a difference.
Collin
From be54bf53fae8fb9cc254b9666c18501a67009482 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Thu, 13 Jun 2024 20:18:13 -0700
Subject: [PATCH] ifnames: Check for #elifdef and #elifndef
* bin/ifnames.in (scan_file): Check for #elifdef and #elifndef added
in C23 and C++23.
* tests/tools.at (ifnames): Add a test case.
* NEWS: Mention the change.
---
NEWS | 5 +++++
bin/ifnames.in | 2 +-
tests/tools.at | 14 ++++++++++----
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/NEWS b/NEWS
index 521bbd3a..9d723299 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,11 @@ 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
+
+*** ifnames now checks for #elifdef and #elifndef directives.
+ These directives were added in C23 and C++23.
+
* Noteworthy changes in release 2.72 (2023-12-22) [release]
** Backward incompatibilities
diff --git a/bin/ifnames.in b/bin/ifnames.in
index c0c5f611..737f2064 100644
--- a/bin/ifnames.in
+++ b/bin/ifnames.in
@@ -109,7 +109,7 @@ sub scan_file ($)
while (s/\\$//);
# Preprocessor directives.
- if (s/^\s*\#\s*(if|ifdef|ifndef|elif)\s+//)
+ if (s/^\s*\#\s*(if|ifdef|ifndef|elif|elifdef|elifndef)\s+//)
{
# Remove comments. Not perfect, but close enough.
s(/\*.*?\*/)();
diff --git a/tests/tools.at b/tests/tools.at
index 37fe1466..3a9d0e1e 100644
--- a/tests/tools.at
+++ b/tests/tools.at
@@ -735,7 +735,13 @@ AT_DATA([iftest2.c],
#if VAL1
]])
-AT_CHECK([ifnames iftest1.c iftest2.c], 0,
+AT_DATA([iftest3.c],
+[[#ifdef VAL1
+#elifdef VAL2
+#elifndef VAL3
+]])
+
+AT_CHECK([ifnames iftest1.c iftest2.c iftest3.c], 0,
[DEF1 iftest1.c
DEF2 iftest1.c
DEF3 iftest1.c
@@ -745,9 +751,9 @@ LINE1 iftest1.c
LINE2 iftest1.c
SPACES iftest1.c
TABS iftest1.c
-VAL1 iftest1.c iftest2.c
-VAL2 iftest1.c
-VAL3 iftest1.c
+VAL1 iftest1.c iftest2.c iftest3.c
+VAL2 iftest1.c iftest3.c
+VAL3 iftest1.c iftest3.c
VAL4 iftest1.c
], [])
--
2.45.2