brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 61e71fd Raw
32 lines · cpp
1// RUN: %clang_analyze_cc1 -std=c++14 -w -analyzer-checker=core,cplusplus -analyzer-output=text -verify %s2 3namespace no_crash_on_delete_dtor {4// We were crashing when producing diagnostics for this code, but not for the5// report that it currently emits. Instead, Static Analyzer was thinking that6// p.get()->foo() is a null dereference because it was dropping7// constraints over x too early and took a different branch next time8// we call .get().9struct S {10  void foo();11  ~S();12};13 14struct smart_ptr {15  int x;16  S *s;17  smart_ptr(S *);18  S *get() {19    return (x || 0) ? nullptr : s; // expected-note{{Field 'x' is 0}}20                                   // expected-note@-1{{Left side of '||' is false}}21                                   // expected-note@-2{{'?' condition is false}}22                                   // expected-warning@-3{{Use of memory after it is released}}23                                   // expected-note@-4{{Use of memory after it is released}}24  }25};26 27void bar(smart_ptr p) {28  delete p.get(); // expected-note{{Memory is released}}29  p.get()->foo(); // expected-note{{Calling 'smart_ptr::get'}}30}31} // namespace no_crash_on_delete_dtor32