https://bugs.llvm.org/show_bug.cgi?id=49860

            Bug ID: 49860
           Summary: allocation function should not be called for erroneous
                    expression
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++17
          Assignee: unassignedclangb...@nondot.org
          Reporter: zi...@kayari.org
                CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
                    llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk

namespace std {
  using size_t = decltype(sizeof(0));
}

extern "C" void abort();
extern "C" int puts(const char*);

struct X
{
  void* operator new[](std::size_t) noexcept {
    puts("should not be here");
    abort();
    return nullptr;
  }

  int data;
};

int main()
{
  int n = -1;
  auto p = new X[n];
  if (p)
    abort();
}

This terminates with:

should not be here
Aborted (core dumped)

The allocation function should not be called, because the expression -1 is
erroneous. In C++14 the new-expression should throw std::bad_array_new_length,
in C++17 it should yield (X*)0 because the allocation function is non-throwing.
But in both cases the allocation function should not be called.

It doesn't seem to matter whether the expression is a non-class type less than
zero, or a class type that converts to an integer less than zero, or whether
it's a value is such that the size of the allocated object would be larger than
the entire address space. In all three cases the erroneous value is not
detected and the allocation function is called (except when the erroneous value
is a core constant expression, which gets detected since the fix for Bug
22845).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to