Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 146817 | Differences between
and this patch

Collapse All | Expand All

(-)gcc/doc/extend.texi (+10 lines)
Lines 2346-2351 Link Here
2346
Otherwise, template instantiations and specializations default to the
2346
Otherwise, template instantiations and specializations default to the
2347
visibility of their template.
2347
visibility of their template.
2348
2348
2349
If both the template and enclosing class have explicit visibility, the
2350
visibility from the template is used.
2351
2349
@item warn_unused_result
2352
@item warn_unused_result
2350
@cindex @code{warn_unused_result} attribute
2353
@cindex @code{warn_unused_result} attribute
2351
The @code{warn_unused_result} attribute causes a warning to be emitted
2354
The @code{warn_unused_result} attribute causes a warning to be emitted
Lines 3465-3470 Link Here
3465
attributes, the attribute must appear between the initial keyword and
3468
attributes, the attribute must appear between the initial keyword and
3466
the name of the type; it cannot appear after the body of the type.
3469
the name of the type; it cannot appear after the body of the type.
3467
3470
3471
Note that the type visibility is applied to vague linkage entities
3472
associated with the class (vtable, typeinfo node, etc.).  In
3473
particular, if a class is thrown as an exception in one shared object
3474
and caught in another, the class must have default visibility.
3475
Otherwise the two shared objects will be unable to use the same
3476
typeinfo node and exception handling will break.
3477
3468
@subsection ARM Type Attributes
3478
@subsection ARM Type Attributes
3469
3479
3470
On those ARM targets that support @code{dllimport} (such as Symbian
3480
On those ARM targets that support @code{dllimport} (such as Symbian
(-)gcc/tree.c (+22 lines)
Lines 3461-3466 Link Here
3461
  return NULL_TREE;
3461
  return NULL_TREE;
3462
}
3462
}
3463
3463
3464
/* Remove any instances of attribute ATTR_NAME in LIST and return the
3465
   modified list.  */
3466
3467
tree
3468
remove_attribute (const char *attr_name, tree list)
3469
{
3470
  tree *p;
3471
  size_t attr_len = strlen (attr_name);
3472
3473
  for (p = &list; *p; )
3474
    {
3475
      tree l = *p;
3476
      gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE);
3477
      if (is_attribute_with_length_p (attr_name, attr_len, TREE_PURPOSE (l)))
3478
	*p = TREE_CHAIN (l);
3479
      else
3480
	p = &TREE_CHAIN (l);
3481
    }
3482
3483
  return list;
3484
}
3485
3464
/* Return an attribute list that is the union of a1 and a2.  */
3486
/* Return an attribute list that is the union of a1 and a2.  */
3465
3487
3466
tree
3488
tree
(-)gcc/tree.h (+5 lines)
Lines 3613-3618 Link Here
3613
3613
3614
extern tree lookup_attribute (const char *, tree);
3614
extern tree lookup_attribute (const char *, tree);
3615
3615
3616
/* Remove any instances of attribute ATTR_NAME in LIST and return the
3617
   modified list.  */
3618
3619
extern tree remove_attribute (const char *, tree);
3620
3616
/* Given two attributes lists, return a list of their union.  */
3621
/* Given two attributes lists, return a list of their union.  */
3617
3622
3618
extern tree merge_attributes (tree, tree);
3623
extern tree merge_attributes (tree, tree);
(-)gcc/testsuite/g++.dg/ext/visibility/template6.C (+17 lines)
Line 0 Link Here
1
// Test for explicit visibility taking precedence
2
3
// { dg-require-visibility "" }
4
// { dg-final { scan-not-hidden "_ZN1AIiE1fEv" } }
5
6
template <class T> struct A
7
{
8
  // This attribute takes precedence over...
9
  __attribute ((visibility ("default"))) void f ();
10
};
11
12
template <class T>
13
void A<T>::f ()
14
{ }
15
16
// ...this attribute.
17
template struct __attribute ((visibility ("hidden"))) A<int>;
(-)gcc/testsuite/g++.dg/ext/visibility/warn2.C (-1 / +1 lines)
Lines 14-19 Link Here
14
  N::A a;
