https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79961
Bug ID: 79961
Summary: Should diagnose when '__nonnull__' attribute is
applied to implicit this argument
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: palves at redhat dot com
Target Milestone: ---
struct A
{
A (const char *arg) __attribute__ ((__nonnull__ (1)));
void foo (const char *arg) __attribute__ ((__nonnull__ (1)));
};
Above, nonnull(1) should have been nonnull(2), since argument 1 is the implicit
"this" pointer (which is always non-NULL anyway).
Unfortunately, G++ fails to help find the bug.
With GNU C++14 (GCC) version 7.0.1 20170307 (experimental):
$ /opt/gcc/bin/g++ nonnull.cc -o nonnull -g3 -O2 -c -Wall -Wextra
(no warnings)
Note Clang 3.7:
$ clang++ nonnull.cc -o nonnull -c
nonnull.cc:3:39: error: '__nonnull__' attribute is invalid for the implicit
this argument
A (const char *arg) __attribute__ ((__nonnull__ (1)));
^ ~
nonnull.cc:4:46: error: '__nonnull__' attribute is invalid for the implicit
this argument
void foo (const char *arg) __attribute__ ((__nonnull__ (1)));
^ ~
2 errors generated.