make(1): try to set the variable named "" using the command line

Before 2020-08-22, the command line argument '=cmline-plain' triggered
undefined behavior, just like the assignment '=assigned' in the Makefile.
This commit is contained in:
rillig 2020-08-22 21:22:24 +00:00
parent 2a45c242fb
commit 7d6be9ffc4
3 changed files with 17 additions and 7 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.111 2020/08/22 20:50:43 sjg Exp $
# $NetBSD: Makefile,v 1.112 2020/08/22 21:22:24 rillig Exp $
#
# Unit tests for make(1)
#
@ -323,6 +323,7 @@ FLAGS.order= -j1
FLAGS.recursive= -dL
FLAGS.vardebug= -k -dv FROM_CMDLINE=
FLAGS.varmod-match-escape= -dv
FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain'
# Some tests need extra post-processing.
SED_CMDS.sh-dots+= -e 's,^${.SHELL}: ,,'
@ -336,6 +337,7 @@ SED_CMDS.varshell+= -e '/command/s,No such.*,not found,'
POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p'
POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p'
# Some tests reuse other tests, which makes them unnecessarily fragile.
export-all.rawout: export.mk

View File

@ -1,3 +1,11 @@
fallback
1 2 3
Var_Set("${:U}", "cmdline-u", ...) name expands to empty string - ignored
Var_Set("", "cmline-plain", ...) name expands to empty string - ignored
Var_Set("", "default", ...) name expands to empty string - ignored
Var_Set("", "assigned", ...) name expands to empty string - ignored
Var_Set("", "appended", ...) name expands to empty string - ignored
Var_Set("", "", ...) name expands to empty string - ignored
Var_Set("", "subst", ...) name expands to empty string - ignored
Var_Set("", "shell-output", ...) name expands to empty string - ignored
out: fallback
out: 1 2 3
exit status 0

View File

@ -1,4 +1,4 @@
# $NetBSD: varname-empty.mk,v 1.4 2020/08/22 21:12:29 rillig Exp $
# $NetBSD: varname-empty.mk,v 1.5 2020/08/22 21:22:24 rillig Exp $
#
# Tests for the special variable with the empty name.
#
@ -12,7 +12,7 @@
= assigned # undefined behavior until 2020-08-22
+= appended
:= subst
!= echo 'value'
!= echo 'shell-output'
# The .for loop expands the expression ${i} to ${:U1}, ${:U2} and so on.
# This only works if the variable with the empty name is guaranteed to
@ -22,5 +22,5 @@ NUMBERS+= ${i}
.endfor
all:
@echo ${:Ufallback}
@echo ${NUMBERS}
@echo out: ${:Ufallback}
@echo out: ${NUMBERS}