make: do not expand the variable name in the ':_' modifier

This edge case had been so obscure that even discovering this takes
quite some time and requires reading the source code of make.

The manual page doesn't document whether the variable name is expanded
or not, it doesn't even give an example.  When this obscure modifier was
initially added in var.c 1.210 from 2017-01-30, Var_Set always expanded
the variable name once, and there was no way around it.  Therefore this
expansion has probably been unintentional.
This commit is contained in:
rillig 2021-03-14 17:27:27 +00:00
parent a442584d73
commit 0fc517c113
2 changed files with 8 additions and 11 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: varmod-remember.mk,v 1.5 2021/03/14 17:14:15 rillig Exp $
# $NetBSD: varmod-remember.mk,v 1.6 2021/03/14 17:27:27 rillig Exp $
#
# Tests for the :_ modifier, which saves the current variable value
# in the _ variable or another, to be used later again.
@ -22,10 +22,13 @@
# oversight than an intended feature. The variable name stops at the first
# '}' or ')' and thus cannot use the usual form ${VARNAME} of long variable
# names.
#
# Because of all these edge-casey conditions, this "feature" has been removed
# in var.c 1.867 from 2021-03-14.
S= INDIRECT_VARNAME
.if ${value:L:@var@${var:_=$S}@} != "value"
. error
.elif ${INDIRECT_VARNAME} != "value"
.elif defined(INDIRECT_VARNAME)
. error
.endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.866 2021/03/14 16:43:30 rillig Exp $ */
/* $NetBSD: var.c,v 1.867 2021/03/14 17:27:27 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -140,7 +140,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: var.c,v 1.866 2021/03/14 16:43:30 rillig Exp $");
MAKE_RCSID("$NetBSD: var.c,v 1.867 2021/03/14 17:27:27 rillig Exp $");
typedef enum VarFlags {
VFL_NONE = 0,
@ -3433,13 +3433,7 @@ ApplyModifier_Remember(const char **pp, ApplyModifiersState *st)
if (expr->eflags & VARE_WANTRES) {
char *name = bmake_strldup(mod + 2, n);
/*
* FIXME: do not expand the variable name here; it
* would only work for single-character variable names
* anyway.
*/
Var_SetExpand(expr->scope, name, expr->value.str);
Var_Set(expr->scope, name, expr->value.str);
free(name);
}
} else {