diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 180e913155d67..774d2b53a3825 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -7588,8 +7588,8 @@ def ext_gnu_ptr_func_arith : Extension< InGroup; def err_readonly_message_assignment : Error< "assigning to 'readonly' return result of an Objective-C message not allowed">; -def ext_integer_increment_complex : Extension< - "ISO C does not support '++'/'--' on complex integer type %0">; +def ext_increment_complex : Extension< + "'%select{--|++}0' on an object of complex type is a Clang extension">; def ext_integer_complement_complex : Extension< "ISO C does not support '~' for complex conjugation of %0">; def err_nosetter_property_assignment : Error< diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 18284e0c3e987..b294d2bd9f53f 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -14859,8 +14859,8 @@ static QualType CheckIncrementDecrementOperand(Sema &S, Expr *Op, return QualType(); } else if (ResType->isAnyComplexType()) { // C99 does not support ++/-- on complex types, we allow as an extension. - S.Diag(OpLoc, diag::ext_integer_increment_complex) - << ResType << Op->getSourceRange(); + S.Diag(OpLoc, diag::ext_increment_complex) + << IsInc << Op->getSourceRange(); } else if (ResType->isPlaceholderType()) { ExprResult PR = S.CheckPlaceholderExpr(Op); if (PR.isInvalid()) return QualType(); diff --git a/clang/test/Sema/complex-inc-dec.c b/clang/test/Sema/complex-inc-dec.c new file mode 100644 index 0000000000000..ebc23c36f40c8 --- /dev/null +++ b/clang/test/Sema/complex-inc-dec.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -verify -pedantic -std=c99 %s + +void func(void) { + _Complex float cf; + _Complex double cd; + _Complex long double cld; + + ++cf; // expected-warning {{'++' on an object of complex type is a Clang extension}} + ++cd; // expected-warning {{'++' on an object of complex type is a Clang extension}} + ++cld; // expected-warning {{'++' on an object of complex type is a Clang extension}} + + --cf; // expected-warning {{'--' on an object of complex type is a Clang extension}} + --cd; // expected-warning {{'--' on an object of complex type is a Clang extension}} + --cld; // expected-warning {{'--' on an object of complex type is a Clang extension}} + + cf++; // expected-warning {{'++' on an object of complex type is a Clang extension}} + cd++; // expected-warning {{'++' on an object of complex type is a Clang extension}} + cld++; // expected-warning {{'++' on an object of complex type is a Clang extension}} + + cf--; // expected-warning {{'--' on an object of complex type is a Clang extension}} + cd--; // expected-warning {{'--' on an object of complex type is a Clang extension}} + cld--; // expected-warning {{'--' on an object of complex type is a Clang extension}} +} +