typeid() produces type information for the cv-unqualified version of

the type. Thanks to Anders for the bug report!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105314 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Douglas Gregor 2010-06-02 06:16:02 +00:00
Родитель c044193732
Коммит d1c1d7bd14
2 изменённых файлов: 20 добавлений и 4 удалений

Просмотреть файл

@ -284,7 +284,10 @@ Sema::OwningExprResult Sema::BuildCXXTypeId(QualType TypeInfoType,
// that is the operand of typeid are always ignored.
// 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 T = Operand->getType().getNonReferenceType();
Qualifiers Quals;
QualType T
= Context.getUnqualifiedArrayType(Operand->getType().getNonReferenceType(),
Quals);
if (T->getAs<RecordType>() &&
RequireCompleteType(TypeidLoc, T, diag::err_incomplete_typeid))
return ExprError();
@ -328,9 +331,11 @@ Sema::OwningExprResult Sema::BuildCXXTypeId(QualType TypeInfoType,
// cv-qualified type, the result of the typeid expression refers to a
// std::type_info object representing the cv-unqualified referenced
// type.
if (T.hasQualifiers()) {
ImpCastExprToType(E, T.getUnqualifiedType(), CastExpr::CK_NoOp,
E->isLvalue(Context));
Qualifiers Quals;
QualType UnqualT = Context.getUnqualifiedArrayType(T, Quals);
if (!Context.hasSameType(T, UnqualT)) {
T = UnqualT;
ImpCastExprToType(E, UnqualT, CastExpr::CK_NoOp, E->isLvalue(Context));
Operand.release();
Operand = Owned(E);
}

Просмотреть файл

@ -14,6 +14,7 @@
// CHECK: _ZTI1A = weak_odr constant
// CHECK: _ZTI1B = constant
// CHECK: _ZTI1C = internal constant
// CHECK: _ZTIA10_i = weak_odr constant
// CHECK: _ZTIFN12_GLOBAL__N_11DEvE = internal constant
// CHECK: _ZTIFvN12_GLOBAL__N_11DEE = internal constant
// CHECK: _ZTIFvvE = weak_odr
@ -33,6 +34,7 @@
// CHECK: _ZTS1B = constant
// CHECK: _ZTS1C = internal constant
// CHECK: _ZTS1F = weak_odr constant
// CHECK: _ZTSA10_i = weak_odr constant
// CHECK: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
// CHECK: _ZTSFvN12_GLOBAL__N_11DEE = internal constant
// CHECK: _ZTSFvvE = weak_odr constant
@ -107,3 +109,12 @@ const std::type_info &t2() {
return typeid(getD());
}
namespace Arrays {
struct A {
static const int a[10];
};
const std::type_info &f() {
return typeid(A::a);
}
}