[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-commits
Subject:    [cfe-commits] r102777 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp
From:       Douglas Gregor <dgregor () apple ! com>
Date:       2010-04-30 21:46:38
Message-ID: 20100430214638.CFCDC312800A () llvm ! org
[Download RAW message or body]

Author: dgregor
Date: Fri Apr 30 16:46:38 2010
New Revision: 102777

URL: http://llvm.org/viewvc/llvm-project?rev=102777&view=rev
Log:
After substituting a template argument for a non-type template
parameter with pointer-to-member type, we may have to perform a
qualification conversion, since the pointee type of the parameter
might be more qualified than the pointee type of the argument we form
from the declaration. Fixes PR6986.

Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/SemaTemplate/instantiate-non-type-template-parameter.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=102777&r1=102776&r2=102777&view=diff
 ==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Apr 30 16:46:38 2010
@@ -3061,9 +3061,21 @@
         return ExprError();
       
       RefExpr = CreateBuiltinUnaryOp(Loc, UnaryOperator::AddrOf, move(RefExpr));
+      
+      // We might need to perform a trailing qualification conversion, since
+      // the element type on the parameter could be more qualified than the
+      // element type in the expression we constructed.
+      if (IsQualificationConversion(((Expr*) RefExpr.get())->getType(),
+                                    ParamType.getUnqualifiedType())) {
+        Expr *RefE = RefExpr.takeAs<Expr>();
+        ImpCastExprToType(RefE, ParamType.getUnqualifiedType(),
+                          CastExpr::CK_NoOp);
+        RefExpr = Owned(RefE);
+      }
+      
       assert(!RefExpr.isInvalid() &&
              Context.hasSameType(((Expr*) RefExpr.get())->getType(),
-                                 ParamType));
+                                 ParamType.getUnqualifiedType()));
       return move(RefExpr);
     }
   }

Modified: cfe/trunk/test/SemaTemplate/instantiate-non-type-template-parameter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-non-type-template-parameter.cpp?rev=102777&r1=102776&r2=102777&view=diff
 ==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-non-type-template-parameter.cpp \
                (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-non-type-template-parameter.cpp Fri Apr \
30 16:46:38 2010 @@ -9,6 +9,28 @@
   }
 };
 
-int main(int argc, char *argv[]) {
+void test_stringswitch(int argc, char *argv[]) {
   (void)StringSwitch<int>();
 }
+
+namespace PR6986 {
+  template<class Class,typename Type,Type Class::*> 
+  struct non_const_member_base
+  {
+  };
+
+  template<class Class,typename Type,Type Class::*PtrToMember> 
+  struct member: non_const_member_base<Class,Type,PtrToMember>
+  {
+  };
+
+  struct test_class
+  {
+    int int_member;
+  };
+  typedef member< test_class,const int,&test_class::int_member > ckey_m;
+  void test()
+  {
+    ckey_m m;
+  }
+}


_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic