ldionne wrote:

Ok so after scratching my head a bit, I'm actually not certain of how to 
proceed with this. I can't find a way to implement `__libcpp_datasizeof` in 
libc++ that doesn't involve `offsetof`, so our only option would be to silence 
the warning. We could do it like (if we end up doing that, just take that diff 
and incorporate it to your patch, we can land both at once and the libc++ CI 
will also trigger):

```
diff --git a/libcxx/include/__type_traits/datasizeof.h 
b/libcxx/include/__type_traits/datasizeof.h
index 019099a9cf18..88a702470c3c 100644
--- a/libcxx/include/__type_traits/datasizeof.h
+++ b/libcxx/include/__type_traits/datasizeof.h
@@ -47,7 +47,11 @@ struct __libcpp_datasizeof {
   };
 #endif
 
+  _LIBCPP_DIAGNOSTIC_PUSH
+  _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-offsetof")
+  _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Winvalid-offsetof")
   static const size_t value = offsetof(_FirstPaddingByte<>, 
__first_padding_byte_);
+  _LIBCPP_DIAGNOSTIC_POP
 };
 
 _LIBCPP_END_NAMESPACE_STD
```

However, in C++03, using `offsetof` with a non-POD is undefined behavior (hence 
the warning, I guess). So we'd technically have UB in our code here, which 
isn't great. In C++17 doing that is conditionally supported, so I guess we're 
fine.

So... should we strive to eradicate this from libc++ in the first place, or 
should we just silence the warning. WDYT?

Also, given that it is conditionally supported in C++17, I assume this warning 
doesn't trigger at all in C++17 mode, right?

https://github.com/llvm/llvm-project/pull/65246
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to