def err_typecheck_sclass_func : Error<"illegal storage class on function">;
def err_static_block_func : Error<
"function declared in block scope cannot have 'static' storage class">;
-def err_typecheck_address_of : Error<"address of %0 requested">;
+def err_typecheck_address_of : Error<"address of %select{bit-field"
+ "|vector element|property expression|register variable}0 requested">;
def ext_typecheck_addrof_void : Extension<
"ISO C forbids taking the address of an expression of type 'void'">;
def err_unqualified_pointer_member_function : Error<
}
}
+/// \brief Diagnose invalid operand for address of operations.
+///
+/// \param Type The type of operand which cannot have its address taken.
+/// 0:bit-field 1:vector element 2:property expression 3:register variable
+static void diagnoseAddressOfInvalidType(Sema &S, SourceLocation Loc,
+ Expr *E, unsigned Type) {
+ S.Diag(Loc, diag::err_typecheck_address_of) << Type << E->getSourceRange();
+}
+
/// CheckAddressOfOperand - The operand of & must be either a function
/// designator or an lvalue designating an object. If it is an lvalue, the
/// object cannot be declared with storage class register or be a bit field.
}
} else if (op->getObjectKind() == OK_BitField) { // C99 6.5.3.2p1
// The operand cannot be a bit-field
- S.Diag(OpLoc, diag::err_typecheck_address_of)
- << "bit-field" << op->getSourceRange();
- return QualType();
+ diagnoseAddressOfInvalidType(S, OpLoc, op, /*bit-field*/ 0);
+ return QualType();
} else if (op->getObjectKind() == OK_VectorComponent) {
// The operand cannot be an element of a vector
- S.Diag(OpLoc, diag::err_typecheck_address_of)
- << "vector element" << op->getSourceRange();
+ diagnoseAddressOfInvalidType(S, OpLoc, op, /*vector element*/ 1);
return QualType();
} else if (op->getObjectKind() == OK_ObjCProperty) {
// cannot take address of a property expression.
- S.Diag(OpLoc, diag::err_typecheck_address_of)
- << "property expression" << op->getSourceRange();
+ diagnoseAddressOfInvalidType(S, OpLoc, op, /*property expression*/ 2);
return QualType();
} else if (dcl) { // C99 6.5.3.2p1
// We have an lvalue with a decl. Make sure the decl is not declared
// variable (c++03 7.1.1P3)
if (vd->getStorageClass() == SC_Register &&
!S.getLangOptions().CPlusPlus) {
- S.Diag(OpLoc, diag::err_typecheck_address_of)
- << "register variable" << op->getSourceRange();
+ diagnoseAddressOfInvalidType(S, OpLoc, op, /*register variable*/ 3);
return QualType();
}
} else if (isa<FunctionTemplateDecl>(dcl)) {