diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:49:41 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:49:41 +0000 |
| commit | 45b533945f0851ec234ca846e1af5ee1e4df0b6e (patch) | |
| tree | 0a5b74c0b9ca73aded34df95c91fcaf3815230d8 /test/Analysis/initializer.cpp | |
| parent | 7e86edd64bfae4e324224452e4ea879b3371a4bd (diff) | |
Notes
Diffstat (limited to 'test/Analysis/initializer.cpp')
| -rw-r--r-- | test/Analysis/initializer.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/Analysis/initializer.cpp b/test/Analysis/initializer.cpp index a71e35dc63c6..b31c315ba524 100644 --- a/test/Analysis/initializer.cpp +++ b/test/Analysis/initializer.cpp @@ -143,3 +143,57 @@ namespace DefaultMemberInitializers { clang_analyzer_eval(w.p[1] == 'y'); // expected-warning{{TRUE}} } } + +namespace ReferenceInitialization { + struct OtherStruct { + OtherStruct(int i); + ~OtherStruct(); + }; + + struct MyStruct { + MyStruct(int i); + MyStruct(OtherStruct os); + + void method() const; + }; + + void referenceInitializeLocal() { + const MyStruct &myStruct(5); + myStruct.method(); // no-warning + } + + void referenceInitializeMultipleLocals() { + const MyStruct &myStruct1(5), myStruct2(5), &myStruct3(5); + myStruct1.method(); // no-warning + myStruct2.method(); // no-warning + myStruct3.method(); // no-warning + } + + void referenceInitializeLocalWithCleanup() { + const MyStruct &myStruct(OtherStruct(5)); + myStruct.method(); // no-warning + } + + struct HasMyStruct { + const MyStruct &ms; // expected-note {{reference member declared here}} + const MyStruct &msWithCleanups; // expected-note {{reference member declared here}} + + // clang's Sema issues a warning when binding a reference member to a + // temporary value. + HasMyStruct() : ms(5), msWithCleanups(OtherStruct(5)) { + // expected-warning@-1 {{binding reference member 'ms' to a temporary value}} + // expected-warning@-2 {{binding reference member 'msWithCleanups' to a temporary value}} + + // At this point the members are not garbage so we should not expect an + // analyzer warning here even though binding a reference member + // to a member is a terrible idea. + ms.method(); // no-warning + msWithCleanups.method(); // no-warning + } + }; + + void referenceInitializeField() { + HasMyStruct hms; + } + +}; |
