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 false warning on reinterpret_casting unknown template type (#109430)
After 1595988
diag::warn_undefined_reinterpret_cast started raising on
non-instantiated template functions without sufficient knowledge whether
the reinterpret_cast is indeed UB.
Copy file name to clipboardExpand all lines: clang/docs/ReleaseNotes.rst
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -660,6 +660,8 @@ Improvements to Clang's diagnostics
660
660
661
661
- Don't emit bogus dangling diagnostics when ``[[gsl::Owner]]`` and `[[clang::lifetimebound]]` are used together (#GH108272).
662
662
663
+
- Don't emit bogus dignostic about an undefined behavior on ``reinterpret_cast<T>`` for non-instantiated template functions without sufficient knowledge whether it can actually lead to undefined behavior for ``T`` (#GH109430).
664
+
663
665
- The ``-Wreturn-stack-address`` warning now also warns about addresses of
664
666
local variables passed to function calls using the ``[[clang::musttail]]``
(void)*reinterpret_cast<const TARGETTYPE*>(data); // no warning
311
+
}
312
+
313
+
314
+
template <typename TARGETTYPE, typename UATYPE>
315
+
voidcast_instantiated_badly() {
316
+
const UATYPE* data;
317
+
(void)*reinterpret_cast<const TARGETTYPE*>(data); // expected-warning {{dereference of type 'const int *' that was reinterpret_cast from type 'const float *' has undefined behavior}}
318
+
}
319
+
320
+
template <typename TARGETTYPE, typename UATYPE>
321
+
voidcast_instantiated_well() {
322
+
const UATYPE* data;
323
+
(void)*reinterpret_cast<const TARGETTYPE*>(data); // no warning
324
+
}
325
+
326
+
template <typename TARGETTYPE>
327
+
voidcast_one_tmpl_arg_uninstantiated() {
328
+
constint* data;
329
+
(void)*reinterpret_cast<const TARGETTYPE*>(data); // no warning
330
+
}
331
+
332
+
template <typename TARGETTYPE>
333
+
voidcast_one_tmpl_arg_instantiated_badly() {
334
+
constfloat* data;
335
+
(void)*reinterpret_cast<const TARGETTYPE*>(data); // expected-warning {{dereference of type 'const int *' that was reinterpret_cast from type 'const float *' has undefined behavior}}
336
+
}
337
+
338
+
template <typename TARGETTYPE>
339
+
voidcast_one_tmpl_arg_instantiated_well() {
340
+
constfloat* data;
341
+
(void)*reinterpret_cast<const TARGETTYPE*>(data); // no warning
(void)*reinterpret_cast<constint*>(data); // expected-warning {{dereference of type 'const int *' that was reinterpret_cast from type 'const float *' has undefined behavior}}
0 commit comments