https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91127

            Bug ID: 91127
           Summary: Incorrect checking of nonnull attribute with argument
                    to a constructor of class with a virtual base
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: frankhb1989 at gmail dot com
  Target Milestone: ---

Case:

struct B
{};

struct C : virtual B
{
        __attribute__((nonnull(2))) C(const char*);
};


a.cc:6:43: warning: 'nonnull' attribute argument value '2' refers to parameter
type 'int' [-Wattributes]
    6 |  __attribute__((nonnull(2))) C(const char*);
      |                                           ^

Removal of `virtual` makes it works. Use of `__attribute__((nonnull))` (with no
argument `2`) also works.

Clang++ 8 seems OK with or without `virtual`.

Note it is worse in old versions of the compiler, e.g. with G++ 7.1:

a.cc:6:43: error: nonnull argument references non-pointer operand (argument 1,
operand 2)
  __attribute__((nonnull(2))) C(const char*);
                                           ^

The change in PR 87541 has made the diagnostics more explicit. Not sure whether
the change from error to warning is intended, though.

Reply via email to