It turns out that permerror_opt is not directly usable for
-fpermissive in the C front end. The front end uses pedwarn
extensively, and pedwarns are not overridable by -Wno-* options,
yet permerrors are. Add new pedpermerror helpers that turn into
pedwarns if -pedantic-errors is active.
Due to the dependency on flag_pedantic_errors, the new helpers
are specific to the C-family front ends. For implementing the
rich location variant, export emit_diagnostic_valist from
gcc/diagnostic.cc in parallel to its location_t variant.
gcc/
* diagnostic-core.h (emit_diagnostic_valist): Declare function.
* diagnostic.cc (emit_diagnostic_valist): Define it.
gcc/c-family/
* c-common.h (pedpermerror): Declare functions.
* c-warn.cc (pedpermerror): Define them.
---
gcc/c-family/c-common.h | 4 ++++
gcc/c-family/c-warn.cc | 34 ++++++++++++++++++++++++++++++++++
gcc/diagnostic-core.h | 3 +++
gcc/diagnostic.cc | 7 +++++++
4 files changed, 48 insertions(+)
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index b57e83d7c5d..789e0bf2459 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1486,6 +1486,10 @@ extern void warn_for_address_or_pointer_of_packed_member
(tree, tree);
extern void warn_parm_array_mismatch (location_t, tree, tree);
extern void maybe_warn_sizeof_array_div (location_t, tree, tree, tree, tree);
extern void do_warn_array_compare (location_t, tree_code, tree, tree);
+extern bool pedpermerror (location_t, int, const char *,
+ ...) ATTRIBUTE_GCC_DIAG(3,4);
+extern bool pedpermerror (rich_location *, int, const char *,
+ ...) ATTRIBUTE_GCC_DIAG(3,4);
/* Places where an lvalue, or modifiable lvalue, may be required.
Used to select diagnostic messages in lvalue_error and
diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index b1bd8ba9f42..475a3e4b42e 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -3932,3 +3932,37 @@ check_for_xor_used_as_pow (location_t lhs_loc, tree
lhs_val,
lhs_uhwi, lhs_uhwi);
}
}
+
+/* If !flag_pedantic_errors, equivalent to permerror_opt, otherwise to
+ pedwarn. */
+
+bool
+pedpermerror (location_t location, int opt, const char *gmsgid, ...)
+{
+ auto_diagnostic_group d;
+ va_list ap;
+ va_start (ap, gmsgid);
+ rich_location richloc (line_table, location);
+ bool ret = emit_diagnostic_valist (flag_pedantic_errors
+ ? DK_PEDWARN : DK_PERMERROR,
+ location, opt, gmsgid, &ap);
+ va_end (ap);
+ return ret;
+}
+
+/* Same as "pedpermerror" above, but at RICHLOC. */
+
+bool
+pedpermerror (rich_location *richloc, int opt, const char *gmsgid, ...)
+{
+ gcc_assert (richloc);
+
+ auto_diagnostic_group d;
+ va_list ap;
+ va_start (ap, gmsgid);
+ bool ret = emit_diagnostic_valist (flag_pedantic_errors
+ ? DK_PEDWARN : DK_PERMERROR,
+ richloc, opt, gmsgid, &ap);
+ va_end (ap);
+ return ret;
+}
diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h
index 04eba3d140e..eac775fb573 100644
--- a/gcc/diagnostic-core.h
+++ b/gcc/diagnostic-core.h
@@ -121,6 +121,9 @@ extern bool emit_diagnostic (diagnostic_t, location_t, int,
const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
extern bool emit_diagnostic (diagnostic_t, rich_location *, int,
const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
+extern bool emit_diagnostic_valist (diagnostic_t, rich_location *, int,
+ const char *,
+ va_list *) ATTRIBUTE_GCC_DIAG (4,0);
extern bool emit_diagnostic_valist (diagnostic_t, location_t, int, const char
*,
va_list *) ATTRIBUTE_GCC_DIAG (4,0);
extern bool seen_error (void);
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index addd6606eaa..6e73343dbdb 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -1829,6 +1829,13 @@ emit_diagnostic_valist (diagnostic_t kind, location_t
location, int opt,
return diagnostic_impl (&richloc, NULL, opt, gmsgid, ap, kind);
}
+bool
+emit_diagnostic_valist (diagnostic_t kind, rich_location *richloc, int opt,
+ const char *gmsgid, va_list *ap)
+{
+ return diagnostic_impl (richloc, NULL, opt, gmsgid, ap, kind);
+}
+
/* An informative note at LOCATION. Use this for additional details on an
error
message. */
void
--
2.41.0