Clang Project

clang_source_code/test/Analysis/new-ctor-null-throw.cpp
1// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
2
3void clang_analyzer_eval(bool);
4
5typedef __typeof__(sizeof(int)) size_t;
6
7
8// These are ill-formed. One cannot return nullptr from a throwing version of an
9// operator new.
10void *operator new(size_t size) {
11  return nullptr;
12}
13void *operator new[](size_t size) {
14  return nullptr;
15}
16
17struct S {
18  int x;
19  S() : x(1) {}
20  ~S() {}
21};
22
23void testArrays() {
24  S *s = new S[10]; // no-crash
25  s[0].x = 2; // expected-warning{{Dereference of null pointer}}
26}
27