Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: only accept assignment-expression ...



details:   https://anonhg.NetBSD.org/src/rev/57e498022888
branches:  trunk
changeset: 379939:57e498022888
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Jun 28 07:55:05 2021 +0000

description:
lint: only accept assignment-expression in _Generic

That's what C11 says.

diffstat:

 tests/usr.bin/xlint/lint1/c11_generic_expression.c |  15 ++++++++++++++-
 usr.bin/xlint/lint1/cgram.y                        |   8 ++++----
 2 files changed, 18 insertions(+), 5 deletions(-)

diffs (60 lines):

diff -r 839c0a4bb84a -r 57e498022888 tests/usr.bin/xlint/lint1/c11_generic_expression.c
--- a/tests/usr.bin/xlint/lint1/c11_generic_expression.c        Mon Jun 28 07:18:01 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/c11_generic_expression.c        Mon Jun 28 07:55:05 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: c11_generic_expression.c,v 1.5 2021/06/27 21:30:46 rillig Exp $        */
+/*     $NetBSD: c11_generic_expression.c,v 1.6 2021/06/28 07:55:05 rillig Exp $        */
 # 3 "c11_generic_expression.c"
 
 /*
@@ -75,3 +75,16 @@ comma_expression(char first, double seco
        );
        /* expect+1: without returning value [217] */
 }
+
+/*
+ * Ensure that assignment-expressions are accepted by the grammar, as
+ * opposed to comma-expressions.
+ */
+/* ARGSUSED */
+int
+assignment_expression(int first, int second)
+{
+       return _Generic(first = second,
+           int: second = first
+       );
+}
diff -r 839c0a4bb84a -r 57e498022888 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Mon Jun 28 07:18:01 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Mon Jun 28 07:55:05 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.241 2021/06/27 21:52:18 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.242 2021/06/28 07:55:05 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.241 2021/06/27 21:52:18 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.242 2021/06/28 07:55:05 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -1659,12 +1659,12 @@ generic_assoc_list:             /* C11 6.5.1.1 */
        ;
 
 generic_association:           /* C11 6.5.1.1 */
-         type_name T_COLON expr {
+         type_name T_COLON assignment_expression {
                $$ = getblk(sizeof(*$$));
                $$->gat_arg = $1;
                $$->gat_result = $3;
          }
-       | T_DEFAULT T_COLON expr {
+       | T_DEFAULT T_COLON assignment_expression {
                $$ = getblk(sizeof(*$$));
                $$->gat_arg = NULL;
                $$->gat_result = $3;



Home | Main Index | Thread Index | Old Index