On 6/11/19 7:59 AM, Matthew Beliveau wrote:
Hello,

Correct me if I'm wrong, but before the function checks for virtual
bases, an if-statement checks for extra_warnings on line 6049(when my
patch is applied). The check was there before I made my changes, and
my test fails
without  -Wextra.  Below is the code above the warning call:

   if (extra_warnings)
     for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
vec_safe_iterate (vbases, i, &binfo); i++)
       {
basetype = BINFO_TYPE (binfo);

Just as an FYI, testing warning flags prevents #pragma GCC
diagnostic from having the expected effect:

  struct A { };
  struct B : virtual A { };
  struct C : A { };
  struct D0 : B, C { };   // -Winaccessible-base (good)

  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Wextra"
  struct D1 : B, C { };   //  -Winaccessible-base not suppressed
  #pragma GCC diagnostic pop

  struct D2 : B, C { };   // -Winaccessible-base (good)

(A more realistic use case is supressing -Wextra before including
a third party header and then restoring it.)

This can be solved by adding a function (say, is_warning_enabled
(int)) that does the same #pragma-sensitive checking as warning()
and calling it instead of testing extra_warnings directly.  I.e.,

  if (is_diagnostic_enabled (OPT_Wextra))
    ...
    warning (OPT_Winaccessible_base, ...);

Martin


Unless I'm mistaken and you meant for me to check for extra_warnings
again in the if-statement directly above the warning call.

Thank you,
Matthew Beliveau

On Tue, Jun 11, 2019 at 12:43 AM Jason Merrill <ja...@redhat.com> wrote:

On 6/10/19 12:02 PM, Matthew Beliveau wrote:
       if (!uniquely_derived_from_p (basetype, t))
-       warning (OPT_Wextra, "virtual base %qT inaccessible in %qT due "
-                "to ambiguity", basetype, t);
+       warning (OPT_Winaccessible_base, "virtual base %qT inaccessible in "
+                "%qT due to ambiguity", basetype, t);

You mentioned using -Wextra for this message, and you have a testcase
for it, but here you remove the only connection between this message and
-Wextra: with this patch, the virtual base warning will be enabled by
default.  Perhaps you want to check extra_warnings in the if condition?

Jason

Reply via email to