[PATCH] D13330: Implement __attribute__((unique_instantiation))
Keno Fischer via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 7 16:41:39 PST 2015
loladiro added inline comments.
================
Comment at: lib/AST/ASTContext.cpp:8257-8266
@@ -8256,1 +8256,12 @@
+bool ASTContext::containedInUniqueInstantiation(const Decl *D) {
+ const RecordDecl *RD;
+ while ((RD = dyn_cast<RecordDecl>(D->getDeclContext()))) {
+ auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD);
+ if (CTSD && CTSD->hasAttr<UniqueInstantiationAttr>())
+ return true;
+ D = RD;
+ }
+ return false;
+}
+
----------------
majnemer wrote:
> Function templates can contain class templates which contain functions. I think this code will return false if the outermost function template is the only one annotated with UniqueInstantiationAttr.
So you're concerned about this case:
```
template < typename T > auto foo( T x ) {
class inner {
T y;
public:
virtual ~inner() {}
inner(T y) : y(y) {}
T getY() { return y; }
};
return inner{x}.getY();
}
extern template __attribute__((unique_instantiation)) auto foo<int>(int);
template __attribute__((unique_instantiation)) auto foo<int>(int);
```
Right now the inner class's vtable and method is linkonce_odr. If you think it should be strong I'll look into it.
http://reviews.llvm.org/D13330
More information about the cfe-commits
mailing list