]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
tests: fix yacc C++ tests with some C++ compilers
authorMike Frysinger <vapier@gentoo.org>
Sun, 20 Feb 2022 19:28:11 +0000 (14:28 -0500)
committerMike Frysinger <vapier@gentoo.org>
Thu, 24 Feb 2022 04:04:41 +0000 (23:04 -0500)
Fixes automake bug https://bugs.gnu.org/20031.

The C++ standard does not require symbols be placed into the global
namespace, just in the std namespace.  The GNU implementation will
place symbols in both.  For our specific code, we don't care either.

Unfortunately, it looks like generated flex code assumes that some
stdlib.h symbols (free, malloc, exit) are in the global namespace,
even when compiling for C++.  So when we include <cstdlib> but not
<stdlib.h>, we might not get the symbols in the global namespace.

We can workaround this by including stdlib.h in these tests without
invalidating the point of the tests in general.

* t/yacc-cxx.sh: Include stdlib.h.
* t/yacc-d-cxx.sh: Likewise.
* t/yacc-mix-c-cxx.sh: Likewise.

t/yacc-cxx.sh
t/yacc-d-cxx.sh
t/yacc-mix-c-cxx.sh

index 9dd9aabf7f3890a49b8caa20d73001752e7d802d..33e73cbc0837f72f933014bf1e9909f7f39abed8 100644 (file)
@@ -43,6 +43,9 @@ END
 
 cat > parse1.yy << 'END'
 %{
+// Include C header to provide global symbols that flex assumes.
+// https://bugs.gnu.org/20031
+#include <stdlib.h>
 // Valid C++, but deliberately invalid C.
 #include <cstdio>
 #include <cstdlib>
index ce7a9b123094c3409a16772240e962df93fb4868..b6390a67a51db600d544d440bf2f31a59642552e 100644 (file)
@@ -26,6 +26,9 @@ write_parse ()
   header=$1
   unindent <<END
     %{
+    // Include C header to provide global symbols that flex assumes.
+    // https://bugs.gnu.org/20031
+    #include <stdlib.h>
     // Valid C++, but deliberately invalid C.
     #include <cstdlib>
     #include "$header"
index eb02d4cd57903d261b59efb53da0454629874d2e..475a8e9f5588d99f05be8c7ec14ab9aca79bd4fa 100644 (file)
@@ -82,6 +82,10 @@ END
 
 cat > parse.yy <<'END'
 %{
+// Include C header to provide global symbols that flex assumes.
+// https://bugs.gnu.org/20031
+#include <stdlib.h>
+// Valid C++, but deliberately invalid C.
 #include <cstdlib>
 #include "parse.hh"
 int yylex (void) { return 0; }