<div style="font-family: arial, helvetica, sans-serif"><font size="2"><div class="gmail_quote">On Fri, Jun 22, 2012 at 11:51 AM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com" target="_blank">rjmccall@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Jun 22, 2012, at 4:59 AM, James Dennett wrote:<br>
> On Fri, Jun 22, 2012 at 4:30 AM, Konstantin Tokarev <<a href="mailto:annulen@yandex.ru">annulen@yandex.ru</a>> wrote:<br>
>> Hi all,<br>
>><br>
>> After recent clang update I'm getting new warnings from Qt headers:<br>
>><br>
>> /usr/local/Trolltech/Qt-4.8.0/include/QtCore/qsharedpointer_impl.h:595:43: warning: field is uninitialized when used here [-Wuninitialized]<br>
>> inline QWeakPointer(X *ptr) : d(ptr ? d->getAndRef(ptr) : 0), value(ptr)<br>
>> ^<br>
>><br>
>> (caret is pointing at 'd' before '->getAndRef')<br>
>><br>
>> Here is complete piece of subject code:<br>
>><br>
>> template <class X><br>
>> inline QWeakPointer(X *ptr) : d(ptr ? d->getAndRef(ptr) : 0), value(ptr)<br>
>> { }<br>
>><br>
>> where getAndRef is static method, so value of d is not needed here. I assume this warning should not be emitted.<br>
><br>
> The warning seems valid, and the code should be fixed.<br>
> d->getAndRef(ptr) requires that d be evaluated even if getAndRef is<br>
> static, just as f()->getAndRef(ptr) would be required to call f(),<br>
> even though the result would be discarded.<br>
<br>
</div>Yes, the base expression must be evaluated, meaning that the pointer value must be loaded; however, since that value is immediately ignored, this is innocuous, and no undefined behavior is invoked.<br>
<span class="HOEnZb"><font color="#888888"><br>
John.<br>
</font></span><div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div>This looks like the result of r158477 which extended the -Wuninitialized checking on field initializers. This only happens when dereferencing pointers. If d was a class instead of a pointer to a class, this warning would not have triggered. It should be possible to special case this during the field check to ignore static calls on a dereferenced pointer.</div>
</div></font></div>