aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-08-26 05:39:26 +0000
committerChris Lattner <sabre@nondot.org>2007-08-26 05:39:26 +0000
commitcc26ed7dfc54b39f4b7ad1778c3fff93fc63c0d0 (patch)
treedfc7470150d04ec7fcabb2e88dd0630710649978
parent36f8406db837957b24b926fd657af909e1b12665 (diff)
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
-rw-r--r--Sema/SemaExpr.cpp10
-rw-r--r--include/clang/Basic/DiagnosticKinds.def2
2 files changed, 11 insertions, 1 deletions
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,