blob: e8858787839d29507195cad9fa6dabac74390f2c [file] [log] [blame]
Anna Zaksbfa9ab82013-01-24 23:15:30 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify -w %s
Jordan Rose73212df2012-08-29 01:11:59 +00002
3struct Trivial {
4 Trivial(int x) : value(x) {}
5 int value;
6};
7
8struct NonTrivial : public Trivial {
9 NonTrivial(int x) : Trivial(x) {}
10 ~NonTrivial();
11};
12
13
14Trivial getTrivial() {
15 return Trivial(42); // no-warning
16}
17
18const Trivial &getTrivialRef() {
Jordan Rosebc403862013-02-15 00:32:15 +000019 return Trivial(42); // expected-warning {{Address of stack memory associated with temporary object of type 'const struct Trivial' returned to caller}}
Jordan Rose73212df2012-08-29 01:11:59 +000020}
21
22
23NonTrivial getNonTrivial() {
24 return NonTrivial(42); // no-warning
25}
26
27const NonTrivial &getNonTrivialRef() {
Jordan Rosebc403862013-02-15 00:32:15 +000028 return NonTrivial(42); // expected-warning {{Address of stack memory associated with temporary object of type 'const struct NonTrivial' returned to caller}}
Jordan Rose73212df2012-08-29 01:11:59 +000029}
30