14
  N::A a;
15
};
15
};
16
16
17
B f () { }			// { dg-warning "visibility" }
17
N::A f () { }			// { dg-warning "visibility" }
18
18
19
struct C: public N::A { };	// { dg-warning "visibility" }
19
struct C: public N::A { };	// { dg-warning "visibility" }
(-)gcc/testsuite/g++.dg/ext/visibility/warn3.C (-3 / +24 lines)
Lines 1-11 Link Here
1
// Warn when a class member is specified to have greater visibility than
1
// Tests for various visibility mismatch situations.
2
// its class.
3
2
4
// { dg-require-visibility "" }
3
// { dg-require-visibility "" }
5
4
5
// { dg-final { scan-not-hidden "_ZN1A1fEv" } }
6
6
struct __attribute ((visibility ("hidden"))) A
7
struct __attribute ((visibility ("hidden"))) A
7
{
8
{
8
  __attribute ((visibility ("default"))) void f (); // { dg-warning "visibility" }
9
  // This is OK, A::f gets default visibility.
10
  __attribute ((visibility ("default"))) void f ();
9
};
11
};
10
12
11
void A::f() { }
13
void A::f() { }
14
15
// This gets a warning; it should have explicit visibility of some sort.
16
A* afactory1() { return new A; }	// { dg-warning "visibility" }
17
18
// This is OK.
19
__attribute ((visibility ("default"))) A*
20
afactory2 () { return new A; }
21
22
// This gets a warning.
23
struct B
24
{				// { dg-warning "visibility" }
25
  A a;
26
};
27
28
// This one has explicit visibility, so it doesn't get a warning.
29
struct __attribute ((visibility ("default"))) C
30
{
31
  A a;
32
};
(-)gcc/testsuite/g++.dg/lookup/anon5.C (+21 lines)
Line 0 Link Here
1
// PR c++/28409
2
// shouldIbevisible should be emitted because it's an extern "C" decl with
3
// external linkage, even though it's in the anonymous namespace.
4
5
namespace
6
{
7
  extern "C" int shouldIbevisible()
8
  {
9
    return 0;
10
  }
11
}
12
13
namespace t
14
{
15
  extern "C" int shouldIbevisible(void);
16
}
17
18
int main(void)
19
{
20
  return t::shouldIbevisible();
21
}
(-)gcc/testsuite/g++.dg/template/anon3.C (+20 lines)
Line 0 Link Here
1
// PR c++/28370
2
// { dg-do run }
3
4
namespace
5
{
6
  template<typename T> struct A { static int *a; };
7
  template<typename T> int *A<T>::a = 0;
8
}
9
10
int *
11
foo ()
12
{
13
  return A<int>::a;
14
}
15
16
int
17
main ()
18
{
19
  return foo() != 0;
20
}
(-)gcc/testsuite/g++.dg/template/anon4.C (+10 lines)
Line 0 Link Here
1
// PR c++/28407
2
// A declaration in the anonymous namespace still has external linkage.
3
4
template <int *P> class A { };
5
namespace
6
{
7
  int i;
8
}
9
10
A<&i> a;
(-)gcc/cp/decl.c (+8 lines)
Lines 5274-5279 Link Here
5274
  determine_visibility (decl);
5274
  determine_visibility (decl);
5275
  layout_var_decl (decl);
5275
  layout_var_decl (decl);
5276
  maybe_commonize_var (decl);
5276
  maybe_commonize_var (decl);
5277
	  if (DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl)
5278
	      && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl))
5279
	    {
5280
	      /* This is a const variable with implicit 'static'.  Set
5281
		 DECL_THIS_STATIC so we can tell it from variables that are
5282
		 !TREE_PUBLIC because of the anonymous namespace.  */
5283
	      DECL_THIS_STATIC (decl) = 1;
5284
	    }
