warning: avoid warnings about unreachable code

Reported by Uxio Prego.
https://lists.gnu.org/archive/html/help-bison/2018-11/msg00031.html

We also need to move the unreachable 'goto' to a reachable place,
otherwise clang complains about the code being unreachable anyway.
See also https://bugs.llvm.org/show_bug.cgi?id=39736.

Interestingly, we don't have to apply that trick to
`#define YYCDEBUG if (false) std::cerr`, clang does not warn when the
code comes from macro expansion.

* configure.ac: Use -Wunreachable-code when supported.
* data/lalr1.cc, data/yacc.c: Pacify clang's warning about `if (0)`
by using a macro.
Another possibility was to move this statement to a reachable place.
* tests/actions.at, tests/c++.at: Avoid generating unreachable code.
This commit is contained in:
Akim Demaille
2018-11-22 18:03:12 +01:00
parent 660811a6c5
commit cc050fd321
6 changed files with 24 additions and 13 deletions

View File

@@ -519,6 +519,8 @@ AT_DATA_GRAMMAR([[input.y]],
#define RANGE(Location) ]AT_LALR1_CC_IF([(Location).begin.line, (Location).end.line],
[(Location).first_line, (Location).last_line])[
#define USE(SYM)
/* Display the symbol type Symbol. */
#define V(Symbol, Value, Location, Sep) \
fprintf (stderr, #Symbol " (%d@%d-%d)%s", Value, RANGE(Location), Sep)
@@ -610,8 +612,8 @@ input:
;
check-spontaneous-errors:
raise { abort(); $$ = $1; }
| '(' raise ')' { abort(); $$ = $2; }
raise { abort(); USE(($$, $1)); }
| '(' raise ')' { abort(); USE(($$, $2)); }
| error
{
$$ = 5;

View File

@@ -435,8 +435,6 @@ namespace yy
return parser::token::TEXT;]])[
}
}
abort ();
}
}