title: How to fix warning "the compiler can assume that the address of 'object' will never be NULL"
body: <p>I use gcc8 to compile this code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class person
  {
      public:
          virtual void setage()=0;
  };
  
  void test(person &amp;object)
  {
      if (&amp;object == NULL) {
          std::cout &lt;&lt; "NULL object1" &lt;&lt; std::endl;
      }
  
      if (!(&amp;object)) 
      {
          std::cout &lt;&lt; "NULL object1" &lt;&lt; std::endl;
      }
  }
  
  int main()
  {
      person *object=NULL;
      person &amp;object1=*object;
  
      test(object1);
  }
  </code></pre>
  
  <p>Then, two warnings come out after compiling and running:</p>
  
  <blockquote>
    <p>$g++ -std=c++14 -pthread -fgnu-tm  -O2 -Wall -Wextra -pedantic -pthread
    -pedantic-errors main.cpp -lm  -latomic -lstdc++fs  &amp;&amp; ./a.out</p>
    
    <p>main.cpp: In function 'void test(person&amp;)':</p>
    
    <p>main.cpp:11:17: warning: the compiler can assume that the address of
    'object' will never be NULL [-Waddress]</p>
  
  <pre><code> if (&amp;object == NULL) {
  
               ^
  </code></pre>
    
    <p>main.cpp:15:18: warning: the compiler can assume that the address of
    'object' will never be NULL [-Waddress]</p>
  
  <pre><code> if (!(&amp;object))
  
                ^
  </code></pre>
    
    <p>main.cpp:15:5: warning: nonnull argument 'object' compared to NULL
    [-Wnonnull-compare]</p>
  
  <pre><code> if (!(&amp;object))
  
   ^~
  </code></pre>
    
    <p>main.cpp:11:5: warning: nonnull argument 'object' compared to NULL
    [-Wnonnull-compare]</p>
  
  <pre><code> if (&amp;object == NULL) {
  
   ^~
  </code></pre>
  </blockquote>
  
  <ol>
  <li>Why is the address of <code>object</code> in function <code>test</code> not NULL even passing a NULL reference value to it?</li>
  <li>It seems that reference <code>object</code> in function <code>test</code> can never be NULL, so we can just remove the code <code>if (&amp;object == NULL){...}</code> and <code>if (&amp;object == NULL) {...}</code> to avoid these two warnings, right?</li>
  </ol>
  
  <p>Thanks for hints.</p>