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 |