"Fossies" - the Fresh Open Source Software Archive

Member "cfe-9.0.0.src/test/Analysis/rvo.cpp" (1 Jul 2019, 550 Bytes) of package /linux/misc/cfe-9.0.0.src.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // RUN: %clang_analyze_cc1 -analyzer-checker core,cplusplus \
    2 // RUN:                    -analyzer-checker debug.ExprInspection -verify %s
    3 
    4 void clang_analyzer_eval(bool);
    5 
    6 struct A {
    7   int x;
    8 };
    9 
   10 A getA();
   11 
   12 struct B {
   13   int *p;
   14   A a;
   15 
   16   B(int *p) : p(p), a(getA()) {}
   17 };
   18 
   19 void foo() {
   20   B b1(nullptr);
   21   clang_analyzer_eval(b1.p == nullptr); // expected-warning{{TRUE}}
   22   B b2(new int); // No leak yet!
   23   clang_analyzer_eval(b2.p == nullptr); // expected-warning{{FALSE}}
   24   // expected-warning@-1{{Potential leak of memory pointed to by 'b2.p'}}
   25 }