Clang Project

clang_source_code/test/Analysis/new-dynamic-types.cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core -std=c++11 -verify %s
2
3// expected-no-diagnostics
4
5typedef __typeof(sizeof(int)) size_t;
6
7void *operator new(size_t size, void *ptr);
8
9struct B {
10  virtual void foo();
11};
12
13struct D : public B {
14  virtual void foo() override {}
15};
16
17void test_ub() {
18  // FIXME: Potentially warn because this code is pretty weird.
19  B b;
20  new (&b) D;
21  b.foo(); // no-crash
22}
23
24void test_non_ub() {
25  char c[sizeof(D)]; // Should be enough storage.
26  new (c) D;
27  ((B *)c)->foo(); // no-crash
28}
29