]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
AC_PROG_LEX: Be compatible with Solaris 10 lex’s handling of C++.
authorZack Weinberg <zack@owlfolio.org>
Wed, 4 Feb 2026 18:36:06 +0000 (13:36 -0500)
committerZack Weinberg <zack@owlfolio.org>
Wed, 4 Feb 2026 18:48:59 +0000 (13:48 -0500)
Solaris 10 lex (Software Generation Utilities (SGU) Solaris-ELF (4.0))
provides its own declaration of yywrap.  When the generated scanner is
compiled as C++, that declaration will *not* be tagged with `extern "C"`
unless the preprocessor macro __EXTERN_C__ is defined using -D.
The %{ %} block of the .l file is too late.

Our test .l file also declares yywrap, and it unconditionally tags it
with `extern "C"` when compiling as C++.  Thus, we need to define
__EXTERN_C__ or we’ll get a spurious compile error with this
implementation of lex.  This macro should be harmless with other
implementations.

sr #111381

* lib/autoconf/programs.m4 (_AC_PROG_LEX_YYTEXT_DECL): Add -D__EXTERN_C__=1
  to CPPFLAGS while compiling test programs, for improved compatibility
  with Solaris 10 lex.

lib/autoconf/programs.m4

index 332a72bc83ce1a72e516586b5f1558041fc27b6b..c7c1766019f280c727fd02aa85552b9a7956d4ba 100644 (file)
@@ -822,6 +822,14 @@ AS_IF([test "$ac_cv_prog_lex_root" = unknown],
    LEX=: LEXLIB=])
 AC_SUBST([LEX_OUTPUT_ROOT], [$ac_cv_prog_lex_root])dnl
 
+# When compiled as C++, the test lexer declares yywrap with extern "C".
+# Solaris 10 lex (Software Generation Utilities (SGU) Solaris-ELF (4.0))'s
+# scanner skeleton will provide a conflicting declaration of yywrap,
+# *without* extern "C", unless we define this macro on the command line.
+# The %{ %} block is not early enough for the definition to be effective.
+ac_save_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS -D__EXTERN_C__=1"
+
 AS_VAR_SET_IF([LEXLIB], [], [
   AC_CACHE_CHECK([for lex library], [ac_cv_lib_lex], [
     ac_save_LIBS="$LIBS"
@@ -898,6 +906,7 @@ if test $ac_cv_prog_lex_yytext_pointer = yes; then
             not a 'char[]'.])
 fi
 ])
+CPPFLAGS="$ac_save_CPPFLAGS"
 rm -f conftest.l $LEX_OUTPUT_ROOT.c
 ])# _AC_PROG_LEX_YYTEXT_DECL