5277
  make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
5285
  make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
5278
}
5286
}
(-)gcc/cp/tree.c (-1 / +12 lines)
Lines 2189-2195 Link Here
2189
  /* Things that are TREE_PUBLIC have external linkage.  */
2189
  /* Things that are TREE_PUBLIC have external linkage.  */
2190
  if (TREE_PUBLIC (decl))
2190
  if (TREE_PUBLIC (decl))
2191
    return lk_external;
2191
    return lk_external;
2192
  
2192
2193
  if (TREE_CODE (decl) == NAMESPACE_DECL)
2194
    return lk_external;
2195
2193
  /* Linkage of a CONST_DECL depends on the linkage of the enumeration 
2196
  /* Linkage of a CONST_DECL depends on the linkage of the enumeration 
2194
     type.  */
2197
     type.  */
2195
  if (TREE_CODE (decl) == CONST_DECL)
2198
  if (TREE_CODE (decl) == CONST_DECL)
Lines 2209-2214 Link Here
2209
  if (decl_function_context (decl))
2212
  if (decl_function_context (decl))
2210
    return lk_none;
2213
    return lk_none;
2211
2214
2215
  /* Members of the anonymous namespace also have TREE_PUBLIC unset, but
2216
     are considered to have external linkage for language purposes.  DECLs
2217
     really meant to have internal linkage have DECL_THIS_STATIC set.  */
2218
  if (TREE_CODE (decl) == TYPE_DECL
2219
      || ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
2220
	  && !DECL_THIS_STATIC (decl)))
2221
    return lk_external;
2222
2212
  /* Everything else has internal linkage.  */
2223
  /* Everything else has internal linkage.  */
2213
  return lk_internal;
2224
  return lk_internal;
2214
}
2225
}
(-)gcc/cp/pt.c (-2 / +12 lines)
Lines 6609-6615 Link Here
6609
6609
6610
	/* Possibly limit visibility based on template args.  */
6610
	/* Possibly limit visibility based on template args.  */
6611
	DECL_VISIBILITY (r) = VISIBILITY_DEFAULT;
6611
	DECL_VISIBILITY (r) = VISIBILITY_DEFAULT;
6612
	DECL_VISIBILITY_SPECIFIED (r) = 0;
6612
	if (DECL_VISIBILITY_SPECIFIED (t))
6613
	  {
6614
	    DECL_VISIBILITY_SPECIFIED (r) = 0;
6615
	    DECL_ATTRIBUTES (r)
6616
	      = remove_attribute ("visibility", DECL_ATTRIBUTES (r));
6617
	  }
6613
	determine_visibility (r);
6618
	determine_visibility (r);
6614
      }
6619
      }
6615
      break;
6620
      break;
Lines 6811-6817 Link Here
6811
	  {
6816
	  {
6812
	    /* Possibly limit visibility based on template args.  */
6817
	    /* Possibly limit visibility based on template args.  */
6813
	    DECL_VISIBILITY (r) = VISIBILITY_DEFAULT;
6818
	    DECL_VISIBILITY (r) = VISIBILITY_DEFAULT;
6814
	    DECL_VISIBILITY_SPECIFIED (r) = 0;
6819
	    if (DECL_VISIBILITY_SPECIFIED (t))
6820
	      {
6821
		DECL_VISIBILITY_SPECIFIED (r) = 0;
6822
		DECL_ATTRIBUTES (r)
6823
		  = remove_attribute ("visibility", DECL_ATTRIBUTES (r));
6824
	      }
6815
	    determine_visibility (r);
6825
	    determine_visibility (r);
6816
	  }
6826
	  }
6817
6827
(-)gcc/cp/decl2.c (-60 / +76 lines)
Lines 737-750 Link Here
737
    }
737
    }
