[cfe-commits] r90835 - in /cfe/trunk: lib/AST/DeclBase.cpp lib/Sema/SemaDecl.cpp test/CodeGenCXX/function-template-explicit-specialization.cpp
Eli Friedman
eli.friedman at gmail.com
Mon Dec 7 21:40:04 PST 2009
Author: efriedma
Date: Mon Dec 7 23:40:03 2009
New Revision: 90835
URL: http://llvm.org/viewvc/llvm-project?rev=90835&view=rev
Log:
Fix for PR5710: make sure to put function template specializations into the
DeclContext, so they don't completely disappear from the AST.
I don't particularly like this fix, but I don't see any obviously better way
to deal with it, and I think it's pretty clearly an improvement; comments
welcome.
Added:
cfe/trunk/test/CodeGenCXX/function-template-explicit-specialization.cpp
Modified:
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=90835&r1=90834&r2=90835&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Mon Dec 7 23:40:03 2009
@@ -741,6 +741,9 @@
// from being visible?
if (isa<ClassTemplateSpecializationDecl>(D))
return;
+ if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
+ if (FD->isFunctionTemplateSpecialization())
+ return;
DeclContext *PrimaryContext = getPrimaryContext();
if (PrimaryContext != this) {
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=90835&r1=90834&r2=90835&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Dec 7 23:40:03 2009
@@ -379,7 +379,9 @@
// scope.
if ((isa<FunctionTemplateDecl>(D) &&
cast<FunctionTemplateDecl>(D)->getTemplatedDecl()->isOutOfLine()) ||
- (isa<FunctionDecl>(D) && cast<FunctionDecl>(D)->isOutOfLine()) ||
+ (isa<FunctionDecl>(D) &&
+ (cast<FunctionDecl>(D)->isFunctionTemplateSpecialization() ||
+ cast<FunctionDecl>(D)->isOutOfLine())) ||
(isa<VarDecl>(D) && cast<VarDecl>(D)->isOutOfLine()))
return;
@@ -2023,9 +2025,7 @@
// If this has an identifier and is not an invalid redeclaration or
// function template specialization, add it to the scope stack.
- if (Name && !(Redeclaration && New->isInvalidDecl()) &&
- !(isa<FunctionDecl>(New) &&
- cast<FunctionDecl>(New)->isFunctionTemplateSpecialization()))
+ if (Name && !(Redeclaration && New->isInvalidDecl()))
PushOnScopeChains(New, S);
return DeclPtrTy::make(New);
Added: cfe/trunk/test/CodeGenCXX/function-template-explicit-specialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/function-template-explicit-specialization.cpp?rev=90835&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/function-template-explicit-specialization.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/function-template-explicit-specialization.cpp Mon Dec 7 23:40:03 2009
@@ -0,0 +1,13 @@
+// RUN: clang-cc -emit-llvm %s -o - | FileCheck %s
+
+template<typename T> void a(T);
+template<> void a(int) {}
+
+// CHECK: define void @_Z1aIiEvT_
+
+namespace X {
+template<typename T> void b(T);
+template<> void b(int) {}
+}
+
+// CHECK: define void @_ZN1X1bIiEEvT_
More information about the cfe-commits
mailing list