[LLVMbugs] [Bug 24133] New: Enable support for nonnull attributes that appertain to pointer-to-member-function declarations
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Jul 15 10:23:01 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=24133
Bug ID: 24133
Summary: Enable support for nonnull attributes that appertain
to pointer-to-member-function declarations
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: thonermann at coverity.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Recent versions of gcc allow application of nonnull attributes to pointer to
member function declarations:
$ cat t.cpp
struct S {
void mf(void*);
};
void f(S *s) {
void (S::*pmf)(void *) __attribute__((nonnull)) = &S::mf;
(s->*pmf)(0);
}
$ gcc --version
gcc (GCC) 6.0.0 20150413 (experimental)
...
$ gcc -Wall -c t.cpp
t.cpp: In function ‘void f(S*)’:
t.cpp:6:16: warning: null argument where non-null required (argument 2)
[-Wnonnull]
(s->*pmf)(0);
^
Clang (3.4-3.6, trunk) rejects such attributes:
$ clang -c t.cpp
t.cpp:5:43: warning: 'nonnull' attribute only applies to functions, methods,
and parameters [-Wignored-attributes]
void (S::*pmf)(void *) __attribute__((nonnull)) = &S::mf;
^
1 warning generated.
gcc also allows these attributes to be specified on parameters of pointer to
member function type:
$ cat t2.cpp
struct S;
void f1(S *s, void (S::*pmf)(void*) __attribute__ ((nonnull))) {
(s->*pmf)(0);
}
void f2(S *s) {
f1(s, 0);
}
$ gcc -Wall -c t.cpp
t.cpp: In function ‘void f(S*)’:
t.cpp:6:16: warning: null argument where non-null required (argument 2)
[-Wnonnull]
(s->*pmf)(0);
^
Note that there is a warning when passing a null argument for the function
invocation using the pointer to member function variable, but not when passing
a null argument as the pointer to member function value. This indicates that
gcc applies the attribute to the member function type of the parameter
declaration, not to the parameter declaration itself.
Clang (3.4-3.6, trunk) rejects such attributes here as well:
$ clang -c t2.cpp
t2.cpp:2:53: warning: 'nonnull' attribute only applies to functions
[-Wignored-attributes]
void f1(S *s, void (S::*pmf)(void*) __attribute__ ((nonnull))) {
^
1 warning generated.
Clang 3.5 added support for infix nonnull attributes on parameter declarations
that uses the above syntax. This resulted in an ambiguity for parameters of
function pointer type; does the attribute appertain to the parameter
declaration or to the type of the declaration? Consider this example:
$ cat t3.cpp
void f1(void (*pf)(void*) __attribute__((nonnull))) {
pf(0);
}
void f2() {
f1(0);
}
In Clang 3.4, the attribute appertained to the function type of the parameter
declaration (a warning is emitted for line 2). In Clang 3.5, it appertained to
the parameter declaration (and not to the function type of the parameter
declaration - a warning is emitted for line 5). In Clang 3.6, it appertains to
*both* the function type of the parameter and the parameter declaration
(warnings are emitted for lines 2 and 5 of t3.cpp).
Presumably, nonnull attributes on parameters of pointer to member function type
should work the same way; the attribute should apply to both the parameter and
the pointer to member function type of the parameter.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150715/ba645a43/attachment.html>
More information about the llvm-bugs
mailing list