rsandifo-arm added a comment. In D76084#1920103 <https://reviews.llvm.org/D76084#1920103>, @efriedma wrote:
> I'm not sure we actually want to reject this; let's discuss on the review for > D76086 <https://reviews.llvm.org/D76086>, since subscripting is sort of a > special case of arithmetic. A silly corner case for this is: template<typename T> constexpr __SIZE_TYPE__ f(T *x) { return &x[1] - x; } typedef int arr1[f((int *)0) - 1]; typedef int arr2[f((__SVInt8_t *)0) - 1]; which gives: a.cpp:2:48: warning: subtraction of pointers to type '__SVInt8_t' of zero size has undefined behavior [-Wpointer-arith] constexpr __SIZE_TYPE__ f(T *x) { return &x[1] - x; } ~~~~~ ^ ~ a.cpp:4:18: note: in instantiation of function template specialization 'f<__SVInt8_t>' requested here typedef int arr2[f((__SVInt8_t *)0) - 1]; ^ a.cpp:4:13: error: variable length array declaration not allowed at file scope typedef int arr2[f((__SVInt8_t *)0) - 1]; ^ No real code would do anything like this of course. But I think it shows that it's going to be difficult to divide cases that measure `sizeof` only during CodeGen from those that measure it during Sema. With more and more things being accepted as constexprs, I think it's safer to treat any measure of `sizeof` as being at least potentially computable at compile time. There's also the argument that this is what the spec says. I realise that's a fairly weak argument though, since the spec could always be changed. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D76084/new/ https://reviews.llvm.org/D76084 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits