[cfe-commits] r84848 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp test/SemaTemplate/member-access-expr.cpp
Douglas Gregor
dgregor at apple.com
Thu Oct 22 00:19:15 PDT 2009
Author: dgregor
Date: Thu Oct 22 02:19:14 2009
New Revision: 84848
URL: http://llvm.org/viewvc/llvm-project?rev=84848&view=rev
Log:
When a template-id expression refers to a member function template, turn it into an (implicit) member access expression. Fixes PR5220
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaTemplate/member-access-expr.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=84848&r1=84847&r2=84848&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Oct 22 02:19:14 2009
@@ -1261,6 +1261,24 @@
// 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,
Modified: cfe/trunk/test/SemaTemplate/member-access-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/member-access-expr.cpp?rev=84848&r1=84847&r2=84848&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/member-access-expr.cpp (original)
+++ cfe/trunk/test/SemaTemplate/member-access-expr.cpp Thu Oct 22 02:19:14 2009
@@ -74,4 +74,17 @@
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>();
+ }
+};
More information about the cfe-commits
mailing list