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();
}
"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,