title: Are nullptr references undefined behaviour in C++?
body: <p>The following code fools around with <code>nullptr</code> pointer and reference:</p>
  
  <pre><code>#include &lt;cstdio&gt;
  
  void printRefAddr(int &amp;ref) {
      printf("printAddr %p\n", &amp;ref);
  }
  
  int main() {    
      int *ip = nullptr;
      int &amp;ir = *ip;
  
      // 1. get address of nullptr reference
      printf("ip=%p &amp;ir=%p\n", ip, &amp;ir);
  
      // 2. dereference a nullptr pointer and pass it as reference
      printRefAddr(*ip);
  
      // 3. pass nullptr reference
      printRefAddr(ir);
  
      return 0;
  }
  </code></pre>
  
  <p><strong>Question</strong>: In C++ standards, are commented statements 1..3 valid code or undefined behavior?</p>
  
  <p>Is this same or different with different versions of C++ (older ones would of course use <code>0</code> literal instead of <code>nullptr</code> keyword)?</p>
  
  <p>Bonus question: are there known compilers / optimization options, which would actually cause above code to do something unexpected / crash? For example, is there a flag for any compiler, which would generate implicit assertion for <code>nullptr</code> everywhere where reference is initialized, including passing reference argument from <code>*ptr</code>?</p>
  
  <hr>
  
  <p>An example output for the curious, nothing unexpected:</p>
  
  <pre><code>ip=(nil) &amp;ir=(nil)
  printAddr (nil)
  printAddr (nil)
  </code></pre>