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
[Clang] Fix cleanup attribute by delaying type checks after the type is deduced (#164440)
Previously, the handling of the `cleanup` attribute had some checks
based on the type, but we were deducing the type after handling the
attribute.
This PR fixes the way the are dealing with type checks for the `cleanup`
attribute by delaying these checks after we are deducing the type.
It is also fixed in a way that the solution can be adapted for other
attributes that does some type based checks.
This is the list of C/C++ attributes that are doing type based checks
and will need to be fixed in additional PRs:
- CUDAShared
- MutualExclusions
- PassObjectSize
- InitPriority
- Sentinel
- AcquireCapability
- RequiresCapability
- LocksExcluded
- AcquireHandle
NB: Some attributes could have been missed in my shallow search.
Fixes#129631
floatfd_invalid [[gnu::cleanup(close)]] =open(); // expected-error {{'cleanup' function 'close' parameter has type 'typeof (open()) *' (aka 'int *') which is incompatible with type 'float *'}}
Copy file name to clipboardExpand all lines: clang/test/SemaCXX/attr-cleanup.cpp
+25Lines changed: 25 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -27,3 +27,28 @@ namespace E {
27
27
int v1 __attribute__((cleanup(c3))); // expected-error {{'c3' is not a single function}}
28
28
}
29
29
}
30
+
31
+
namespaceF {
32
+
intopen() { return0; }
33
+
voidclose(decltype(open()) *) {}
34
+
35
+
voidtest1() {
36
+
auto fd [[gnu::cleanup(close)]] = open();
37
+
}
38
+
39
+
template <typename Ty>
40
+
voidtest2() {
41
+
Ty fd [[gnu::cleanup(close)]] = open();
42
+
}
43
+
44
+
template <typename Ty>
45
+
voidtest3() {
46
+
Ty fd [[gnu::cleanup(close)]] = open(); // #TEST3_CLEANUP
47
+
}
48
+
49
+
intmain() {
50
+
test2<int>();
51
+
test3<float>(); // expected-error@#TEST3_CLEANUP {{'cleanup' function 'close' parameter has type 'decltype(open()) *' (aka 'int *') which is incompatible with type 'float *'}} \
52
+
expected-note {{in instantiation of function template specialization 'F::test3<float>' requested here}}
0 commit comments