<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi,<br>
    </p>
    <div class="moz-cite-prefix">On 20/09/2021 13:33, via cfe-dev wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:00c001d7ae1b$a74891e0$f5d9b5a0$@gmail.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style>@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}div.WordSection1
        {page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal"><span lang="EN-US">Hi,<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">Let’s examine this code
            snippet:<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">  void
            simply_deref_null() {<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">    int *p = 0;<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">    *p ; // no warning?<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">    *p = 42; // warns!<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">  }<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">Turns out the
            NullDereference checker treats the two pointer derefs
            differently.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">For simply reading
            through a null pointer is allowed but storing a value is
            prohibited.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">Why don't we prohibit
            reading through null pointers?</span></p>
      </div>
    </blockquote>
    <p>Reads through null pointers do trigger the warning as well.
      However, there is no read through a null pointer here.
      Dereferencing a pointer produces an lvalue, not an rvalue, and
      discarding an lvalue expression does not cause a load.</p>
    <p>If you change the example to, for example,</p>
    <pre>int simply_deref_null() {
  int *p = 0;
  return *p;
}</pre>
    <p>you will see:</p>
    <pre>test.cc:3:10: warning: Dereference of null pointer (loaded from variable 'p') [core.NullDereference]
  return *p;
         ^~
</pre>
    <p>Cheers,<br>
      Harald van Dijk<br>
    </p>
  </body>
</html>