[PATCH] Fix to PR5683 - issue diagnostic for pointer subtraction with type of size zero.

Serge Pavlov sepavloff at gmail.com
Sat Jun 22 03:53:20 PDT 2013



================
Comment at: lib/AST/ExprConstant.cpp:6412
@@ +6411,3 @@
+        if (ElementSize.isZero()) {
+          CCEDiag(E, diag::note_constexpr_pointer_subtraction_zero_size_types);
+          return false;
----------------
Richard Smith wrote:
> This should be a Diag not a CCEDiag, because you're bailing out.
It looks like diagnostic isn't needed at all. There is nothing specific to constantness, warning about pointer subtraction has been already emitted. The expression may be evaluated to some constant, say, zero as it doesn't break constantness.

================
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}}
+}
----------------
Richard Smith wrote:
> 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;
OK


http://llvm-reviews.chandlerc.com/D637



More information about the cfe-commits mailing list