@@ -105,6 +105,9 @@ extern bool pedwarn (rich_location *, int, const char *, ...)
extern bool permerror (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
extern bool permerror (rich_location *, const char *,
...) ATTRIBUTE_GCC_DIAG(2,3);
+extern bool permerror (location_t, int, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4);
+extern bool permerror (rich_location *, int, const char *,
+ ...) ATTRIBUTE_GCC_DIAG(3,4);
extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
extern void sorry_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
@@ -1109,15 +1109,12 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain,
else if (complain & tf_error)
{
int savederrorcount = errorcount;
- if (!flag_permissive)
- global_dc->pedantic_errors = 1;
auto s = make_temp_override (global_dc->dc_warn_system_headers, true);
- pedwarn (loc, OPT_Wnarrowing,
- "narrowing conversion of %qE from %qH to %qI",
- init, ftype, type);
+ permerror (loc, OPT_Wnarrowing,
+ "narrowing conversion of %qE from %qH to %qI",
+ init, ftype, type);
if (errorcount == savederrorcount)
ok = true;
- global_dc->pedantic_errors = flag_pedantic_errors;
}
}
@@ -2054,6 +2054,45 @@ permerror (rich_location *richloc, const char *gmsgid, ...)
return ret;
}
+/* Similar to the above, but controlled by a flag other than -fpermissive.
+ As above, an error by default or a warning with -fpermissive, but this
+ diagnostic can also be downgraded by -Wno-error=opt. */
+
+bool
+permerror (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 pe = global_dc->pedantic_errors;
+ if (!global_dc->permissive)
+ global_dc->pedantic_errors = true;
+ bool ret = diagnostic_impl (&richloc, NULL, opt, gmsgid, &ap, DK_PEDWARN);
+ global_dc->pedantic_errors = pe;
+ va_end (ap);
+ return ret;
+}
+
+/* Same as "permerror" above, but at RICHLOC. */
+
+bool
+permerror (rich_location *richloc, int opt, const char *gmsgid, ...)
+{
+ gcc_assert (richloc);
+
+ auto_diagnostic_group d;
+ va_list ap;
+ va_start (ap, gmsgid);
+ bool pe = global_dc->pedantic_errors;
+ if (!global_dc->permissive)
+ global_dc->pedantic_errors = true;
+ bool ret = diagnostic_impl (richloc, NULL, opt, gmsgid, &ap, DK_PEDWARN);
+ global_dc->pedantic_errors = pe;
+ va_end (ap);
+ return ret;
+}
+
/* A hard error: the code is definitely ill-formed, and an object file
will not be produced. */
void