@@ -510,7 +510,7 @@ C++ ObjC++ Var(warn_nonvdtor) Warning
Warn about non-virtual destructors
Wnonnull
-C ObjC Var(warn_nonnull) Warning
+C C++ ObjC Var(warn_nonnull) Warning
Warn about NULL being passed to argument slots marked as requiring non-NULL
Wnormalized=
@@ -2943,6 +2943,10 @@ as non-null, and the @option{-Wnonnull} option is enabled, a warning
is issued. The compiler may also choose to make optimizations based
on the knowledge that certain function arguments will not be null.
+Since non-static C++ methods have an implicit @code{this} argument, the
+arguments of such methods should be counted from two, not one, when
+giving values for @var{arg-index}.
+
If no argument index list is given to the @code{nonnull} attribute,
all pointer arguments are marked as non-null. To illustrate, the
following declaration is equivalent to the previous example:
@@ -3194,7 +3194,7 @@ Enable @option{-Wformat} plus format checks not included in
@option{-Wformat}. Currently equivalent to @samp{-Wformat
-Wformat-nonliteral -Wformat-security -Wformat-y2k}.
-@item -Wnonnull @r{(C and Objective-C only)}
+@item -Wnonnull @r{(C, C++, Objective-C, and Objective-C++ only)}
@opindex Wnonnull
@opindex Wno-nonnull
Warn about passing a null pointer for arguments marked as
new file mode 100644
@@ -0,0 +1,16 @@
+// { dg-do compile }
+// { dg-options "-Wnonnull" }
+
+#include <stddef.h>
+
+class Foo {
+ char *name;
+ public:
+ void func1(const int *ptr) __attribute__((nonnull(2))) {}
+ Foo(char *str) __attribute__((nonnull)) : name(str) {}
+};
+
+void Bar() {
+ Foo foo(NULL); // { dg-warning "null argument where non-null required" }
+ foo.func1(NULL); // { dg-warning "null argument where non-null required" }
+}