]> granicus.if.org Git - clang/commitdiff
require that operands to __real/__imag are complex or arithmetic. This
authorChris Lattner <sabre@nondot.org>
Sun, 26 Aug 2007 05:39:26 +0000 (05:39 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 26 Aug 2007 05:39:26 +0000 (05:39 +0000)
fixes GCC PR33193

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

Sema/SemaExpr.cpp
include/clang/Basic/DiagnosticKinds.def

index e4dd9bb490f2e9f7d66abc92c3358fd343477dbe..a859fe8ab2a324ecf5c2cd2dfc60436d025cc5b8 100644 (file)
@@ -283,9 +283,17 @@ ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
 QualType Sema::CheckRealImagOperand(Expr *&V, SourceLocation Loc) {
   DefaultFunctionArrayConversion(V);
   
+  // These operators return the element type of a complex type.
   if (const ComplexType *CT = V->getType()->getAsComplexType())
     return CT->getElementType();
-  return V->getType();
+  
+  // Otherwise they pass through real integer and floating point types here.
+  if (V->getType()->isArithmeticType())
+    return V->getType();
+  
+  // Reject anything else.
+  Diag(Loc, diag::err_realimag_invalid_type, V->getType().getAsString());
+  return QualType();
 }
 
 
index e9756fdd5531a5be54932c723e9cf8f0888f89ea..721a6a5781f2964c36475224d1a415d50d777f64 100644 (file)
@@ -610,6 +610,8 @@ DIAG(err_typecheck_arithmetic_incomplete_type, ERROR,
      "arithmetic on pointer to incomplete type '%0'")
 DIAG(err_typecheck_decl_incomplete_type, ERROR,
      "variable has incomplete type '%0'")
+DIAG(err_realimag_invalid_type, ERROR,
+     "invalid type '%0' to __real or __imag operator")
 DIAG(err_typecheck_sclass_fscope, ERROR,
      "illegal storage class on file-scoped variable")
 DIAG(err_typecheck_sclass_func, ERROR,