7
7
// RUN: %clang_cc1 -std=c++20 -fblocks -include %s %s 2>&1 | FileCheck --allow-empty %s
8
8
// CHECK-NOT: [-Wunsafe-buffer-usage]
9
9
10
+ #include < stdint.h>
10
11
#ifndef INCLUDED
11
12
#define INCLUDED
12
13
#pragma clang system_header
@@ -90,15 +91,18 @@ void cast_without_data(int *ptr) {
90
91
void warned_patterns (std::span<int > span_ptr, std::span<Base> base_span, span<int > span_without_qual) {
91
92
A *a1 = (A*)span_ptr.data (); // expected-warning{{unsafe invocation of span::data}}
92
93
a1 = (A*)span_ptr.data (); // expected-warning{{unsafe invocation of span::data}}
93
-
94
- A *a2 = (A*) span_without_qual.data (); // expected-warning{{unsafe invocation of span::data}}
95
-
96
- // TODO:: Should we warn when we cast from base to derived type?
97
- Derived *b = dynamic_cast <Derived*> (base_span.data ());// expected-warning{{unsafe invocation of span::data}}
98
94
99
- // TODO:: This pattern is safe. We can add special handling for it, if we decide this
100
- // is the recommended fixit for the unsafe invocations.
101
- A *a3 = (A*)span_ptr.subspan (0 , sizeof (A)).data (); // expected-warning{{unsafe invocation of span::data}}
95
+ a1 = (A*)(span_ptr.data ()); // expected-warning{{unsafe invocation of span::data}}
96
+ A *a2 = (A*) (span_without_qual.data ()); // expected-warning{{unsafe invocation of span::data}}
97
+
98
+ a2 = (A*) span_without_qual.data (); // expected-warning{{unsafe invocation of span::data}}
99
+
100
+ // TODO:: Should we warn when we cast from base to derived type?
101
+ Derived *b = dynamic_cast <Derived*> (base_span.data ());// expected-warning{{unsafe invocation of span::data}}
102
+
103
+ // TODO:: This pattern is safe. We can add special handling for it, if we decide this
104
+ // is the recommended fixit for the unsafe invocations.
105
+ A *a3 = (A*)span_ptr.subspan (0 , sizeof (A)).data (); // expected-warning{{unsafe invocation of span::data}}
102
106
}
103
107
104
108
void not_warned_patterns (std::span<A> span_ptr, std::span<Base> base_span) {
@@ -108,6 +112,9 @@ void not_warned_patterns(std::span<A> span_ptr, std::span<Base> base_span) {
108
112
109
113
p = (int *) span_ptr.data ();
110
114
A *a = (A*) span_ptr.hello (); // Invoking other methods.
115
+
116
+ intptr_t k = (intptr_t ) span_ptr.data ();
117
+ k = (intptr_t ) (span_ptr.data ());
111
118
}
112
119
113
120
// We do not want to warn about other types
0 commit comments