+
+AT_BISON_CHECK([[sr-rr.y]], [[0]], [[]],
+[[sr-rr.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
+sr-rr.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
+]])
+AT_BISON_CHECK([[-Wno-conflicts-sr sr-rr.y]], [[0]], [[]],
+[[sr-rr.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
+]])
+AT_BISON_CHECK([[-Wno-conflicts-rr sr-rr.y]], [[0]], [[]],
+[[sr-rr.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
+]])
+
+[
+# This is piece of code is rather complex for a simple task: try every
+# combinaison of (0 or 1 real SR) x (0 or 1 real RR) x (don't %expect
+# or %expect 0, 1, or 2 SR) x (don't %expect-rr or %expect-rr 0, 1, or 2
+# RR).
+
+# Number and types of genuine conflicts in the grammar.
+for gram in sr-rr sr rr; do
+ # Number of expected s/r conflicts.
+ for sr_exp_i in '' 0 1 2; do
+ # Number of expected r/r conflicts.
+ for rr_exp_i in '' 0 1 2; do
+ test -z "$sr_exp_i" && test -z "$rr_exp_i" && continue
+
+ # Build grammar file.
+ sr_exp=0
+ rr_exp=0
+ file=$gram
+ directives=
+ if test -n "$sr_exp_i"; then
+ sr_exp=$sr_exp_i
+ file=$file-expect-$sr_exp
+ directives="%expect $sr_exp"
+ fi
+ if test -n "$rr_exp_i"; then
+ rr_exp=$rr_exp_i
+ file=$file-expect-rr-$rr_exp
+ directives="$directives %expect-rr $rr_exp"
+ fi
+ file=$file.y
+ echo "$directives" > $file
+ cat $gram.y >> $file
+
+ # Number of found conflicts.
+ case $gram in
+ (sr) sr_count=1; rr_count=0;;
+ (rr) sr_count=0; rr_count=1;;
+ (sr-rr) sr_count=1; rr_count=1;;
+ esac
+
+ # Update number of expected conflicts: if %expect is given then
+ # %expect-rr defaults to 0, and vice-versa. Leave empty if
+ # nothing expected.
+ case $sr_exp_i:$rr_exp_i in
+ ?:) rr_exp_i=0;;
+ :?) sr_exp_i=0;;
+ esac
+
+ # Run tests.
+ if test $sr_count -eq $sr_exp && test $rr_count -eq $rr_exp; then
+ ]AT_BISON_CHECK([[-Wnone $file]])[
+ ]AT_BISON_CHECK([[-Werror $file]])[
+ else
+ {
+ if test -z "$sr_exp_i" && test "$sr_count" -ne 0; then
+ echo "warning: $sr_count shift/reduce conflicts"
+ elif test "$sr_exp_i" -ne "$sr_count"; then
+ echo "error: shift/reduce conflicts: $sr_count found, $sr_exp_i expected"
+ fi
+ if test -z "$rr_exp_i" && test "$rr_count" -ne 0; then
+ echo "warning: $rr_count reduce/reduce conflicts"
+ elif test "$rr_exp_i" -ne "$rr_count"; then
+ echo "error: reduce/reduce conflicts: $rr_count found, $rr_exp_i expected"
+ fi
+ } | sed -e "s/^/$file: /" > experr
+ ]AT_BISON_CHECK([[-Wnone $file]], [[1]], [[]], [[experr]])[
+ ]AT_BISON_CHECK([[-Werror $file]], [[1]], [[]], [[experr]])[
+ fi
+ done
+ done
+done]
+