aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/Decl.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-10-27 23:26:40 +0000
committerDouglas Gregor <dgregor@apple.com>2009-10-27 23:26:40 +0000
commit7d9c3c92c90ae36d58ec21bc53c4c08e02ac3555 (patch)
tree66200812f0e8c8a2deabc239201de742f8e3e944 /lib/AST/Decl.cpp
parentdb07b3f7cdcb505329c1280d7cf70791739a7cad (diff)
Implement proper linkage for explicit instantiation declarations of
inlined functions. For example, given template<typename T> class string { unsigned Len; public: unsigned size() const { return Len; } }; extern template class string<char>; we now give the instantiation of string<char>::size available_externally linkage (if it is ever instantiated!), as permitted by the C++0x standard. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85340 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r--lib/AST/Decl.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 28d0a8357e..a6996a4bfe 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -643,10 +643,33 @@ unsigned FunctionDecl::getMinRequiredArguments() const {
}
bool FunctionDecl::isInlined() const {
- return isInlineSpecified() || (isa<CXXMethodDecl>(this) && !isOutOfLine());
+ if (isInlineSpecified() || (isa<CXXMethodDecl>(this) && !isOutOfLine()))
+ return true;
+
+ switch (getTemplateSpecializationKind()) {
+ case TSK_Undeclared:
+ case TSK_ExplicitSpecialization:
+ return false;
+
+ case TSK_ImplicitInstantiation:
+ case TSK_ExplicitInstantiationDeclaration:
+ case TSK_ExplicitInstantiationDefinition:
+ // Handle below.
+ break;
+ }
+
+ const FunctionDecl *PatternDecl = getTemplateInstantiationPattern();
+ Stmt *Pattern = 0;
+ if (PatternDecl)
+ Pattern = PatternDecl->getBody(PatternDecl);
+
+ if (Pattern && PatternDecl)
+ return PatternDecl->isInlined();
+
+ return false;
}
-/// \brief For an inline function definition in C, determine whether the
+/// \brief For an inline function definition in C or C++, determine whether the
/// definition will be externally visible.
///
/// Inline function definitions are always available for inlining optimizations.
@@ -666,8 +689,9 @@ bool FunctionDecl::isInlined() const {
bool FunctionDecl::isInlineDefinitionExternallyVisible() const {
assert(isThisDeclarationADefinition() && "Must have the function definition");
assert(isInlined() && "Function must be inline");
+ ASTContext &Context = getASTContext();
- if (!getASTContext().getLangOptions().C99 || hasAttr<GNUInlineAttr>()) {
+ if (!Context.getLangOptions().C99 || hasAttr<GNUInlineAttr>()) {
// GNU inline semantics. Based on a number of examples, we came up with the
// following heuristic: if the "inline" keyword is present on a
// declaration of the function but "extern" is not present on that