]> granicus.if.org Git - clang/commitdiff
When a template-id expression refers to a member function template, turn it into...
authorDouglas Gregor <dgregor@apple.com>
Thu, 22 Oct 2009 07:19:14 +0000 (07:19 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 22 Oct 2009 07:19:14 +0000 (07:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84848 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplate.cpp
test/SemaTemplate/member-access-expr.cpp

index d9c53ebec63d53d864850244dc39940dfb1fa0dc..c691cd93a0bd640c2deab86e907b61969b55d32e 100644 (file)
@@ -1261,6 +1261,24 @@ Sema::OwningExprResult Sema::BuildTemplateIdExpr(TemplateName Template,
   // template arguments that we have against the template name, if the template
   // name refers to a single template. That's not a terribly common case,
   // though.
+  
+  // Cope with an implicit member access in a C++ non-static member function.
+  NamedDecl *D = Template.getAsTemplateDecl();
+  if (!D)
+    D = Template.getAsOverloadedFunctionDecl();
+  
+  QualType ThisType, MemberType;
+  if (D && isImplicitMemberReference(/*FIXME:??*/0, D, TemplateNameLoc, 
+                                     ThisType, MemberType)) {
+    Expr *This = new (Context) CXXThisExpr(SourceLocation(), ThisType);
+    return Owned(MemberExpr::Create(Context, This, true,
+                                    /*FIXME:*/0, /*FIXME:*/SourceRange(),
+                                    D, TemplateNameLoc, true,
+                                    LAngleLoc, TemplateArgs,
+                                    NumTemplateArgs, RAngleLoc,
+                                    Context.OverloadTy));
+  }
+  
   return Owned(TemplateIdRefExpr::Create(Context,
                                          /*FIXME: New type?*/Context.OverloadTy,
                                          /*FIXME: Necessary?*/0,
index f4922e8ff5208e5bdbd84b461ba74b949299537e..0a6a6bc0990e5f9233b860b2777b393542b6792f 100644 (file)
@@ -74,4 +74,17 @@ void test_destruct(X2 *x2p, int *ip) {
   destruct(x2p);
   destruct(ip);
   destruct_intptr<int>(ip);
-}
\ No newline at end of file
+}
+
+// PR5220
+class X3 {
+protected:
+  template <int> float* &f0();
+  template <int> const float* &f0() const;
+  void f1() {
+    (void)static_cast<float*>(f0<0>());
+  }
+  void f1() const{
+    (void)f0<0>();
+  }
+};