[cfe-commits] [patch] Template instantiation and visibility

Rafael EspĂ­ndola rafael.espindola at gmail.com
Sun Apr 22 11:48:13 PDT 2012


Given

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

gcc 4.7 produces a default symbol for the first test and a hidden one
for the second one. 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 lets us get the first testcase
right.
* Goes back to selecting the minimum visibility in cases where we
should look at the template visibility. This lets us get the second
testcase right.

The summary is that this fixes cases where where we were being
unnecessary conservative in producing a default visibility but avoids
breaking chrome's build.

Cheers,
Rafael



More information about the cfe-commits mailing list