]> granicus.if.org Git - clang/commitdiff
Change dyn_cast for reference types to be more like pointers and not need the canonic...
authorBill Wendling <isanbard@gmail.com>
Tue, 17 Jul 2007 04:16:47 +0000 (04:16 +0000)
committerBill Wendling <isanbard@gmail.com>
Tue, 17 Jul 2007 04:16:47 +0000 (04:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39954 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Type.cpp
Sema/SemaExpr.cpp

index 7b999faa662b7b713f67af81564ed78e9662f1d1..f083a73fdceb9ce382a36e871ae8b8aad54df925 100644 (file)
@@ -73,7 +73,15 @@ const PointerType *Type::isPointerType() const {
 }
 
 bool Type::isReferenceType() const {
-  return isa<ReferenceType>(CanonicalType);
+  // If this is directly a reference type, return it.
+  if (const ReferenceType *RTy = dyn_cast<ReferenceType>(this))
+    return RTy;
+  
+  // If this is a typedef for a reference type, strip the typedef off without
+  // losing all typedef information.
+  if (isa<ReferenceType>(CanonicalType))
+    return cast<ReferenceType>(cast<TypedefType>(this)->LookThroughTypedefs());
+  return 0;
 }
 
 bool Type::isArrayType() const {
index 93a2df90aa5c4cadd06c4643316f298a4e90d96d..952c83fcf138a474541ede39e5a25829f482b680 100644 (file)
@@ -597,8 +597,10 @@ void Sema::DefaultFunctionArrayConversion(Expr *&e) {
   QualType t = e->getType();
   assert(!t.isNull() && "DefaultFunctionArrayConversion - missing type");
 
-  if (const ReferenceType *ref = dyn_cast<ReferenceType>(t.getCanonicalType()))
-    t = promoteExprToType(e, ref->getReferenceeType()); // C++ [expr]
+  if (const ReferenceType *ref = dyn_cast<ReferenceType>(t)) {
+    promoteExprToType(e, ref->getReferenceeType()); // C++ [expr]
+    t = e->getType();
+  }
   if (t->isFunctionType())
     promoteExprToType(e, Context.getPointerType(t));
   else if (const ArrayType *ary = dyn_cast<ArrayType>(t.getCanonicalType()))
@@ -614,8 +616,10 @@ void Sema::UsualUnaryConversions(Expr *&expr) {
   QualType t = expr->getType();
   assert(!t.isNull() && "UsualUnaryConversions - missing type");
   
-  if (const ReferenceType *ref = dyn_cast<ReferenceType>(t.getCanonicalType()))
-    t = promoteExprToType(expr, ref->getReferenceeType()); // C++ [expr]
+  if (const ReferenceType *ref = dyn_cast<ReferenceType>(t)) {
+    promoteExprToType(expr, ref->getReferenceeType()); // C++ [expr]
+    t = expr->getType();
+  }
   if (t->isPromotableIntegerType()) // C99 6.3.1.1p2
     promoteExprToType(expr, Context.IntTy);
   else