[cfe-dev] Clang ignores nonnull attributes on pointer-to-member-function declarations
Tom Honermann
thonermann at coverity.com
Mon Jul 13 08:31:54 PDT 2015
Clang (3.4-trunk) ignores nonnull attributes on
pointer-to-member-function declarations.
A test case follows. Recent versions of gcc [1] allow nonnull
attributes on pointer-to-member-function declarations. Is there any
reason that Clang shouldn't also permit these? If not, I'll open a new
PR for this.
Tom.
[1] gcc 5.0, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60765
$ cat t.cpp
struct S;
void (S::*pmf)(int *p1)
__attribute__((nonnull));
void f(S *s) {
(s->*pmf)(0);
}
# Clang trunk emits a warning for the presence of the attribute, but not
# for passing a null argument:
$ clang -c t.cpp
t.cpp:3:20: warning: 'nonnull' attribute only applies to functions,
methods, and parameters [-Wignored-attributes]
__attribute__((nonnull));
^
1 warning generated.
# gcc (6.0) accepts the nonnull attribute and emits a warning for
# passing a null argument:
$ gcc -Wall -c t.cpp
t.cpp: In function ‘void f(S*)’:
t.cpp:5:16: warning: null argument where non-null required (argument 2)
[-Wnonnull]
(s->*pmf)(0);
^
More information about the cfe-dev
mailing list