Module Name:    src
Committed By:   rillig
Date:           Thu Jan 21 23:32:28 UTC 2021

Modified Files:
        src/usr.bin/make: cond.c
        src/usr.bin/make/unit-tests: cond-cmp-numeric.exp cond-cmp-string.exp
            cond-token-plain.exp cond1.exp

Log Message:
make(1): replace warning + error with just an error in conditionals

Before, there was a "warning" for comparing strings using '<', which was
wrong.  That warning was then followed by an error, after parsing the
whole conditional.  This was only because it was easier to implement.

Replace the warning with an actual error.  This only affects
conditionals in .if lines, the conditionals in the :? modifier such as
${"A" < "B":?smaller:greater} still print 2 errors.


To generate a diff of this commit:
cvs rdiff -u -r1.251 -r1.252 src/usr.bin/make/cond.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cond-cmp-numeric.exp
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/cond-cmp-string.exp
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/cond-token-plain.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond1.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.251 src/usr.bin/make/cond.c:1.252
--- src/usr.bin/make/cond.c:1.251	Thu Jan 21 23:25:08 2021
+++ src/usr.bin/make/cond.c	Thu Jan 21 23:32:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.251 2021/01/21 23:25:08 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.252 2021/01/21 23:32:28 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.251 2021/01/21 23:25:08 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.252 2021/01/21 23:32:28 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -603,12 +603,13 @@ EvalCompareNum(double lhs, ComparisonOp 
 }
 
 static Token