738
}
738
}
739
739
740
/* Like note_vague_linkage_fn but for variables.  */
741
742
static void
743
note_vague_linkage_var (tree var)
744
{
745
  VEC_safe_push (tree, gc, pending_statics, var);
746
}
747
748
/* We have just processed the DECL, which is a static data member.
740
/* We have just processed the DECL, which is a static data member.
749
   The other parameters are as for cp_finish_decl.  */
741
   The other parameters are as for cp_finish_decl.  */
750
742
Lines 763-770 Link Here
763
  if (!asmspec_tree && current_class_type)
755
  if (!asmspec_tree && current_class_type)
764
    DECL_INITIAL (decl) = error_mark_node;
756
    DECL_INITIAL (decl) = error_mark_node;
765
757
766
  if (! processing_template_decl && TREE_PUBLIC (decl))
758
  if (! processing_template_decl)
767
    note_vague_linkage_var (decl);
759
    VEC_safe_push (tree, gc, pending_statics, decl);
768
760
769
  if (LOCAL_CLASS_P (current_class_type))
761
  if (LOCAL_CLASS_P (current_class_type))
770
    pedwarn ("local class %q#T shall not have static data member %q#D",
762
    pedwarn ("local class %q#T shall not have static data member %q#D",
Lines 1579-1585 Link Here
1579
/* A special return value from type_visibility meaning internal
1571
/* A special return value from type_visibility meaning internal
1580
   linkage.  */
1572
   linkage.  */
1581
1573
1582
enum { VISIBILITY_STATIC = VISIBILITY_INTERNAL+1 };
1574
enum { VISIBILITY_ANON = VISIBILITY_INTERNAL+1 };
1583
1575
1584
/* walk_tree helper function for type_visibility.  */
1576
/* walk_tree helper function for type_visibility.  */
1585
1577
Lines 1595-1601 Link Here
1595
    {
1587
    {
1596
      if (!TREE_PUBLIC (TYPE_MAIN_DECL (*tp)))
1588
      if (!TREE_PUBLIC (TYPE_MAIN_DECL (*tp)))
1597
	{
1589
	{
1598
	  *vis_p = VISIBILITY_STATIC;
1590
	  *vis_p = VISIBILITY_ANON;
1599
	  return *tp;
1591
	  return *tp;
1600
	}
1592
	}
1601
      else if (CLASSTYPE_VISIBILITY (*tp) > *vis_p)
1593
      else if (CLASSTYPE_VISIBILITY (*tp) > *vis_p)
Lines 1615-1643 Link Here
1615
  return vis;
1607
  return vis;
1616
}
1608
}
1617
1609
1618
/* Limit the visibility of DECL to VISIBILITY.  SPECIFIED is true if the
1610
/* Limit the visibility of DECL to VISIBILITY, if not explicitly
1619
   constraint comes from an attribute or pragma; REASON is the source of
1611
   specified (or if VISIBILITY is static).  */
1620
   the constraint.  */
1621
1612
1622
static bool
1613
static bool
1623
constrain_visibility (tree decl, int visibility, bool specified,
1614
constrain_visibility (tree decl, int visibility)
1624
		      const char *reason)
1625
{
1615
{
1626
  if (visibility == VISIBILITY_STATIC)
1616
  if (visibility == VISIBILITY_ANON)
1627
    {
1617
    {
1628
      TREE_PUBLIC (decl) = 0;
1618
      /* extern "C" declarations aren't affected by the anonymous
1629
      DECL_INTERFACE_KNOWN (decl) = 1;
1619
	 namespace.  */
1630
      if (DECL_LANG_SPECIFIC (decl))
1620
      if (!DECL_EXTERN_C_P (decl))
1631
	DECL_NOT_REALLY_EXTERN (decl) = 1;
1621
	{
1622
	  TREE_PUBLIC (decl) = 0;
1623
	  DECL_INTERFACE_KNOWN (decl) = 1;
1624
	  if (DECL_LANG_SPECIFIC (decl))
1625
	    DECL_NOT_REALLY_EXTERN (decl) = 1;
1626
	}
1632
    }
1627
    }
1633
  else if (visibility > DECL_VISIBILITY (decl))
1628
  else if (visibility > DECL_VISIBILITY (decl)
1629
	   && !DECL_VISIBILITY_SPECIFIED (decl))
1634
    {
1630
    {
1635
      if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl)))
1636
	warning (OPT_Wattributes, "%q+D: visibility attribute requests "
1637
		 "greater visibility than its %s allows", decl, reason);
1638
      DECL_VISIBILITY (decl) = visibility;
1631
      DECL_VISIBILITY (decl) = visibility;
1639
      if (!DECL_VISIBILITY_SPECIFIED (decl))
1640
	DECL_VISIBILITY_SPECIFIED (decl) = specified;
1641
      return true;
1632
      return true;
1642
    }
1633
    }
1643
  return false;
1634
  return false;
Lines 1670-1682 Link Here
1670
	      || TREE_CODE (arg) == FUNCTION_DECL)
