[PATCH] Fix to PR5683 - issue diagnostic for pointer subtraction with type of size zero.
Richard Smith
richard at metafoo.co.uk
Fri Jun 21 13:59:10 PDT 2013
================
Comment at: test/Sema/empty1.cpp:3-5
@@ +2,4 @@
+
+int func_1(int (*p1)[0], int (*p2)[0]) {
+ return p1 - p2; // expected-warning {{subtraction of pointers to type 'int [0]' of zero size has undefined behavior}}
+}
----------------
Please also add a test for the constant expression handling. Something like
constexpr int (*p1)[0] = 0, (*p2)[0] = 0;
constexpr int k = p2 - p1;
================
Comment at: lib/AST/ExprConstant.cpp:6412
@@ +6411,3 @@
+ if (ElementSize.isZero()) {
+ CCEDiag(E, diag::note_constexpr_pointer_subtraction_zero_size_types);
+ return false;
----------------
This should be a Diag not a CCEDiag, because you're bailing out.
http://llvm-reviews.chandlerc.com/D637
More information about the cfe-commits
mailing list