From: Chris Lattner Date: Sun, 26 Aug 2007 05:39:26 +0000 (+0000) Subject: require that operands to __real/__imag are complex or arithmetic. This X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cc26ed7dfc54b39f4b7ad1778c3fff93fc63c0d0;p=clang require that operands to __real/__imag are complex or arithmetic. This fixes GCC PR33193 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41428 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index e4dd9bb490..a859fe8ab2 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -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(); } diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index e9756fdd55..721a6a5781 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -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,