-EvalCompareStr(const char *lhs, ComparisonOp op, const char *rhs)
+EvalCompareStr(CondParser *par, const char *lhs,
+	       ComparisonOp op, const char *rhs)
 {
 	if (op != EQ && op != NE) {
-		Parse_Error(PARSE_WARNING,
+		Parse_Error(PARSE_FATAL,
 		    "String comparison operator must be either == or !=");
-		/* The PARSE_FATAL follows in CondEvalExpression. */
+		par->printedError = TRUE;
 		return TOK_ERROR;
 	}
 
@@ -619,8 +620,8 @@ EvalCompareStr(const char *lhs, Comparis
 
 /* Evaluate a comparison, such as "${VAR} == 12345". */
 static Token
-EvalCompare(const char *lhs, Boolean lhsQuoted, ComparisonOp op,
-	    const char *rhs, Boolean rhsQuoted)
+EvalCompare(CondParser *par, const char *lhs, Boolean lhsQuoted,
+	    ComparisonOp op, const char *rhs, Boolean rhsQuoted)
 {
 	double left, right;
 
@@ -628,7 +629,7 @@ EvalCompare(const char *lhs, Boolean lhs
 		if (TryParseNumber(lhs, &left) && TryParseNumber(rhs, &right))
 			return ToToken(EvalCompareNum(left, op, right));
 
-	return EvalCompareStr(lhs, op, rhs);
+	return EvalCompareStr(par, lhs, op, rhs);
 }
 
 static Boolean
@@ -700,9 +701,9 @@ CondParser_Comparison(CondParser *par, B
 	CondParser_SkipWhitespace(par);
 
 	if (par->p[0] == '\0') {
-		Parse_Error(PARSE_WARNING,
-			    "Missing right-hand-side of operator");
-		/* The PARSE_FATAL follows in CondEvalExpression. */
+		Parse_Error(PARSE_FATAL,
+		    "Missing right-hand-side of operator '%s'", opname[op]);
+		par->printedError = TRUE;
 		goto done_lhs;
 	}
 
@@ -715,7 +716,7 @@ CondParser_Comparison(CondParser *par, B
 		goto done_rhs;
 	}
 
-	t = EvalCompare(lhs.str, lhsQuoted, op, rhs.str, rhsQuoted);
+	t = EvalCompare(par, lhs.str, lhsQuoted, op, rhs.str, rhsQuoted);
 
 done_rhs:
 	FStr_Done(&rhs);

Index: src/usr.bin/make/unit-tests/cond-cmp-numeric.exp
diff -u src/usr.bin/make/unit-tests/cond-cmp-numeric.exp:1.4 src/usr.bin/make/unit-tests/cond-cmp-numeric.exp:1.5
--- src/usr.bin/make/unit-tests/cond-cmp-numeric.exp:1.4	Thu Jan 21 23:25:08 2021
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric.exp	Thu Jan 21 23:32:28 2021
@@ -1,9 +1,7 @@
 CondParser_Eval: !(${:UINF} > 1e100)
-make: "cond-cmp-numeric.mk" line 11: warning: String comparison operator must be either == or !=
-make: "cond-cmp-numeric.mk" line 11: Malformed conditional (!(${:UINF} > 1e100))
+make: "cond-cmp-numeric.mk" line 11: String comparison operator must be either == or !=
 CondParser_Eval: ${:UNaN} > NaN
-make: "cond-cmp-numeric.mk" line 16: warning: String comparison operator must be either == or !=
-make: "cond-cmp-numeric.mk" line 16: Malformed conditional (${:UNaN} > NaN)
+make: "cond-cmp-numeric.mk" line 16: String comparison operator must be either == or !=
 CondParser_Eval: !(${:UNaN} == NaN)
 lhs = "NaN", rhs = "NaN", op = ==
 CondParser_Eval: 123 ! 123

Index: src/usr.bin/make/unit-tests/cond-cmp-string.exp
diff -u src/usr.bin/make/unit-tests/cond-cmp-string.exp:1.10 src/usr.bin/make/unit-tests/cond-cmp-string.exp:1.11
--- src/usr.bin/make/unit-tests/cond-cmp-string.exp:1.10	Thu Jan 21 23:25:08 2021
+++ src/usr.bin/make/unit-tests/cond-cmp-string.exp	Thu Jan 21 23:32:28 2021
@@ -2,14 +2,10 @@ make: "cond-cmp-string.mk" line 18: Malf
 make: "cond-cmp-string.mk" line 42: Malformed conditional ("string" != "str""ing")
 make: "cond-cmp-string.mk" line 49: Malformed conditional (!("value" = "value"))
 make: "cond-cmp-string.mk" line 56: Malformed conditional (!("value" === "value"))
-make: "cond-cmp-string.mk" line 113: warning: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 113: Malformed conditional ("string" < "string")
-make: "cond-cmp-string.mk" line 120: warning: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 120: Malformed conditional ("string" <= "string")
-make: "cond-cmp-string.mk" line 127: warning: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 127: Malformed conditional ("string" > "string")
-make: "cond-cmp-string.mk" line 134: warning: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 134: Malformed conditional ("string" >= "string")
+make: "cond-cmp-string.mk" line 113: String comparison operator must be either == or !=
+make: "cond-cmp-string.mk" line 120: String comparison operator must be either == or !=
+make: "cond-cmp-string.mk" line 127: String comparison operator must be either == or !=
+make: "cond-cmp-string.mk" line 134: String comparison operator must be either == or !=
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/cond-token-plain.exp
diff -u src/usr.bin/make/unit-tests/cond-token-plain.exp:1.8 src/usr.bin/make/unit-tests/cond-token-plain.exp:1.9
--- src/usr.bin/make/unit-tests/cond-token-plain.exp:1.8	Thu Jan 21 23:25:08 2021
+++ src/usr.bin/make/unit-tests/cond-token-plain.exp	Thu Jan 21 23:32:28 2021
@@ -39,8 +39,7 @@ make: "cond-token-plain.mk" line 130: Nu
 CondParser_Eval: 0${:Ux01}
 make: "cond-token-plain.mk" line 134: Numbers can be composed from literals and variable expressions.
 CondParser_Eval: "" ==
-make: "cond-token-plain.mk" line 140: warning: Missing right-hand-side of operator
-make: "cond-token-plain.mk" line 140: Malformed conditional ("" ==)
+make: "cond-token-plain.mk" line 140: Missing right-hand-side of operator '=='
 CondParser_Eval: == ""
 make: "cond-token-plain.mk" line 148: Malformed conditional (== "")
 CondParser_Eval: \\

Index: src/usr.bin/make/unit-tests/cond1.exp
diff -u src/usr.bin/make/unit-tests/cond1.exp:1.3 src/usr.bin/make/unit-tests/cond1.exp:1.4
--- src/usr.bin/make/unit-tests/cond1.exp:1.3	Sun Nov 15 14:58:14 2020
+++ src/usr.bin/make/unit-tests/cond1.exp	Thu Jan 21 23:32:28 2021
@@ -16,7 +16,7 @@ Passed:
 4 is not prime
 5 is  prime
 
-make: warning: String comparison operator must be either == or !=
+make: String comparison operator must be either == or !=
 make: Bad conditional expression `"0" > 0' in "0" > 0?OK:No
 
 OK

Reply via email to