[cfe-commits] [patch] Template instantiation and visibility (take 2)

Rafael EspĂ­ndola rafael.espindola at gmail.com
Mon Apr 23 13:00:00 PDT 2012


In the testcases

namespace t1 {
 struct HIDDEN foo {};
 template<class T>
 DEFAULT void bar() {}
 template DEFAULT void bar<foo>();
}
namespace t2 {
 struct HIDDEN foo {};
 template<class T>
 DEFAULT void bar() {}
 template void bar<foo>();
}
namespace t3 {
 template<typename T>
 class DEFAULT foo {
   void bar() {}
 };
 struct HIDDEN zed {};
 template class DEFAULT foo<zed>;
}
namespace t4 {
 template<typename T>
 class DEFAULT foo {
   void bar() {}
 };
 struct HIDDEN zed {};
 template class foo<zed>;
}

gcc 4.7 produces symbols with default visibility in t1 and t3, and
hidden visibility in t2 and t4.

This requires differentiating attributes in a template and attributes
in an instantiation. Clang currently doesn't do that for any attributes,
but Jeff tells me that "C++11 just says that attributes appertain to
particular things, not how they propagate from templates to
instantiations" so this looks like a valid c++ extension by gcc.

The attached patch:

* Avoids cloning the visibility attribute during instantiations.

* Avoids considering visibility info in a template when the
instantiation has an attribute. This handles t1 and t3.

* Goes back to selecting the minimum visibility in cases where we
should look at the template visibility. This handles t2 and t4.

The difference from the previous patch is that this one doesn't
change our merging of implicit visibility. I will try to do that in a
separate patch.

Cheers,
Rafael



More information about the cfe-commits mailing list