<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jul 13, 2015 at 2:00 PM, Tom Honermann <span dir="ltr"><<a href="mailto:thonermann@coverity.com" target="_blank">thonermann@coverity.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 07/13/2015 03:33 PM, Richard Smith wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
On Mon, Jul 13, 2015 at 10:41 AM, Joerg Sonnenberger<br></span><span class="">
<<a href="mailto:joerg@britannica.bec.de" target="_blank">joerg@britannica.bec.de</a> <mailto:<a href="mailto:joerg@britannica.bec.de" target="_blank">joerg@britannica.bec.de</a>>> wrote:<br>
<br>
    On Mon, Jul 13, 2015 at 11:31:54AM -0400, Tom Honermann wrote:<br>
    > Clang (3.4-trunk) ignores nonnull attributes on pointer-to-member-function<br>
    > declarations.<br>
<br>
    You are aware that 3.4-trunk is quite old and we are about to start the<br>
    3.7 release cycle?<br>
<br>
<br>
I read that as "from version 3.4 to trunk"<br>
</span></blockquote>
<br>
And that is how I intended it.<span class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
And it's true: clang trunk<br>
still behaves as described. But I'm a bit confused, because the<br>
referenced GCC bug report says they made this work:<br>
<br>
struct Foo;<br>
void foo (void (Foo::*) () __attribute__ ((nonnull)));<br>
<br>
... where the attribute would presumably apply to the pointer-to-member,<br>
and the request is to support this:<br>
<br>
void (S::*pmf)(int *p1)<br>
     __attribute__((nonnull));<br>
<br>
... where the attribute (again, presumably) jumps over the<br>
pointer-to-member and applies to the pointer parameter? This does not<br>
seem consistent. What is the actual GCC behavior?<br>
</blockquote>
<br></span>
Interesting.  It didn't occur to me that the case in the gcc bug report is ambiguous with respect to Clang's support for infix nonnull attributes.<br>
<br>
As specified, the attribute is either an infix attribute specifying that the pointer-to-member-function parameter value must not be null, or it is a non-infix attribute specifying that all of the parameters of the target of the pointer-to-member-function must not be null.<br>
<br>
I don't think gcc supports infix nonnull attributes, so I believe the latter behavior is what is intended.  gcc compiler warnings appear to bear this out:<span class=""><br>
<br>
$ cat t.cpp<br>
struct S;<br></span>
void f1(S *s, void (S::*pmf)(void*) __attribute__ ((nonnull))) {<br>
    (s->*pmf)(0);<br>
}<br>
void f2(S *s) {<br>
    f1(s, 0);<br>
}<br>
<br>
$ gcc -c -Wall t.cpp<br>
t.cpp: In function ‘void f1(S*, void (S::*)(void*))’:<br>
t.cpp:3:16: warning: null argument where non-null required (argument 2) [-Wnonnull]<br>
     (s->*pmf)(0);<br>
                ^<br>
<br>
Note that there is a warning when passing a null argument with the pointer-to-member-function invocation, but not when passing a null argument as the pointer-to-member-function value.</blockquote><div><br></div><div>OK, we'll need to figure out how to integrate this into our __attribute__((nonnull)) semantics. Please do file that PR so we don't forget! </div></div></div></div>