]> granicus.if.org Git - clang/commitdiff
GCC supports the complex conjugate operator (an extension) on complex int
authorChris Lattner <sabre@nondot.org>
Fri, 25 Jul 2008 23:52:49 +0000 (23:52 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 25 Jul 2008 23:52:49 +0000 (23:52 +0000)
as well as complex float. rdar://6097730

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54080 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/complex-int.c

index 99c070990b6fad796b4fdbffc4d7e516f83093b3..25a86fabdb7905c7aecdb04a09bfba310cc15882 100644 (file)
@@ -2261,16 +2261,14 @@ Action::ExprResult Sema::ActOnUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
   case UnaryOperator::Not: // bitwise complement
     UsualUnaryConversions(Input);
     resultType = Input->getType();
-    // C99 6.5.3.3p1. We allow complex as a GCC extension.
-    if (!resultType->isIntegerType()) {
-      if (resultType->isComplexType())
-        // C99 does not support '~' for complex conjugation.
-        Diag(OpLoc, diag::ext_integer_complement_complex,
-                    resultType.getAsString());
-      else
-        return Diag(OpLoc, diag::err_typecheck_unary_expr,
-                    resultType.getAsString());
-    }
+    // C99 6.5.3.3p1. We allow complex int and float as a GCC extension.
+    if (resultType->isComplexType() || resultType->isComplexIntegerType())
+      // C99 does not support '~' for complex conjugation.
+      Diag(OpLoc, diag::ext_integer_complement_complex,
+           resultType.getAsString(), Input->getSourceRange());
+    else if (!resultType->isIntegerType())
+      return Diag(OpLoc, diag::err_typecheck_unary_expr,
+                  resultType.getAsString(), Input->getSourceRange());
     break;
   case UnaryOperator::LNot: // logical negation
     // Unlike +/-/~, integer promotions aren't done here (C99 6.5.3.3p5).
index d7244d113bbf545de02dcd3cde9be8f6e92516ea..1e58b5320cb98c5956cf1e70669ab50f16e93ca0 100644 (file)
@@ -41,3 +41,12 @@ TestPairs(5); TestPairs(6);
 TestPairs(7); TestPairs(8);
 }
 
+// rdar://6097730
+void test3(_Complex int *x) {
+  *x = ~*x;
+}              
+
+void test4(_Complex float *x) {
+  *x = ~*x;
+}              
+