[LLVMbugs] [Bug 19346] New: adding zero to null pointer rejected in constant expressions

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Apr 4 11:21:36 PDT 2014


            Bug ID: 19346
           Summary: adding zero to null pointer rejected in constant
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zilla at kayari.org
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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
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();

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140404/217f4d95/attachment.html>

More information about the llvm-bugs mailing list