Subject: [PATCH 2/2] tests: Fix implicit function declaration errors

From: Frederic Berat <[email-masked]>
Date: Mon, 12 Dec 2022 08:05:54 +0100

From: Frédéric Bérat <[email-masked]>

This is related to an effort to prepare Automake for future GCC/Clang
versions which set c99 as default standard to be used.

Function should be properly declared prior to use in order to be
compatible with c99 standard.
This is valid for both local functions and standard functions (as
printf).

Modified files:

 * t/ax/depcomp.sh
 * t/c-demo.sh
 * t/cond35.sh
 * t/dist-vs-built-sources.sh
 * t/lex-clean.sh
 * t/lex-multiple.sh
 * t/lex-nodist.sh
 * t/ltcond2.sh
 * t/ltconv.sh
 * t/subobj-clean-lt-pr10697.sh
 * t/subobj-clean-pr10697.sh
 * t/tags-pr12372.sh
 * t/yacc-basic.sh
 * t/yacc-clean.sh
 * t/yacc-nodist.sh
---
 t/ax/depcomp.sh              |  4 ++--
 t/c-demo.sh                  |  1 +
 t/cond35.sh                  |  2 ++
 t/dist-vs-built-sources.sh   |  1 +
 t/lex-clean.sh               |  1 +
 t/lex-multiple.sh            |  4 ++++
 t/lex-nodist.sh              |  2 ++
 t/ltcond2.sh                 |  2 ++
 t/ltconv.sh                  |  6 ++++++
 t/subobj-clean-lt-pr10697.sh | 10 +++++++++-
 t/subobj-clean-pr10697.sh    | 10 +++++++++-
 t/tags-pr12372.sh            |  3 ++-
 t/yacc-basic.sh              |  1 +
 t/yacc-clean.sh              |  4 ++++
 t/yacc-nodist.sh             |  2 ++
 15 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/t/ax/depcomp.sh b/t/ax/depcomp.sh
index e4e7565df..a9debc8ef 100644
--- a/t/ax/depcomp.sh
+++ b/t/ax/depcomp.sh
@@ -243,6 +243,7 @@ cat > sub/subfoo.h <<'END'
 #include <stdio.h>
 extern int subfoo (void);
 END
+cp sub/subfoo.h sub/subfoo.save
 
 cat > src/baz.c <<'END'
 #include "baz.h"
@@ -399,8 +400,7 @@ do_test ()
       && rewrite "$srcdir"/sub/subfoo.h echo 'choke me' \
       && not $MAKE \
       && delete "$srcdir"/sub/subfoo.h \
-      && edit "$srcdir"/sub/subfoo.c -e 1d \
-      && edit "$srcdir"/foo.h -e 2d \
+      && mv  "$srcdir"/sub/subfoo.save "$srcdir"/sub/subfoo.h \
       && make_ok \
       || r='not ok'
     result_ "$r" "$pfx dependency tracking works"
diff --git a/t/c-demo.sh b/t/c-demo.sh
index 7e0e8d64f..d25bf214b 100644
--- a/t/c-demo.sh
+++ b/t/c-demo.sh
@@ -113,6 +113,7 @@ test -f build-aux/compile # We have per-target flags on C sources.
 ./configure --enable-dependency-tracking
 
 cat > src/main.c << 'END'
+#include <stdio.h>
 #include "foo.h"
 #include "bar.h"
 int main (void)
diff --git a/t/cond35.sh b/t/cond35.sh
index 215a22548..bad133970 100644
--- a/t/cond35.sh
+++ b/t/cond35.sh
@@ -73,6 +73,8 @@ END
 
 cat > tparse.y << 'END'
 %{
+extern int yylex(void);
+
 void yyerror (const char *s) {}
 %}
 %token EOF
diff --git a/t/dist-vs-built-sources.sh b/t/dist-vs-built-sources.sh
index d038e66dd..db2776f9a 100644
--- a/t/dist-vs-built-sources.sh
+++ b/t/dist-vs-built-sources.sh
@@ -41,6 +41,7 @@ foo_SOURCES = foo.c
 END
 
 cat > foo.c << 'END'
+#include <stdio.h>
 #include "h.h"
 int main (void) { printf ("%s\n", F); return 0; }
 END
diff --git a/t/lex-clean.sh b/t/lex-clean.sh
index 5aa199338..e53da8fd2 100644
--- a/t/lex-clean.sh
+++ b/t/lex-clean.sh
@@ -61,6 +61,7 @@ cat > lexer.l << 'END'
 END
 
 cat > main.c << 'END'
