[PATCH] Make Clang error on enum increment/decrement in C++
Arthur O'Dwyer
arthur.j.odwyer at gmail.com
Tue Jul 23 20:22:29 PDT 2013
Even though I'm pretty sure your patch doesn't affect them, it might
be worth adding a test to make sure that user-defined operator++
overloads are still accepted:
enum A { apple, banana };
inline A &operator++ (A &a) { a = A((int)a+1); return a; }
inline A operator++ (A &a, int) { A oa = a; ++a; return oa; }
void foo(enum A a) { ++a; a++; }
-Arthur
On Tue, Jul 23, 2013 at 5:59 PM, Richard Trieu <rtrieu at google.com> wrote:
> Patch for PR16394, new error for enum increment/decrement.
>
> http://llvm-reviews.chandlerc.com/D1205
>
> Files:
> lib/Sema/SemaExpr.cpp
> test/SemaCXX/enum-increment.cpp
> include/clang/Basic/DiagnosticSemaKinds.td
>
> Index: lib/Sema/SemaExpr.cpp
> ===================================================================
> --- lib/Sema/SemaExpr.cpp
> +++ lib/Sema/SemaExpr.cpp
> @@ -8302,6 +8302,10 @@
> }
> // Increment of bool sets it to true, but is deprecated.
> S.Diag(OpLoc, diag::warn_increment_bool) << Op->getSourceRange();
> + } else if (S.getLangOpts().CPlusPlus && ResType->isEnumeralType()) {
> + // Error on enum increments and decrements in C++ mode
> + S.Diag(OpLoc, diag::err_increment_decrement_enum) << IsInc << ResType;
> + return QualType();
> } else if (ResType->isRealType()) {
> // OK!
> } else if (ResType->isPointerType()) {
More information about the cfe-commits
mailing list