[PATCH] Sema: Warn on sizeof on binary ops on decayed arrays.

Benjamin Kramer benny.kra at gmail.com
Sun Mar 24 08:27:37 PDT 2013



================
Comment at: lib/Sema/SemaExpr.cpp:3115-3118
@@ +3114,6 @@
+          << BO->getLHS()->getType() << LHSICE->getSubExpr()->getType();
+      else if (!LHSDecay && RHSDecay && BO->getType() == RHSICE->getType())
+        Diag(BO->getOperatorLoc(), diag::warn_sizeof_array_decay)
+          << BO->getRHS()->getSourceRange()
+          << BO->getRHS()->getType() << RHSICE->getSubExpr()->getType();
+    }
----------------
Sean Silva wrote:
> This checks "sizeof(x op array)", right? If so, the comment above probably should at least mention it. Also, would it be feasible to factor out this whole diagnostic check into a static helper?
Fixed the comment. We could hoist the whole thing into a static helper but I fail to see the value of it right now. We can't really hoist parts out because the checks depend on each other to avoid the case where both sides are decayed arrays. It's debatable whether this really happens in practice though.


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



More information about the cfe-commits mailing list