[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/5] c++: issue a warning with a value is moved several times
From: |
Akim Demaille |
Subject: |
[PATCH 4/5] c++: issue a warning with a value is moved several times |
Date: |
Sat, 22 Sep 2018 12:53:23 +0200 |
Suggested by Frank Heckenbach.
http://lists.gnu.org/archive/html/bug-bison/2018-09/msg00022.html
* src/scan-code.l (parse_ref): Check multiple occurrences of rhs
values.
* tests/c++.at (Multiple occurrences of $n and api.value.automove): New.
---
src/scan-code.l | 21 ++++++++++++---------
tests/c++.at | 37 ++++++++++++++++++++++++++++++++++++-
2 files changed, 48 insertions(+), 10 deletions(-)
diff --git a/src/scan-code.l b/src/scan-code.l
index c9cef326..828ba9ff 100644
--- a/src/scan-code.l
+++ b/src/scan-code.l
@@ -439,26 +439,22 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
if ('[' == *cp)
{
/* Ignore the brackets. */
- char *p;
- for (p = ++cp; *p != ']'; ++p)
+ for (cp_end = ++cp; *cp_end != ']'; ++cp_end)
continue;
- cp_end = p;
explicit_bracketing = true;
}
else
{
/* Take all characters of the name. */
- char* p;
- for (p = cp; *p; ++p)
+ for (char* p = cp; *p; ++p)
if (is_dot_or_dash (*p))
{
ref_tail_fields = p;
break;
}
- for (p = cp; *p; ++p)
+ for (cp_end = cp; *cp_end; ++cp_end)
continue;
- cp_end = p;
explicit_bracketing = false;
}
@@ -705,8 +701,15 @@ handle_action_dollar (symbol_list *rule, char *text,
location dollar_loc)
obstack_quote (&obstack_for_string, type_name);
obstack_sgrow (&obstack_for_string, ")[");
if (0 < n)
- symbol_list_n_get (effective_rule, n)->action_props.is_value_used =
- true;
+ {
+ symbol_list *sym = symbol_list_n_get (effective_rule, n);
+ if (muscle_percent_define_ifdef ("api.value.automove")
+ && sym->action_props.is_value_used)
+ complain (&dollar_loc, Wother,
+ _("multiple occurrences of $%s with api.value.automove
enabled"),
+ cp);
+ sym->action_props.is_value_used = true;
+ }
break;
}
}
diff --git a/tests/c++.at b/tests/c++.at
index 780a8415..67ce3ab6 100644
--- a/tests/c++.at
+++ b/tests/c++.at
@@ -190,6 +190,41 @@ AT_PARSER_CHECK([./list], 0, [],
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
+## --------------------------------------------------- ##
+## Multiple occurrences of $n and api.value.automove. ##
+## --------------------------------------------------- ##
+
+AT_SETUP([Multiple occurrences of $n and api.value.automove])
+
+AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"])
+
+AT_DATA_GRAMMAR([input.yy],
+[[%skeleton "lalr1.cc"
+%define api.value.automove
+%token <int> NUMBER "number"
+%nterm <int> exp
+%%
+exp:
+ "number" { $$ = $1; $$; }
+| "twice" exp { $$ = $2 + $2; }
+| "thrice" exp[val] { $$ = $2 + $val + $2; }
+]])
+
+AT_BISON_CHECK([[-fcaret input.yy]], [0], [],
+[[input.yy:16.33-34: warning: multiple occurrences of $2 with
api.value.automove enabled [-Wother]
+ | "twice" exp { $$ = $2 + $2; }
+ ^^
+input.yy:17.33-36: warning: multiple occurrences of $val with
api.value.automove enabled [-Wother]
+ | "thrice" exp[val] { $$ = $2 + $val + $2; }
+ ^^^^
+input.yy:17.40-41: warning: multiple occurrences of $2 with api.value.automove
enabled [-Wother]
+ | "thrice" exp[val] { $$ = $2 + $val + $2; }
+ ^^
+]])
+
+AT_BISON_OPTION_POPDEFS
+AT_CLEANUP
+
## ---------- ##
## Variants. ##
@@ -336,7 +371,7 @@ list:
item:
TEXT { $$ = $][1; }
-| NUMBER { if ($][1 == 3) YYERROR; else $$ = to_string ($][1); }
+| NUMBER { int v = $][1; if (v == 3) YYERROR; else $$ = to_string (v); }
;
%%
]AT_TOKEN_CTOR_IF([],
--
2.19.0
- RFC: api.value.automove, Akim Demaille, 2018/09/19
- Re: RFC: api.value.automove, Hans Ã…berg, 2018/09/19
- Re: RFC: api.value.automove, Frank Heckenbach, 2018/09/20
- Re: RFC: api.value.automove, Akim Demaille, 2018/09/21
- Re: RFC: api.value.automove, Frank Heckenbach, 2018/09/21
- [PATCH 0/5] lalr1.cc: automove, Akim Demaille, 2018/09/22
- [PATCH 1/5] tests: prepare a test for automove, Akim Demaille, 2018/09/22
- [PATCH 2/5] tests: c++: use a custom string type, Akim Demaille, 2018/09/22
- [PATCH 3/5] c++: introduce api.value.automove, Akim Demaille, 2018/09/22
- [PATCH 4/5] c++: issue a warning with a value is moved several times,
Akim Demaille <=
- [PATCH 5/5] news: c++: move semantics, Akim Demaille, 2018/09/22