diff options
author | Rafael Auler <rafaelauler@fb.com> | 2019-01-31 09:38:31 +0000 |
---|---|---|
committer | Rafael Auler <rafaelauler@fb.com> | 2019-01-31 09:38:31 +0000 |
commit | 4b702045888898367bb630b8f767e21e68d3445b (patch) | |
tree | 208006b3de300992e70569cff6a41782b82d1179 /clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | |
parent | f392bc846faf9b77edc3ee98902811e3c23ad524 (diff) | |
download | bcm5719-llvm-4b702045888898367bb630b8f767e21e68d3445b.tar.gz bcm5719-llvm-4b702045888898367bb630b8f767e21e68d3445b.zip |
Support attribute used in member funcs of class templates
Summary:
As PR17480 describes, clang does not support the used attribute
for member functions of class templates. This means that if the member
function is not used, its definition is never instantiated. This patch
changes clang to emit the definition if it has the used attribute.
Test Plan: Added a testcase
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D56928
llvm-svn: 352740
Diffstat (limited to 'clang/lib/Sema/SemaTemplateInstantiateDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 883a73f2266..07533828dfd 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2175,6 +2175,20 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, Owner->addDecl(Method); } + // PR17480: Honor the used attribute to instantiate member function + // definitions + if (Method->hasAttr<UsedAttr>()) { + if (const auto *A = dyn_cast<CXXRecordDecl>(Owner)) { + SourceLocation Loc; + if (const MemberSpecializationInfo *MSInfo = + A->getMemberSpecializationInfo()) + Loc = MSInfo->getPointOfInstantiation(); + else if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(A)) + Loc = Spec->getPointOfInstantiation(); + SemaRef.MarkFunctionReferenced(Loc, Method); + } + } + return Method; } |