Propagation rules (C++ only) (IBM extension)

Visibility attributes can be propagated from one entity to other entities. The following table lists all the cases for visibility propagation.
Table 1. Propagation of visibility attributes
Original entity Destination entities Example
namespace named namespaces that are defined in the original namespace
namespace A __attribute__((visibility("hidden"))){
   // Namespace B has the hidden visibility attribute,
   // which is propagated from namespace A.
   namespace B{}
   // The unnamed namespace does not have a visibility 
   // attribute.
   namespace{}
}
namespace classes that are defined in the original namespace
namespace A __attribute__((visibility("hidden"))){
   // Class B has the hidden visibility attribute,
   // which is propagated from namespace A.
   class B;
   // Object x has the hidden visibility attribute,
   // which is propagated from namespace A.
   class{} x;
} 
namespace functions that are defined in the original namespace
namespace A __attribute__((visibility("hidden"))){
   // Function fun() has the hidden visibility
   // attribute, which is propagated from namespace A.
   void fun(){};
} 
namespace objects that are defined in the original namespace
namespace A __attribute__((visibility("hidden"))){
   // Variable m has the hidden visibility attribute,
   // which is propagated from namespace A.
   int m;
} 
class member classes
class __attribute__((visibility("hidden"))) A{
   // Class B has the hidden visibility attribute,
   // which is propagated from class A.
   class B{};
} 
class member functions or static member variables
class __attribute__((visibility("hidden"))) A{
    // Function fun() has the hidden visibility
    // attribute, which is propagated from class A.
    void fun(){};
    // Static variable m has the hidden visibility
    // attribute, which is propagated from class A.
    static int m;
} 
template template instantiations/template specifications/template partial specializations
template<typename T, typename U>
class  __attribute__((visibility("hidden"))) A{
   public:
   void fun(){};
};

// Template instantiation class A<int, char> has the
// hidden visibility attribute, which is propagated 
// from template class A(T,U).
class A<int, char>{
   public:
   void fun(){};
};

// Template specification 
// template<> class A<double, double> has the hidden
// visibility attribute, which is propagated
// from template class A(T,U).
template<> class A<double, double>{
   public:
   void fun(){};
};

// Template partial specification 
// template<typename T> class A<T, char> has the
// hidden visibility attribute, which is propagated
// from template class A(T,U).
template<typename T> class A<T, char>{
   public:
   void fun(){};
};
template argument/parameter template instantiations/template specifications/template partial specializations
template<typename T> void fun1(){}
template<typename T> void fun2(T){}

class M __attribute__((visibility("hidden"))){} m;

// Template instantiation fun1<M>() has the hidden 
// visibility attribute, which is propagated from
// template argument M.
fun1<M>();

// Template instantiation fun2<M>(M) has the hidden 
// visibility attribute, which is propagated from
// template parameter m.
fun2(m);

// Template specification fun1<M>() has the hidden 
// visibility attribute, which is propagated from
// template argument M.
template<> void fun1<M>();
inline function static local variables
inline void __attribute__((visibility("hidden"))) 
   fun(){
   // Variable m has the hidden visibility attribute,
   // which is propagated from inline function fun().
   static int m = 4;
}
type entities of the original type
class __attribute__((visibility("hidden"))) A {};

// Object x has the hidden visibility attribute,
// which is propagated from class A.
class A x;
function return type function
class __attribute__((visibility("hidden"))) A{};
// Function fun() has the hidden visibility attribute,
// which is propagated from function return type A.
A fun();
function parameter type function
class __attribute__((visibility("hidden"))) A{};
// Function fun(class A) has the hidden visibility
// attribute, which is propagated from function 
// parameter type A.
void fun(class A);