[cfe-commits] r105314 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/CodeGenCXX/rtti-linkage.cpp

Douglas Gregor dgregor at apple.com
Tue Jun 1 23:16:02 PDT 2010


Author: dgregor
Date: Wed Jun  2 01:16:02 2010
New Revision: 105314

URL: http://llvm.org/viewvc/llvm-project?rev=105314&view=rev
Log:
typeid() produces type information for the cv-unqualified version of
the type. Thanks to Anders for the bug report!

Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/CodeGenCXX/rtti-linkage.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=105314&r1=105313&r2=105314&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Jun  2 01:16:02 2010
@@ -284,7 +284,10 @@
   //   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 @@
     //   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);
     }

Modified: cfe/trunk/test/CodeGenCXX/rtti-linkage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/rtti-linkage.cpp?rev=105314&r1=105313&r2=105314&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/rtti-linkage.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/rtti-linkage.cpp Wed Jun  2 01:16:02 2010
@@ -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 @@
   
   return typeid(getD());  
 }
+
+namespace Arrays {
+  struct A {
+    static const int a[10];
+  };
+  const std::type_info &f() {
+    return typeid(A::a);
+  }
+}





More information about the cfe-commits mailing list