# the shell variables $as_echo and $as_echo_n. New code should use
# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively.
dnl The @&t@ prevents a spurious deprecation diagnostic.
-as_@&t@echo='printf %s\n'
-as_@&t@echo_n='printf %s'
+dnl Extra quoting in case `s' or `n' are user-defined macros when this
+dnl is expanded; they almost certainly aren't meant to be used here.
+dnl See bug 110377.
+as_@&t@echo='printf [%s\n]'
+as_@&t@echo_n='printf [%s]'
])# _AS_ECHO_N_PREPARE
# (typically a quoted string). The bytes of WORD are output as-is, even
# if it starts with "-" or contains "\".
m4_define([AS_ECHO],
-[printf "%s\n" $1])
+dnl Extra quoting in case `s' or `n' are user-defined macros when this
+dnl is expanded; they almost certainly aren't meant to be used here.
+dnl See bug 110377.
+[printf "[%s\n]" $1])
# Deprecation warning for the former internal shell variable $as_echo.
m4_define([as_echo],
# ---------------
# Like AS_ECHO(WORD), except do not output the trailing newline.
m4_define([AS_ECHO_N],
-[printf %s $1])
+dnl Extra quoting in case `s' is a user-defined macro when this
+dnl is expanded; it almost certainly isn't meant to be used here.
+dnl See bug 110377.
+[printf [%s] $1])
# Deprecation warning for the former internal shell variable $as_echo_n.
m4_define([as_echo_n],
AT_CLEANUP
+## ------------------------------ ##
+## Redefining AS_ECHO internals. ##
+## ------------------------------ ##
+
+AT_SETUP([Redefining AS@&t@_ECHO internals])
+
+# None of the tests below do any AC_DEFINEs, so running autoheader is
+# a waste of time, but the skeleton generated by AT_CONFIGURE_AC needs
+# this file to exist anyway.
+AT_DATA([config.hin])
+
+# Defining a macro named `s' or `n' should not affect AS_ECHO or
+# macros that use it.
+
+AT_CONFIGURE_AC(
+[[m4@&t@_pushdef([s], [z])
+m4@&t@_pushdef([n], [u])
+AC_MSG_NOTICE([checking whether m4sugar echo works... yes])
+AC_MSG_CHECKING([whether m4sugar echo_n works])
+AC_MSG_RESULT([yes])
+m4@&t@_popdef([s])
+m4@&t@_popdef([n])
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE([], [],
+[[configure: checking whether m4sugar echo works... yes
+checking whether m4sugar echo_n works... yes
+configure: creating ./config.status
+config.status: creating config.h
+]], [])
+AT_CHECK_ENV
+rm config.h
+
+# More elaborate version of the above; derived from actual code in
+# ruby 2.7.2's configure script.
+
+AT_CONFIGURE_AC(
+[[AC@&t@_DEFUN([RUBY_CHECK_SIZEOF],[
+AS@&t@_VAR_PUSHDEF([s], [ac_cv_sizeof_size])
+AC@&t@_CACHE_CHECK([size of $1],
+ [AS@&t@_TR_SH([ac_cv_sizeof_$1])],
+ [AS@&t@_TR_SH(ac_cv_sizeof_$1)=1])
+
+# fake use of 's' for illustratve purposes:
+s=42
+echo "s is defined as ${s}"
+
+AS@&t@_VAR_POPDEF([s])
+])
+
+RUBY_CHECK_SIZEOF(int)
+echo "ac_cv_sizeof_int=${ac_cv_sizeof_int}"
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE([], [],
+[[checking size of int... 1
+ac_cv_sizeof_size is defined as 42
+ac_cv_sizeof_int=1
+configure: creating ./config.status
+config.status: creating config.h
+]], [])
+AT_CHECK_ENV
+rm config.h
+
+# However, defining a macro named `printf' _is_ expected to affect
+# the functioning of AS_ECHO.
+
+AT_CONFIGURE_AC(
+[[m4@&t@_pushdef([printf], [echo])
+AC_MSG_NOTICE([checking whether m4sugar echo works... yes])
+AC_MSG_CHECKING([whether m4sugar echo_n works])
+AC_MSG_RESULT([yes])
+m4@&t@_popdef([printf])
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE([], [],
+[[%s\n configure: checking whether m4sugar echo works... yes
+%s checking whether m4sugar echo_n works... @&t@
+%s\n yes
+configure: creating ./config.status
+config.status: creating config.h
+]], [])
+AT_CHECK_ENV
+
+AT_CLEANUP
+
+
## ----------------- ##
## AS_EXECUTABLE_P. ##
## ----------------- ##