1661
	      || TREE_CODE (arg) == FUNCTION_DECL)
1671
	    {
1662
	    {
1672
	      if (! TREE_PUBLIC (arg))
1663
	      if (! TREE_PUBLIC (arg))
1673
		vis = VISIBILITY_STATIC;
1664
		vis = VISIBILITY_ANON;
1674
	      else
1665
	      else
1675
		vis = DECL_VISIBILITY (arg);
1666
		vis = DECL_VISIBILITY (arg);
1676
	    }
1667
	    }
1677
	}
1668
	}
1678
      if (vis)
1669
      if (vis)
1679
	constrain_visibility (decl, vis, false, "template parameter");
1670
	constrain_visibility (decl, vis);
1680
    }
1671
    }
1681
}
1672
}
1682
1673
Lines 1771-1778 Link Here
1771
	{
1762
	{
1772
	  /* tinfo visibility is based on the type it's for.  */
1763
	  /* tinfo visibility is based on the type it's for.  */
1773
	  constrain_visibility
1764
	  constrain_visibility
1774
	    (decl, type_visibility (TREE_TYPE (DECL_NAME (decl))),
1765
	    (decl, type_visibility (TREE_TYPE (DECL_NAME (decl))));
1775
	     false, "type");
1776
	}
1766
	}
1777
      else if (use_template)
1767
      else if (use_template)
1778
	/* Template instantiations and specializations get visibility based
1768
	/* Template instantiations and specializations get visibility based
Lines 1788-1811 Link Here
1788
1778
1789
  if (use_template)
1779
  if (use_template)
1790
    {
1780
    {
1781
      /* If the specialization doesn't specify visibility, use the
1782
	 visibility from the template.  */
1791
      tree tinfo = (TREE_CODE (decl) == TYPE_DECL
1783
      tree tinfo = (TREE_CODE (decl) == TYPE_DECL
1792
		    ? TYPE_TEMPLATE_INFO (TREE_TYPE (decl))
1784
		    ? TYPE_TEMPLATE_INFO (TREE_TYPE (decl))
1793
		    : DECL_TEMPLATE_INFO (decl));
1785
		    : DECL_TEMPLATE_INFO (decl));
1794
      tree args = TI_ARGS (tinfo);
1786
      tree args = TI_ARGS (tinfo);
1795
      int depth = TMPL_ARGS_DEPTH (args);
1787
      int depth = TMPL_ARGS_DEPTH (args);
1788
      tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo));
1796
1789
1797
      /* If the template has explicit visibility and the specialization
1798
	 doesn't, use the visibility from the template.  */
1799
      if (!DECL_VISIBILITY_SPECIFIED (decl))
1790
      if (!DECL_VISIBILITY_SPECIFIED (decl))
1800
	{
1791
	{
1801
	  tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo));
