From e3041be307d4c133605544a74f40c42c7531b5bb Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Mon, 19 Jul 2010 10:14:41 +0000 Subject: [PATCH] Fix http://llvm.org/PR7660 A ParmVarDecl instantiated from a FunctionProtoType may have Record as DeclContext, in which case isStaticDataMember() will erroneously return true. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108692 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 2 +- lib/Sema/SemaTemplateInstantiate.cpp | 3 ++- test/PCH/cxx-templates.h | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 7fbf874e8e..737eeff2a1 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -696,7 +696,7 @@ public: /// \endcode bool isStaticDataMember() const { // If it wasn't static, it would be a FieldDecl. - return getDeclContext()->isRecord(); + return getKind() != Decl::ParmVar && getDeclContext()->isRecord(); } virtual VarDecl *getCanonicalDecl(); diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 0cdc8a12ab..da99c7e8c2 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -1067,7 +1067,8 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm, NewParm->setHasInheritedDefaultArg(OldParm->hasInheritedDefaultArg()); CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm); - // Set DeclContext if inside a Block. + // FIXME: OldParm may come from a FunctionProtoType, in which case CurContext + // can be anything, is this right ? NewParm->setDeclContext(CurContext); return NewParm; diff --git a/test/PCH/cxx-templates.h b/test/PCH/cxx-templates.h index 396853686f..8cffa3f10d 100644 --- a/test/PCH/cxx-templates.h +++ b/test/PCH/cxx-templates.h @@ -100,3 +100,6 @@ class basic_streambuf friend int __copy_streambufs_eof<>(int); }; +// PR 7660 +template struct S_PR7660 { void g(void (*)(T)); }; + template<> void S_PR7660::g(void(*)(int)) {} -- 2.40.0