+extern int yylex (void);
 int main (void)
 {
   return yylex ();
diff --git a/t/lex-multiple.sh b/t/lex-multiple.sh
index 2655b633e..bf119ec84 100644
--- a/t/lex-multiple.sh
+++ b/t/lex-multiple.sh
@@ -56,6 +56,10 @@ cat > main.c << 'END'
 #include <stdlib.h>
 #include <string.h>
 
+extern int yylex (void);
+extern int foolex (void);
+extern int bar_lex (void);
+
 int main (int argc, char *argv[])
 {
   if (argc != 2)
diff --git a/t/lex-nodist.sh b/t/lex-nodist.sh
index 599539405..187dd5437 100644
--- a/t/lex-nodist.sh
+++ b/t/lex-nodist.sh
@@ -62,6 +62,8 @@ CLEANFILES = $(nodist_prog_SOURCES)
 END
 
 cat > main.c << 'END'
+extern int yylex (void);
+
 int main ()
 {
   return yylex ();
diff --git a/t/ltcond2.sh b/t/ltcond2.sh
index 29244c9b3..7e7bcadc4 100644
--- a/t/ltcond2.sh
+++ b/t/ltcond2.sh
@@ -73,6 +73,8 @@ void print (void)
 END
 
 cat > main.c <<'END'
+extern void print(void);
+
 int main (void)
 {
   print();
diff --git a/t/ltconv.sh b/t/ltconv.sh
index 2c4cc47a1..ec79ef80e 100644
--- a/t/ltconv.sh
+++ b/t/ltconv.sh
@@ -91,6 +91,12 @@ echo 'int sub22 () { return 22; }' > sub2/sub22/sub22.c
 
 cat >test.c <<'EOF'
 #include <stdio.h>
+
+extern int sub1 (void);
+extern int sub2 (void);
+extern int sub21 (void);
+extern int sub22 (void);
+
 int main ()
 {
   if (1 != sub1 ())
diff --git a/t/subobj-clean-lt-pr10697.sh b/t/subobj-clean-lt-pr10697.sh
index bb656c43f..53fc02f09 100644
--- a/t/subobj-clean-lt-pr10697.sh
+++ b/t/subobj-clean-lt-pr10697.sh
@@ -83,7 +83,15 @@ libfoo_la_SOURCES = \
 END
 
 mkdir sub1 sub2
-echo 'int libmain (void)' > main.c
+
+echo "/* Subobj clean: libtool case*/" > main.c
+for i in 1 2; do
+  for j in a b c d e f; do
+    echo "extern void $j$i (void);" >> main.c
+  done
+done
+
+echo 'int libmain (void)' >> main.c
 echo '{' >> main.c
 for i in 1 2; do
   for j in a b c d e f; do
diff --git a/t/subobj-clean-pr10697.sh b/t/subobj-clean-pr10697.sh
index f77de8c92..a7f97f6d1 100644
--- a/t/subobj-clean-pr10697.sh
+++ b/t/subobj-clean-pr10697.sh
@@ -81,7 +81,15 @@ foo_SOURCES = \
 END
 
 mkdir sub1 sub2
-echo 'int main (void)' > main.c
+
+echo "/* Subobj clean: generic case*/" > main.c
+for i in 1 2; do
+  for j in a b c d e f; do
+    echo "extern void $j$i (void);" >> main.c
+  done
+done
+
+echo 'int main (void)' >> main.c
 echo '{' >> main.c
 for i in 1 2; do
   for j in a b c d e f; do
diff --git a/t/tags-pr12372.sh b/t/tags-pr12372.sh
index b9c022f70..1a9e1e026 100644
--- a/t/tags-pr12372.sh
+++ b/t/tags-pr12372.sh
@@ -53,7 +53,8 @@ noinst_PROGRAMS = zap
 zap_SOURCES = zardoz.pc
 END
 
-echo 'int main(void) [ return bar(1); ]' > foo-main.pc
+echo 'extern int bar(int);' > foo-main.pc
+echo 'int main(void) [ return bar(1); ]' >> foo-main.pc
 echo 'int bar(int x) { return !x; }' > barbar.c
 echo 'int m@in(void) { return 0; }' > sub/zardoz.pc
 
diff --git a/t/yacc-basic.sh b/t/yacc-basic.sh
index 5b258a30c..8cc0d06a2 100644
--- a/t/yacc-basic.sh
+++ b/t/yacc-basic.sh
@@ -49,6 +49,7 @@ a : 'a' { exit(0); };
 END
 
 cat > foo.c << 'END'
+extern int yyparse(void);
 int main () { yyparse (); return 1; }
 END
 
diff --git a/t/yacc-clean.sh b/t/yacc-clean.sh
index 373774b6a..fef079cf3 100644
--- a/t/yacc-clean.sh
+++ b/t/yacc-clean.sh
@@ -65,6 +65,8 @@ END
 
 cat > sub1/parse.y << 'END'
 %{
+#include <stdio.h>
+
 int yylex () { return (getchar ()); }
 void yyerror (const char *s) {}
 %}
@@ -74,6 +76,8 @@ END
 cp sub1/parse.y sub2/parse.y
 
 cat > sub1/main.c << 'END'
+extern int yyparse(void);
+
 int main ()
 {
   return yyparse ();
diff --git a/t/yacc-nodist.sh b/t/yacc-nodist.sh
index d350a80f9..4a8ebe9ca 100644
--- a/t/yacc-nodist.sh
+++ b/t/yacc-nodist.sh
@@ -78,6 +78,8 @@ BUILT_SOURCES = parse.h
 END
 
 cat > sub1/main.c << 'END'
+extern int yyparse(void);
+
 int main ()
 {
   return yyparse ();
-- 
2.38.1