1802
	  DECL_VISIBILITY (decl) = DECL_VISIBILITY (pattern);
1792
	  DECL_VISIBILITY (decl) = DECL_VISIBILITY (pattern);
1793
	  DECL_VISIBILITY_SPECIFIED (decl)
1794
	    = DECL_VISIBILITY_SPECIFIED (pattern);
1803
	}
1795
	}
1804
1796
1805
      /* FIXME should TMPL_ARGS_DEPTH really return 1 for null input? */
1797
      /* FIXME should TMPL_ARGS_DEPTH really return 1 for null input? */
1806
      if (args && depth > template_class_depth (class_type))
1798
      if (args && depth > template_class_depth (class_type))
1807
	/* Don't let it have more visibility than its template type
1799
	/* Limit visibility based on its template arguments.  */
1808
	   arguments.  */
1809
	constrain_visibility_for_template (decl, args);
1800
	constrain_visibility_for_template (decl, args);
1810
    }
1801
    }
1811
1802
Lines 1814-1830 Link Here
1814
1805
1815
  /* Don't let it have more visibility than its type.  */
1806
  /* Don't let it have more visibility than its type.  */
1816
  if (TREE_CODE (decl) != TYPE_DECL)
1807
  if (TREE_CODE (decl) != TYPE_DECL)
1817
    if (constrain_visibility (decl, type_visibility (TREE_TYPE (decl)),
1808
    if (constrain_visibility (decl, type_visibility (TREE_TYPE (decl))))
1818
			      false, "type"))
1819
      warning (OPT_Wattributes, "\
1809
      warning (OPT_Wattributes, "\
1820
%q+D declared with greater visibility than its type",
1810
lowering visibility of %q+D to match its type",
1821
	       decl);
1811
	       decl);
1822
1812
1823
  if (decl_anon_ns_mem_p (decl))
1813
  if (decl_anon_ns_mem_p (decl))
1824
    /* Names in an anonymous namespace get internal linkage.
1814
    /* Names in an anonymous namespace get internal linkage.
1825
       This might change once we implement export.  */
1815
       This might change once we implement export.  */
1826
    constrain_visibility (decl, VISIBILITY_STATIC,
1816
    constrain_visibility (decl, VISIBILITY_ANON);
1827
			  false, "namespace");
1828
}
1817
}
1829
1818
1830
/* By default, static data members and function members receive
1819
/* By default, static data members and function members receive
Lines 1842-1853 Link Here
1842
      && TREE_CODE (decl) == FUNCTION_DECL
1831
      && TREE_CODE (decl) == FUNCTION_DECL
1843
      && DECL_DECLARED_INLINE_P (decl))
1832
      && DECL_DECLARED_INLINE_P (decl))
1844
    DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1833
    DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1834
  else if (!DECL_VISIBILITY_SPECIFIED (decl))
1835
    {
1836
      /* Default to the class visibility.  */
1837
      DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type);
1838
      DECL_VISIBILITY_SPECIFIED (decl)
1839
	= CLASSTYPE_VISIBILITY_SPECIFIED (class_type);
1840
    }
1845
1841
1846
  /* The decl can't have more visibility than its class.  */
1847
  constrain_visibility (decl, CLASSTYPE_VISIBILITY (class_type),
1848
			CLASSTYPE_VISIBILITY_SPECIFIED (class_type),
1849
			"class");
1850
1851
  /* Give the target a chance to override the visibility associated
1842
  /* Give the target a chance to override the visibility associated
1852
     with DECL.  */
1843
     with DECL.  */
1853
  if (TREE_CODE (decl) == VAR_DECL
1844
  if (TREE_CODE (decl) == VAR_DECL
Lines 1859-1866 Link Here
1859
	      && !DECL_CONSTRUCTION_VTABLE_P (decl)))
1850
	      && !DECL_CONSTRUCTION_VTABLE_P (decl)))
1860
      && TREE_PUBLIC (decl)
