diff options
author | dim <dim@FreeBSD.org> | 2015-12-30 11:49:41 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2015-12-30 11:49:41 +0000 |
commit | 3176e97f130184ece0e1a21352c8124cc83ff24a (patch) | |
tree | 0a5b74c0b9ca73aded34df95c91fcaf3815230d8 /test/Analysis/initializer.cpp | |
parent | 1e9b8d38881c3213d1e67b0c47ab9b2c00721a5c (diff) | |
download | FreeBSD-src-3176e97f130184ece0e1a21352c8124cc83ff24a.zip FreeBSD-src-3176e97f130184ece0e1a21352c8124cc83ff24a.tar.gz |
Vendor import of clang trunk r256633:
https://llvm.org/svn/llvm-project/cfe/trunk@256633
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 a71e35d..b31c315 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; + } + +}; |