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

            Bug ID: 86568
           Summary: -Wnonnull warnings should highlight the relevant
                    argument not the closing parenthesis
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

void f(void*, void*) __attribute__((nonnull(2)));

struct A {
  void f(void*, void*) __attribute__((nonnull(2)));
};

int main()
{
  f(0, 0);
  A().f(0, 0);
}

nonnull.cc: In function 'int main()':
nonnull.cc:9:9: warning: null argument where non-null required (argument 2)
[-Wnonnull]
   f(0, 0);
         ^
nonnull.cc:10:13: warning: null argument where non-null required (argument 2)
[-Wnonnull]
   A().f(0, 0);
             ^


The location of the caret diagnostic is not helpful. It's especially confusing
for member functions where the argument number includes the implicit 'this'
parameter.

Expected result:

nonnull.cc: In function 'int main()':
nonnull.cc:9:9: warning: null argument where non-null required (argument 2)
[-Wnonnull]
   f(0, 0);
        ^
nonnull.cc:10:13: warning: null argument where non-null required (argument 2)
[-Wnonnull]
   A().f(0, 0);
         ^

Reply via email to