[PATCH] D13419: Fix several problems at the intersection of template instantiations and visibility
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 28 15:26:05 PDT 2016
rsmith added a comment.
Please factor out the fix for `getTemplateInstantiationPattern` and commit it separately. https://reviews.llvm.org/D25942 has a testcase for that portion of this change.
================
Comment at: lib/AST/Decl.cpp:1057-1058
+ RD->getTemplateInstantiationPattern();
+ if (!InstantiatedFrom)
+ InstantiatedFrom = RD->getInstantiatedFromMemberClass();
if (InstantiatedFrom)
----------------
This doesn't seem to match GCC; GCC seems to do this for all kinds of member specialization, not just for member class specialization:
```
template<typename T> struct A {
template<typename U> struct __attribute__((visibility("hidden"))) B;
};
template<> template<typename U> struct A<int>::B { virtual void f() {} };
void g() { A<int>::B<int>().f(); }
```
Here, A<int>::B<int> gets hidden visibility, even though it was instantiated from the member template specialization `A<int>::B` which had no visibility attribute.
I don't know what the underlying logic is here -- does GCC look at the visibility on the enclosing class when computing visibility for a member class? -- but I don't think this one special case covers it.
================
Comment at: lib/AST/Decl.cpp:1096-1097
+ FunctionDecl *InstantiatedFrom = fn->getTemplateInstantiationPattern();
+ if (!InstantiatedFrom)
+ InstantiatedFrom = fn->getInstantiatedFromMemberFunction();
----------------
Likewise.
================
Comment at: lib/AST/DeclCXX.cpp:1349-1354
+ while (!CTD->isMemberSpecialization()) {
+ auto *NewCTD = CTD->getInstantiatedFromMemberTemplate();
+ if (!NewCTD)
break;
CTD = NewCTD;
}
----------------
The same bug exists in `VarDecl::getTemplateInstantiationPattern`; can you fix it there too?
Repository:
rL LLVM
https://reviews.llvm.org/D13419
More information about the cfe-commits
mailing list