<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - adding zero to null pointer rejected in constant expressions"
   href="http://llvm.org/bugs/show_bug.cgi?id=19346">19346</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>adding zero to null pointer rejected in constant expressions
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>zilla@kayari.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>constexpr int* p = nullptr;
constexpr int n = 0;
constexpr int* p2 = p + n;

a.cc:3:16: error: constexpr variable 'p2' must be initialized by a constant
expression
constexpr int* p2 = p + n;
               ^    ~~~~~
a.cc:3:23: note: cannot perform pointer arithmetic on null pointer
constexpr int* p2 = p + n;
                      ^

Th last paragraph of [expr.add] says "If the value 0 is added to or subtracted
from a pointer value, the result compares equal to the original pointer value."
 I believe that should also apply for a null pointer.

Rejecting this makes it more awkward to define end() in the code below:

struct initializer_list {
  constexpr initializer_list() : b(nullptr), sz(0) { }
  constexpr int* begin() const { return b; }
  constexpr int* end() const { return b+sz; }
  int* b;
  unsigned sz;
};

constexpr initializer_list il;
constexpr int* p = il.end();</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>