// Other C++ expressions
def err_need_header_before_typeid : Error<
"you need to include <typeinfo> before using the 'typeid' operator">;
+def err_incomplete_typeid : Error<"'typeid' of incomplete type %0">;
def err_static_illegal_in_new : Error<
"the 'static' modifier for the array size is not legal in new expressions">;
def err_array_new_needs_size : Error<
// that is the operand of typeid are always ignored.
// FIXME: Preserve type source info.
// FIXME: Preserve the type before we stripped the cv-qualifiers?
- TyOrExpr =GetTypeFromParser(TyOrExpr).getUnqualifiedType().getAsOpaquePtr();
+ QualType T = GetTypeFromParser(TyOrExpr);
+ if (T.isNull())
+ return ExprError();
+
+ // C++ [expr.typeid]p4:
+ // If the type of the type-id is a class type or a reference to a class
+ // type, the class shall be completely-defined.
+ QualType CheckT = T;
+ if (const ReferenceType *RefType = CheckT->getAs<ReferenceType>())
+ CheckT = RefType->getPointeeType();
+
+ if (CheckT->getAs<RecordType>() &&
+ RequireCompleteType(OpLoc, CheckT, diag::err_incomplete_typeid))
+ return ExprError();
+
+ TyOrExpr = T.getUnqualifiedType().getAsOpaquePtr();
}
IdentifierInfo *TypeInfoII = &PP.getIdentifierTable().get("type_info");
// C++ [expr.typeid]p3:
// [...] If the type of the expression is a class type, the class
// shall be completely-defined.
- // FIXME: implement this!
+ if (RequireCompleteType(OpLoc, T, diag::err_incomplete_typeid))
+ return ExprError();
}
}
{
(void)typeid(int);
}
+
+struct X; // expected-note 3{{forward declaration}}
+
+void g1(X &x) {
+ (void)typeid(X); // expected-error{{'typeid' of incomplete type 'struct X'}}
+ (void)typeid(X&); // expected-error{{'typeid' of incomplete type 'struct X'}}
+ (void)typeid(x); // expected-error{{'typeid' of incomplete type 'struct X'}}
+}
}
};
-struct Incomplete; // expected-note{{forward}}
+struct Incomplete; // expected-note 2{{forward}}
template struct Throw1<int>;
template struct Throw1<int*>;
// typeid expressions
// ---------------------------------------------------------------------
-// FIXME: This should really include <typeinfo>, but we don't have that yet.
namespace std {
class type_info;
}
if (ptr)
return typeid(ptr);
else
- return typeid(T);
+ return typeid(T); // expected-error{{'typeid' of incomplete type 'struct Incomplete'}}
}
};
};
template struct TypeId0<int>;
-template struct TypeId0<Incomplete>;
+template struct TypeId0<Incomplete>; // expected-note{{instantiation of member function}}
template struct TypeId0<Abstract>;
// ---------------------------------------------------------------------