<p>qualifying the pointer with volatile works, and is only a touch awkward. We've already done this for one copy, I'll update the main open source version as soon as I'm able. </p>
<div class="gmail_quote">On Jan 28, 2012 4:21 PM, "Nico Weber" <<a href="mailto:thakis@chromium.org">thakis@chromium.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Eli,<br>
<br>
with this change, clang now warns about this function in gtest (which is fine):<br>
<br>
// Invalid<T>() returns an invalid value of type T.  This is useful<br>
// when a value of type T is needed for compilation, but the statement<br>
// will not really be executed (or we don't care if the statement<br>
// crashes).<br>
template <typename T><br>
inline T Invalid() {<br>
  return *static_cast<typename remove_reference<T>::type*>(NULL);<br>
}<br>
<br>
The warning recommends to add a "volatile", but then code that calls<br>
this function with a type without copy constructor fails to compile.<br>
What's the recommended way to change code like this?<br>
<br>
Should the -Wnull-dereference diagnostic text be changed to something<br>
else in an expression context? It currently says "consider using<br>
__builtin_trap() or qualifying pointer with 'volatile'".<br>
<br>
Thanks,<br>
Nico<br>
<br>
On Tue, Jan 24, 2012 at 2:51 PM, Eli Friedman <<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>> wrote:<br>
> Author: efriedma<br>
> Date: Tue Jan 24 16:51:26 2012<br>
> New Revision: 148874<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=148874&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=148874&view=rev</a><br>
> Log:<br>
> Switch PerformImplicitConversion over to use DefaultLvalueConversion for lvalue-to-rvalue conversion.<br>
><br>
><br>
> Modified:<br>
>    cfe/trunk/lib/Sema/SemaExprCXX.cpp<br>
>    cfe/trunk/test/Analysis/reference.cpp<br>
><br>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=148874&r1=148873&r2=148874&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=148874&r1=148873&r2=148874&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)<br>
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Jan 24 16:51:26 2012<br>
> @@ -2324,12 +2324,14 @@<br>
>     // Nothing to do.<br>
>     break;<br>
><br>
> -  case ICK_Lvalue_To_Rvalue:<br>
> +  case ICK_Lvalue_To_Rvalue: {<br>
>     assert(From->getObjectKind() != OK_ObjCProperty);<br>
>     FromType = FromType.getUnqualifiedType();<br>
> -    From = ImplicitCastExpr::Create(Context, FromType, CK_LValueToRValue,<br>
> -                                    From, 0, VK_RValue);<br>
> +    ExprResult FromRes = DefaultLvalueConversion(From);<br>
> +    assert(!FromRes.isInvalid() && "Can't perform deduced conversion?!");<br>
> +    From = FromRes.take();<br>
>     break;<br>
> +  }<br>
><br>
>   case ICK_Array_To_Pointer:<br>
>     FromType = Context.getArrayDecayedType(FromType);<br>
><br>
> Modified: cfe/trunk/test/Analysis/reference.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/reference.cpp?rev=148874&r1=148873&r2=148874&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/reference.cpp?rev=148874&r1=148873&r2=148874&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/test/Analysis/reference.cpp (original)<br>
> +++ cfe/trunk/test/Analysis/reference.cpp Tue Jan 24 16:51:26 2012<br>
> @@ -1,4 +1,4 @@<br>
> -// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core -analyzer-store=region -analyzer-constraints=range -verify %s<br>
> +// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core -analyzer-store=region -analyzer-constraints=range -verify -Wno-null-dereference %s<br>
>  // XFAIL<br>
><br>
>  typedef typeof(sizeof(int)) size_t;<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>