1851
      && TREE_PUBLIC (decl)
1861
      && !DECL_REALLY_EXTERN (decl)
1852
      && !DECL_REALLY_EXTERN (decl)
1862
      && DECL_VISIBILITY_SPECIFIED (decl)
1853
      && !DECL_VISIBILITY_SPECIFIED (decl)
1863
      && (!class_type || !CLASSTYPE_VISIBILITY_SPECIFIED (class_type)))
1854
      && !CLASSTYPE_VISIBILITY_SPECIFIED (class_type))
1864
    targetm.cxx.determine_class_data_visibility (decl);
1855
    targetm.cxx.determine_class_data_visibility (decl);
1865
}
1856
}
1866
1857
Lines 1870-1894 Link Here
1870
void
1861
void
1871
constrain_class_visibility (tree type)
1862
constrain_class_visibility (tree type)
1872
{
1863
{
1873
  tree decl = TYPE_MAIN_DECL (type);
1864
  tree binfo;
1874
  tree binfo = TYPE_BINFO (type);
1875
  tree t;
1865
  tree t;
1876
  int i;
1866
  int i;
1877
1867
1868
  int vis = type_visibility (type);
1869
1870
  if (vis == VISIBILITY_ANON)
1871
    return;
1872
1873
  /* Don't warn about visibility if the class has explicit visibility.  */
1874
  if (CLASSTYPE_VISIBILITY_SPECIFIED (type))
1875
    vis = VISIBILITY_INTERNAL;
1876
1878
  for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
1877
  for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
1879
    if (TREE_CODE (t) == FIELD_DECL)
1878
    if (TREE_CODE (t) == FIELD_DECL && TREE_TYPE (t) != error_mark_node)
1880
      if (constrain_visibility (decl, type_visibility (TREE_TYPE (t)),
1879
      {
1881
				false, "field type"))
1880
	int subvis = type_visibility (TREE_TYPE (t));
1882
	warning (OPT_Wattributes, "\
1881
1882
	if (subvis == VISIBILITY_ANON)
1883
	  warning (0, "\
1884
%qT has a field %qD whose type uses the anonymous namespace",
1885
		   type, t);
1886
	else if (vis < VISIBILITY_HIDDEN
1887
		 && subvis >= VISIBILITY_HIDDEN)
1888
	  warning (OPT_Wattributes, "\
1883
%qT declared with greater visibility than the type of its field %qD",
1889
%qT declared with greater visibility than the type of its field %qD",
1884
		 type, t);
1890
		   type, t);
1891
      }
1885
1892
1893
  binfo = TYPE_BINFO (type);
1886
  for (i = 0; BINFO_BASE_ITERATE (binfo, i, t); ++i)
1894
  for (i = 0; BINFO_BASE_ITERATE (binfo, i, t); ++i)
1887
    if (constrain_visibility (decl, type_visibility (TREE_TYPE (t)),
1895
    {
1888
			      false, "base type"))
1896
      int subvis = type_visibility (TREE_TYPE (t));
1889
      warning (OPT_Wattributes, "\
1897
1898
      if (subvis == VISIBILITY_ANON)
1899
	warning (0, "\
1900
%qT has a base %qT whose type uses the anonymous namespace",
1901
		 type, TREE_TYPE (t));
1902
      else if (vis < VISIBILITY_HIDDEN
1903
	       && subvis >= VISIBILITY_HIDDEN)
1904
	warning (OPT_Wattributes, "\
1890
%qT declared with greater visibility than its base %qT",
1905
%qT declared with greater visibility than its base %qT",
1891
	       type, TREE_TYPE (t));
1906
		 type, TREE_TYPE (t));
1907
    }
1892
}
1908
}
1893
1909
1894
/* DECL is a FUNCTION_DECL or VAR_DECL.  If the object file linkage
1910
/* DECL is a FUNCTION_DECL or VAR_DECL.  If the object file linkage

Return to bug 146817