[cfe-dev] False warning in recent clang

Richard Smith richard at metafoo.co.uk
Fri Jun 22 14:46:51 PDT 2012


FYI, this is PR13127.

On Fri, Jun 22, 2012 at 1:23 PM, Richard Trieu <rtrieu at google.com> wrote:
> On Fri, Jun 22, 2012 at 11:51 AM, John McCall <rjmccall at apple.com> wrote:
>>
>> On Jun 22, 2012, at 4:59 AM, James Dennett wrote:
>> > On Fri, Jun 22, 2012 at 4:30 AM, Konstantin Tokarev <annulen at yandex.ru>
>> > wrote:
>> >> Hi all,
>> >>
>> >> After recent clang update I'm getting new warnings from Qt headers:
>> >>
>> >>
>> >> /usr/local/Trolltech/Qt-4.8.0/include/QtCore/qsharedpointer_impl.h:595:43:
>> >> warning: field is uninitialized when used here [-Wuninitialized]
>> >>    inline QWeakPointer(X *ptr) : d(ptr ? d->getAndRef(ptr) : 0),
>> >> value(ptr)
>> >>                                          ^
>> >>
>> >> (caret is pointing at 'd' before '->getAndRef')
>> >>
>> >> Here is complete piece of subject code:
>> >>
>> >> template <class X>
>> >> inline QWeakPointer(X *ptr) : d(ptr ? d->getAndRef(ptr) : 0),
>> >> value(ptr)
>> >> { }
>> >>
>> >> where getAndRef is static method, so value of d is not needed here. I
>> >> assume this warning should not be emitted.
>> >
>> > The warning seems valid, and the code should be fixed.
>> > d->getAndRef(ptr) requires that d be evaluated even if getAndRef is
>> > static, just as f()->getAndRef(ptr) would be required to call f(),
>> > even though the result would be discarded.
>>
>> 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.
>>
>> John.
>>
> 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.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>




More information about the cfe-dev mailing list