You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[LifetimeSafety] Extend suggestions for lifetimebound to also warn on canonical declarations (llvm#198784)
With this patch, we suggest adding the `clang::lifetimebound` attribute
on the canonical declaration and on the earliest redeclaration in each
other file, preserving diagnostics for declarations visible from other
translation units while avoiding duplicate suggestions within the same
file.
Fixesllvm#198624Fixesllvm#198628
Copy file name to clipboardExpand all lines: clang/test/Sema/warn-lifetime-safety-misplaced-lifetimebound-cross-tu.cpp
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -14,8 +14,18 @@ struct HeaderS {
14
14
HeaderObj &header_this(); // expected-warning {{'lifetimebound' attribute on this definition is not visible to callers in other translation units; add it to the declaration instead}}
15
15
};
16
16
17
+
//--- cross_1.h
18
+
structHeaderObj;
19
+
HeaderObj &multi_header_param(HeaderObj &obj); // expected-warning {{'lifetimebound' attribute on this definition is not visible to callers in other translation units; add it to the declaration instead}}
20
+
21
+
//--- cross_2.h
22
+
structHeaderObj;
23
+
HeaderObj &multi_header_param(HeaderObj &obj); // expected-warning {{'lifetimebound' attribute on this definition is not visible to callers in other translation units; add it to the declaration instead}}
24
+
17
25
//--- cross.cpp
18
26
#include"cross.h"
27
+
#include"cross_1.h"
28
+
#include"cross_2.h"
19
29
20
30
HeaderObj &header_param(HeaderObj &obj [[clang::lifetimebound]]) { // expected-note {{'lifetimebound' attribute appears here on the definition}}
HeaderObj &HeaderS::header_this() [[clang::lifetimebound]] { // expected-note {{'lifetimebound' attribute appears here on the definition}}
25
35
return data;
26
36
}
37
+
38
+
HeaderObj &multi_header_param(HeaderObj &obj [[clang::lifetimebound]]) { // expected-note 2 {{'lifetimebound' attribute appears here on the definition}}
MyObj &earliest_redecl_param(MyObj &obj); // expected-warning {{'lifetimebound' attribute on this definition is not visible to callers before the definition; add it to the declaration instead}}
13
+
MyObj &earliest_redecl_param(MyObj &obj);
14
+
MyObj &earliest_redecl_param(MyObj &obj [[clang::lifetimebound]]) { // expected-note {{'lifetimebound' attribute appears here on the definition}}
15
+
return obj;
16
+
}
17
+
12
18
structS {
13
19
MyObj data;
14
20
const MyObj &implicit_this_only(); // expected-warning {{'lifetimebound' attribute on this definition is not visible to callers before the definition; add it to the declaration instead}}
0 commit comments