changeset 29746:7f339da6cabd

avoid possible gcc warning about C++ one definition rule (bug #60586) * acinclude.m4 (OCTAVE_PROG_BISON): Also check whether api.prefix applies to yysymbol_kind_t in the files that bison generates. If so, substitute new variables, OCTAVE_PARSER_CPPFLAGS and OCTAVE_TEX_PARSER_CPPFLAGS. * libinterp/corefcn/module.mk (%canon_reldir%_libcorefcn_la_CPPFLAGS): Add $(OCTAVE_TEX_PARSER_CPPFLAGS) to the list. * libinterp/parse-tree/module.mk (%canon_reldir%_libparse_tree_la_CPPFLAGS): Add $(OCTAVE_PARSER_CPPFLAGS) to the list.
author John W. Eaton <jwe@octave.org>
date Tue, 08 Jun 2021 15:49:37 -0400
parents 6c76819255cb
children c9eaf405f691
files libinterp/corefcn/module.mk libinterp/parse-tree/module.mk m4/acinclude.m4
diffstat 3 files changed, 44 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/module.mk	Mon Jun 07 22:54:48 2021 +0200
+++ b/libinterp/corefcn/module.mk	Tue Jun 08 15:49:37 2021 -0400
@@ -333,7 +333,8 @@
   $(HDF5_CPPFLAGS) \
   $(LLVM_CPPFLAGS) \
   $(SPARSE_XCPPFLAGS) \
-  $(Z_CPPFLAGS)
+  $(Z_CPPFLAGS) \
+  $(OCTAVE_TEX_PARSER_CPPFLAGS)
 
 libinterp_EXTRA_DIST += \
   %reldir%/default-defs.in.h \
--- a/libinterp/parse-tree/module.mk	Mon Jun 07 22:54:48 2021 +0200
+++ b/libinterp/parse-tree/module.mk	Tue Jun 08 15:49:37 2021 -0400
@@ -118,7 +118,8 @@
 
 %canon_reldir%_libparse_tree_la_CPPFLAGS = \
   $(libinterp_liboctinterp_la_CPPFLAGS) \
-  $(LLVM_CPPFLAGS)
+  $(LLVM_CPPFLAGS) \
+  $(OCTAVE_PARSER_CPPFLAGS)
 
 libinterp_EXTRA_DIST += \
   %reldir%/octave.gperf
--- a/m4/acinclude.m4	Mon Jun 07 22:54:48 2021 +0200
+++ b/m4/acinclude.m4	Tue Jun 08 15:49:37 2021 -0400
@@ -3221,6 +3221,39 @@
       done
       rm -f conftest.yy y.tab.h y.tab.c
       ])
+
+    AC_CACHE_CHECK([whether api.prefix applies to yysymbol_kind_t],
+                   [octave_cv_bison_api_prefix_applies_to_yysymbol_kind_t], [
+      [case "$octave_cv_bison_api_prefix_decl_style" in
+        "api brace")
+          def='%define api.prefix {PREFIX_}'
+        ;;
+        "api quote")
+          def='%define api.prefix "PREFIX_"'
+        ;;
+        "name brace")
+          def='%define name-prefix {PREFIX_}'
+        ;;
+        "name quote")
+          def='%define name-prefix "PREFIX_"'
+        ;;
+      esac]
+      cat << EOF > conftest.yy
+$def
+%start input
+%%
+input:;
+%%
+EOF
+      ## Older versions of bison only warn and exit with success.
+      $YACC $WARN_YFLAGS conftest.yy
+      if grep PREFIX_symbol_kind_t y.tab.c > /dev/null; then
+        octave_cv_bison_api_prefix_applies_to_yysymbol_kind_t=yes
+      else
+        octave_cv_bison_api_prefix_applies_to_yysymbol_kind_t=no
+      fi
+      rm -f conftest.yy y.tab.h y.tab.c
+      ])
   fi
 
   if test -z "$octave_cv_bison_api_prefix_decl_style" \
@@ -3245,7 +3278,14 @@
 building from VCS sources.
 "
     OCTAVE_CONFIGURE_WARNING([warn_bison])
+
   fi
+  if test "$octave_cv_bison_api_prefix_applies_to_yysymbol_kind_t" = no; then
+    OCTAVE_PARSER_CPPFLAGS="-Dyysymbol_kind_t=octave_symbol_kind_t"
+    OCTAVE_TEX_PARSER_CPPFLAGS="-Dyysymbol_kind_t=octave_tex_symbol_kind_t"
+  fi
+  AC_SUBST(OCTAVE_PARSER_CPPFLAGS)
+  AC_SUBST(OCTAVE_TEX_PARSER_CPPFLAGS)
   AC_SUBST(WARN_YFLAGS)
 ])
 dnl