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/testsuite/g++.dg/ext/visibility/local1.C (+25 lines)
Line 0 Link Here
1
// PR c++/19238
2
// Test that hidden visibility on an inline function is inherited by static
3
// local variables and local classes.
4
5
// { dg-require-visibility "" }
6
// { dg-final { scan-hidden "_Z1fv" } }
7
// { dg-final { scan-hidden "_ZZ1fvE1i" } }
8
// { dg-final { scan-hidden "_ZZ1fvEN1A1fEv" } }
9
10
__attribute ((visibility ("hidden"))) inline int
11
f()
12
{
13
  static int i = 2;
14
  struct A
15
  {
16
    void f () { }
17
  } a;
18
  a.f();
19
  return i;
20
}
21
22
int main()
23
{
24
  f();
25
}
(-)gcc/testsuite/g++.dg/ext/visibility/namespace1.C (+30 lines)
Line 0 Link Here
1
// PR c++/21764
2
// Test for namespace visibility attribute semantics.
3
4
// { dg-require-visibility "" }
5
// { dg-final { scan-hidden "_ZN3foo1fEv" } }
6
// { dg-final { scan-hidden "_ZN3foo1gEv" } }
7
// { dg-final { scan-hidden "_ZN3foo1A1mEv" } }
8
// { dg-final { scan-hidden "_ZN3foo1tIiEEvv" } }
9
// { dg-final { scan-not-hidden "_ZN3foo1hEv" } }
10
11
namespace foo __attribute ((visibility ("hidden")))
12
{
13
  int f() { }
14
  void g();
15
  template <typename T> void t() { }
16
  class A
17
  {
18
    void m ();
19
  };
20
}
21
22
namespace foo
23
{
24
  void h() {}
25
}
26
27
void foo::g() { t<int> (); }
28
29
void foo::A::m() { }
30
(-)gcc/cp/decl.c (-9 / +11 lines)
Lines 5243-5251 Link Here
5243
	     the class specifier.  */
5243
	     the class specifier.  */
5244
	  if (!DECL_EXTERNAL (decl))
5244
	  if (!DECL_EXTERNAL (decl))
5245
	    var_definition_p = true;
5245
	    var_definition_p = true;
5246
	  /* The variable is being defined, so determine its
5247
	     visibility.  */
5248
	  determine_visibility (decl);
5249
	}
5246
	}
5250
      /* If the variable has an array type, lay out the type, even if
5247
      /* If the variable has an array type, lay out the type, even if
5251
	 there is no initializer.  It is valid to index through the
5248
	 there is no initializer.  It is valid to index through the
Lines 5310-5315 Link Here
5310
		initialize_local_var (decl, init);
5307
		initialize_local_var (decl, init);
5311
	    }
5308
	    }
5312
5309
5310
	  /* The variable is being defined, so determine its visibility.
5311
	     This needs to happen after the linkage is set. */
5312
	  determine_visibility (decl);
5313
5313
	  /* If a variable is defined, and then a subsequent
5314
	  /* If a variable is defined, and then a subsequent
5314
	     definition with external linkage is encountered, we will
5315
	     definition with external linkage is encountered, we will
5315
	     get here twice for the same variable.  We want to avoid
5316
	     get here twice for the same variable.  We want to avoid
Lines 10497-10508 Link Here
10497
	maybe_apply_pragma_weak (decl1);
10498
	maybe_apply_pragma_weak (decl1);
10498
    }
10499
    }
10499
10500
10500
  /* Determine the ELF visibility attribute for the function.  We must
10501
     not do this before calling "pushdecl", as we must allow
10502
     "duplicate_decls" to merge any attributes appropriately.  */
10503
  if (!DECL_CLONED_FUNCTION_P (decl1))
10504
    determine_visibility (decl1);
10505
10506
  /* Reset these in case the call to pushdecl changed them.  */
10501
  /* Reset these in case the call to pushdecl changed them.  */
10507
  current_function_decl = decl1;
10502
  current_function_decl = decl1;
10508
  cfun->decl = decl1;
10503
  cfun->decl = decl1;
Lines 10621-10626 Link Here
10621
	DECL_INTERFACE_KNOWN (decl1) = 1;
10616
	DECL_INTERFACE_KNOWN (decl1) = 1;
10622
    }
10617
    }
10623
10618
10619
  /* Determine the ELF visibility attribute for the function.  We must not
10620
     do this before calling "pushdecl", as we must allow "duplicate_decls"
10621
     to merge any attributes appropriately.  We also need to wait until
10622
     linkage is set.  */
10623
  if (!DECL_CLONED_FUNCTION_P (decl1))
10624
    determine_visibility (decl1);
10625
10624
  begin_scope (sk_function_parms, decl1);
10626
  begin_scope (sk_function_parms, decl1);
10625
10627
10626
  ++function_depth;
10628
  ++function_depth;
(-)gcc/cp/cp-tree.h (+12 lines)
Lines 1966-1971 Link Here
1966
/* NULL_TREE in DECL_CONTEXT represents the global namespace.  */
1966
/* NULL_TREE in DECL_CONTEXT represents the global namespace.  */
1967
#define CP_DECL_CONTEXT(NODE) \
1967
#define CP_DECL_CONTEXT(NODE) \
1968
  (DECL_CONTEXT (NODE) ? DECL_CONTEXT (NODE) : global_namespace)
1968
  (DECL_CONTEXT (NODE) ? DECL_CONTEXT (NODE) : global_namespace)
1969
#define CP_TYPE_CONTEXT(NODE) \
1970
  (TYPE_CONTEXT (NODE) ? TYPE_CONTEXT (NODE) : global_namespace)
1969
#define FROB_CONTEXT(NODE)   ((NODE) == global_namespace ? NULL_TREE : (NODE))
1971
#define FROB_CONTEXT(NODE)   ((NODE) == global_namespace ? NULL_TREE : (NODE))
1970
1972
1971
/* 1 iff NODE has namespace scope, including the global namespace.  */
1973
/* 1 iff NODE has namespace scope, including the global namespace.  */
Lines 1973-1987 Link Here
1973
  (!DECL_TEMPLATE_PARM_P (NODE)					\
1975
  (!DECL_TEMPLATE_PARM_P (NODE)					\
1974
   && TREE_CODE (CP_DECL_CONTEXT (NODE)) == NAMESPACE_DECL)
1976
   && TREE_CODE (CP_DECL_CONTEXT (NODE)) == NAMESPACE_DECL)
1975
1977
1978
#define TYPE_NAMESPACE_SCOPE_P(NODE)				\
1979
  (TREE_CODE (CP_TYPE_CONTEXT (NODE)) == NAMESPACE_DECL)
1980
1976
/* 1 iff NODE is a class member.  */
1981
/* 1 iff NODE is a class member.  */
1977
#define DECL_CLASS_SCOPE_P(NODE) \
1982
#define DECL_CLASS_SCOPE_P(NODE) \
1978
  (DECL_CONTEXT (NODE) && TYPE_P (DECL_CONTEXT (NODE)))
1983
  (DECL_CONTEXT (NODE) && TYPE_P (DECL_CONTEXT (NODE)))
1979
1984
1985
#define TYPE_CLASS_SCOPE_P(NODE) \
1986
  (TYPE_CONTEXT (NODE) && TYPE_P (TYPE_CONTEXT (NODE)))
1987
1980
/* 1 iff NODE is function-local.  */
1988
/* 1 iff NODE is function-local.  */
1981
#define DECL_FUNCTION_SCOPE_P(NODE) \
1989
#define DECL_FUNCTION_SCOPE_P(NODE) \
1982
  (DECL_CONTEXT (NODE) \
1990
  (DECL_CONTEXT (NODE) \
1983
   && TREE_CODE (DECL_CONTEXT (NODE)) == FUNCTION_DECL)
1991
   && TREE_CODE (DECL_CONTEXT (NODE)) == FUNCTION_DECL)
1984
1992
1993
#define TYPE_FUNCTION_SCOPE_P(NODE) \
1994
  (TYPE_CONTEXT (NODE) \
1995
   && TREE_CODE (TYPE_CONTEXT (NODE)) == FUNCTION_DECL)
1996
1985
/* 1 iff VAR_DECL node NODE is a type-info decl.  This flag is set for
1997
/* 1 iff VAR_DECL node NODE is a type-info decl.  This flag is set for
1986
   both the primary typeinfo object and the associated NTBS name.  */
1998
   both the primary typeinfo object and the associated NTBS name.  */
1987
#define DECL_TINFO_P(NODE) TREE_LANG_FLAG_4 (VAR_DECL_CHECK (NODE))
1999
#define DECL_TINFO_P(NODE) TREE_LANG_FLAG_4 (VAR_DECL_CHECK (NODE))
(-)gcc/cp/name-lookup.c (-1 / +47 lines)
Lines 31-36 Link Here
31
#include "toplev.h"
31
#include "toplev.h"
32
#include "diagnostic.h"
32
#include "diagnostic.h"
33
#include "debug.h"
33
#include "debug.h"
34
#include "c-pragma.h"
34
35
35
/* The bindings for a particular name in a particular scope.  */
36
/* The bindings for a particular name in a particular scope.  */
36
37
Lines 1344-1354 Link Here
1344
      is_class_level = 0;
1345
      is_class_level = 0;
1345
    }
1346
    }
1346
1347
1348
#ifdef HANDLE_PRAGMA_VISIBILITY
1349
  if (scope->has_visibility)
1350
    pop_visibility ();
1351
#endif
1352
1347
  /* Move one nesting level up.  */
1353
  /* Move one nesting level up.  */
1348
  current_binding_level = scope->level_chain;
1354
  current_binding_level = scope->level_chain;
1349
1355
1350
  /* Namespace-scopes are left most probably temporarily, not
1356
  /* Namespace-scopes are left most probably temporarily, not
1351
     completely; they can be reopen later, e.g. in namespace-extension
1357
     completely; they can be reopened later, e.g. in namespace-extension
1352
     or any name binding activity that requires us to resume a
1358
     or any name binding activity that requires us to resume a
1353
     namespace.  For classes, we cache some binding levels.  For other
1359
     namespace.  For classes, we cache some binding levels.  For other
1354
     scopes, we just make the structure available for reuse.  */
1360
     scopes, we just make the structure available for reuse.  */
Lines 2971-2976 Link Here
2971
void
2977
void
2972
push_namespace (tree name)
2978
push_namespace (tree name)
2973
{
2979
{
2980
  push_namespace_with_attribs (name, NULL_TREE);
2981
}
2982
2983
/* Same, but specify attributes to apply to the namespace.  The attributes
2984
   only apply to the current namespace-body, not to any later extensions. */
2985
2986
void
2987
push_namespace_with_attribs (tree name, tree attributes)
2988
{
2974
  tree d = NULL_TREE;
2989
  tree d = NULL_TREE;
2975
  int need_new = 1;
2990
  int need_new = 1;
2976
  int implicit_use = 0;
2991
  int implicit_use = 0;
Lines 3017-3022 Link Here
3017
      /* Make a new namespace, binding the name to it.  */
3032
      /* Make a new namespace, binding the name to it.  */
3018
      d = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
3033
      d = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
3019
      DECL_CONTEXT (d) = FROB_CONTEXT (current_namespace);
3034
      DECL_CONTEXT (d) = FROB_CONTEXT (current_namespace);
3035
      TREE_PUBLIC (d) = 1;
3020
      pushdecl (d);
3036
      pushdecl (d);
3021
      if (anon)
3037
      if (anon)
3022
	{
3038
	{
Lines 3034-3039 Link Here
3034
  /* Enter the name space.  */
3050
  /* Enter the name space.  */
3035
  current_namespace = d;
3051
  current_namespace = d;
3036
3052
3053
#ifdef HANDLE_PRAGMA_VISIBILITY
3054
  /* Clear has_visibility in case a previous namespace-definition had a
3055
     visibility attribute and this one doesn't.  */
3056
  current_binding_level->has_visibility = 0;
3057
  for (d = attributes; d; d = TREE_CHAIN (d))
3058
    {
3059
      tree name = TREE_PURPOSE (d);
3060
      tree args = TREE_VALUE (d);
3061
      tree x;
3062
      
3063
      if (! is_attribute_p ("visibility", name))
3064
	{
3065
	  warning (OPT_Wattributes, "%qs attribute directive ignored",
3066
		   IDENTIFIER_POINTER (name));
3067
	  continue;
3068
	}
3069
3070
      x = args ? TREE_VALUE (args) : NULL_TREE;
3071
      if (x == NULL_TREE || TREE_CODE (x) != STRING_CST)
3072
	{
3073
	  warning (OPT_Wattributes, "%qs attribute requires an NTBS argument",
3074
		   IDENTIFIER_POINTER (name));
3075
	  continue;
3076
	}
3077
3078
      current_binding_level->has_visibility = 1;
3079
      push_visibility (TREE_STRING_POINTER (x));
3080
    }
3081
#endif
3082
3037
  timevar_pop (TV_NAME_LOOKUP);
3083
  timevar_pop (TV_NAME_LOOKUP);
3038
}
3084
}
3039
3085
(-)gcc/cp/decl2.c (-40 / +77 lines)
Lines 82-87 Link Here
82
static void write_out_vars (tree);
82
static void write_out_vars (tree);
83
static void import_export_class (tree);
83
static void import_export_class (tree);
84
static tree get_guard_bits (tree);
84
static tree get_guard_bits (tree);
85
static void determine_visibility_from_class (tree, tree);
85
86
86
/* A list of static class variables.  This is needed, because a
87
/* A list of static class variables.  This is needed, because a
87
   static class variable can be declared inside the class without
88
   static class variable can be declared inside the class without
Lines 1578-1590 Link Here
1578
}
1579
}
1579
1580
1580
/* Like c_determine_visibility, but with additional C++-specific
1581
/* Like c_determine_visibility, but with additional C++-specific
1581
   behavior.  */
1582
   behavior.
1582
1583
1584
   Function-scope entities can rely on the function's visibility because
1585
   it is set in start_preparsed_function.
1586
1587
   Class-scope entities cannot rely on the class's visibility until the end
1588
   of the enclosing class definition.
1589
1590
   Note that because namespaces have multiple independent definitions,
1591
   namespace visibility is handled elsewhere using the #pragma visibility
1592
   machinery rather than by decorating the namespace declaration.  */
1593
1583
void
1594
void
1584
determine_visibility (tree decl)
1595
determine_visibility (tree decl)
1585
{
1596
{
1586
  tree class_type;
1597
  tree class_type;
1587
1598
1599
  /* Only relevant for names with external linkage.  */
1600
  if (!TREE_PUBLIC (decl))
1601
    return;
1602
1588
  /* Cloned constructors and destructors get the same visibility as
1603
  /* Cloned constructors and destructors get the same visibility as
1589
     the underlying function.  That should be set up in
1604
     the underlying function.  That should be set up in
1590
     maybe_clone_body.  */
1605
     maybe_clone_body.  */
Lines 1608-1613 Link Here
1608
	 so they are automatically handled above.  */
1623
	 so they are automatically handled above.  */
1609
      gcc_assert (TREE_CODE (decl) != VAR_DECL
1624
      gcc_assert (TREE_CODE (decl) != VAR_DECL
1610
		  || !DECL_VTABLE_OR_VTT_P (decl));
1625
		  || !DECL_VTABLE_OR_VTT_P (decl));
1626
1627
      if (DECL_FUNCTION_SCOPE_P (decl))
1628
	{
1629
	  tree fn = DECL_CONTEXT (decl);
1630
	  DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn);
1631
	  DECL_VISIBILITY_SPECIFIED (decl) = DECL_VISIBILITY_SPECIFIED (fn);
1632
	}
1633
1611
      /* Entities not associated with any class just get the
1634
      /* Entities not associated with any class just get the
1612
	 visibility specified by their attributes.  */
1635
	 visibility specified by their attributes.  */
1613
      return;
1636
      return;
Lines 1617-1650 Link Here
1617
     the visibility of their containing class.  */
1640
     the visibility of their containing class.  */
1618
  if (class_type)
1641
  if (class_type)
1619
    {
1642
    {
1620
      if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
1643
      determine_visibility_from_class (decl, class_type);
1621
	  && lookup_attribute ("dllexport", TYPE_ATTRIBUTES (class_type)))
1644
1645
      /* Give the target a chance to override the visibility associated
1646
	 with DECL.  */
1647
      if (TREE_CODE (decl) == VAR_DECL
1648
	  && (DECL_TINFO_P (decl)
1649
	      || (DECL_VTABLE_OR_VTT_P (decl)
1650
		  /* Construction virtual tables are not exported because
1651
		     they cannot be referred to from other object files;
1652
		     their name is not standardized by the ABI.  */
1653
		  && !DECL_CONSTRUCTION_VTABLE_P (decl)))
1654
	  && TREE_PUBLIC (decl)
1655
	  && !DECL_REALLY_EXTERN (decl)
1656
	  && DECL_VISIBILITY_SPECIFIED (decl)
1657
	  && (!class_type || !CLASSTYPE_VISIBILITY_SPECIFIED (class_type)))
1658
	targetm.cxx.determine_class_data_visibility (decl);
1659
    }      
1660
}
1661
1662
static void
1663
determine_visibility_from_class (tree decl, tree class_type)
1664
{
1665
  if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
1666
      && lookup_attribute ("dllexport", TYPE_ATTRIBUTES (class_type)))
1667
    {
1668
      DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
1669
      DECL_VISIBILITY_SPECIFIED (decl) = 1;
1670
    }
1671
  else if (TREE_CODE (decl) == FUNCTION_DECL
1672
	   && DECL_DECLARED_INLINE_P (decl)
1673
	   && visibility_options.inlines_hidden)
1674
    {
1675
      /* Don't change it if it has been set explicitly by user.  */
1676
      if (!DECL_VISIBILITY_SPECIFIED (decl))
1622
	{
1677
	{
1623
	  DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
1678
	  DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1624
	  DECL_VISIBILITY_SPECIFIED (decl) = 1;
1679
	  DECL_VISIBILITY_SPECIFIED (decl) = 1;
1625
	}
1680
	}
1626
      else if (TREE_CODE (decl) == FUNCTION_DECL
1627
	       && DECL_DECLARED_INLINE_P (decl)
1628
	       && visibility_options.inlines_hidden)
1629
	{
1630
	  /* Don't change it if it has been set explicitly by user.  */
1631
	  if (!DECL_VISIBILITY_SPECIFIED (decl))
1632
	    {
1633
	      DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1634
	      DECL_VISIBILITY_SPECIFIED (decl) = 1;
1635
	    }
1636
	}
1637
      else if (CLASSTYPE_VISIBILITY_SPECIFIED (class_type))
1638
	{
1639
	  DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type);
1640
	  DECL_VISIBILITY_SPECIFIED (decl) = 1;
1641
	}
1642
      else if (!DECL_VISIBILITY_SPECIFIED (decl))
1643
	{
1644
	  DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type);
1645
	  DECL_VISIBILITY_SPECIFIED (decl) = 0;
1646
	}
1647
    }
1681
    }
1682
  else if (CLASSTYPE_VISIBILITY_SPECIFIED (class_type))
1683
    {
1684
      DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type);
1685
      DECL_VISIBILITY_SPECIFIED (decl) = 1;
1686
    }
1687
  else if (TYPE_CLASS_SCOPE_P (class_type))
1688
    determine_visibility_from_class (decl, TYPE_CONTEXT (class_type));
1689
  else if (TYPE_FUNCTION_SCOPE_P (class_type))
1690
    {
1691
      tree fn = TYPE_CONTEXT (class_type);
1692
      DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn);
1693
      DECL_VISIBILITY_SPECIFIED (decl) = DECL_VISIBILITY_SPECIFIED (fn);
1694
    }
1695
  else if (!DECL_VISIBILITY_SPECIFIED (decl))
1696
    {
1697
      DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type);
1698
      DECL_VISIBILITY_SPECIFIED (decl) = 0;
1699
    }
1648
}
1700
}
1649
1701
1650
/* DECL is a FUNCTION_DECL or VAR_DECL.  If the object file linkage
1702
/* DECL is a FUNCTION_DECL or VAR_DECL.  If the object file linkage
Lines 1911-1931 Link Here
1911
      comdat_linkage (decl);
1963
      comdat_linkage (decl);
1912
    }
1964
    }
1913
1965
1914
  /* Give the target a chance to override the visibility associated
1915
     with DECL.  */
1916
  if (TREE_CODE (decl) == VAR_DECL
1917
      && (DECL_TINFO_P (decl)
1918
	  || (DECL_VTABLE_OR_VTT_P (decl)
1919
	      /* Construction virtual tables are not exported because
1920
		 they cannot be referred to from other object files;
1921
		 their name is not standardized by the ABI.  */
1922
	      && !DECL_CONSTRUCTION_VTABLE_P (decl)))
1923
      && TREE_PUBLIC (decl)
1924
      && !DECL_REALLY_EXTERN (decl)
1925
      && DECL_VISIBILITY_SPECIFIED (decl)
1926
      && (!class_type || !CLASSTYPE_VISIBILITY_SPECIFIED (class_type)))
1927
    targetm.cxx.determine_class_data_visibility (decl);
1928
1929
  DECL_INTERFACE_KNOWN (decl) = 1;
1966
  DECL_INTERFACE_KNOWN (decl) = 1;
1930
}
1967
}
1931
1968
(-)gcc/cp/name-lookup.h (-1 / +6 lines)
Lines 259-265 Link Here
259
    unsigned more_cleanups_ok : 1;
259
    unsigned more_cleanups_ok : 1;
260
    unsigned have_cleanups : 1;
260
    unsigned have_cleanups : 1;
261
261
262
    /* 22 bits left to fill a 32-bit word.  */
262
    /* Nonzero if this level has associated visibility which we should pop
263
       when leaving the scope. */
264
    unsigned has_visibility : 1;
265
266
    /* 23 bits left to fill a 32-bit word.  */
263
  };
267
  };
264
268
265
/* The binding level currently in effect.  */
269
/* The binding level currently in effect.  */
Lines 307-312 Link Here
307
extern void push_binding_level (struct cp_binding_level *);
311
extern void push_binding_level (struct cp_binding_level *);
308
312
309
extern void push_namespace (tree);
313
extern void push_namespace (tree);
314
extern void push_namespace_with_attribs (tree, tree);
310
extern void pop_namespace (void);
315
extern void pop_namespace (void);
311
extern void push_nested_namespace (tree);
316
extern void push_nested_namespace (tree);
312
extern void pop_nested_namespace (tree);
317
extern void pop_nested_namespace (tree);
(-)gcc/cp/parser.c (-3 / +6 lines)
Lines 7112-7118 Link Here
7112
	   && (/* A named namespace definition.  */
7112
	   && (/* A named namespace definition.  */
7113
	       (token2.type == CPP_NAME
7113
	       (token2.type == CPP_NAME
7114
		&& (cp_lexer_peek_nth_token (parser->lexer, 3)->type
7114
		&& (cp_lexer_peek_nth_token (parser->lexer, 3)->type
7115
		    == CPP_OPEN_BRACE))
7115
		    != CPP_EQ))
7116
	       /* An unnamed namespace definition.  */
7116
	       /* An unnamed namespace definition.  */
7117
	       || token2.type == CPP_OPEN_BRACE))
7117
	       || token2.type == CPP_OPEN_BRACE))
7118
    cp_parser_namespace_definition (parser);
7118
    cp_parser_namespace_definition (parser);
Lines 10471-10477 Link Here
10471
static void
10471
static void
10472
cp_parser_namespace_definition (cp_parser* parser)
10472
cp_parser_namespace_definition (cp_parser* parser)
10473
{
10473
{
10474
  tree identifier;
10474
  tree identifier, attribs;
10475
10475
10476
  /* Look for the `namespace' keyword.  */
10476
  /* Look for the `namespace' keyword.  */
10477
  cp_parser_require_keyword (parser, RID_NAMESPACE, "`namespace'");
10477
  cp_parser_require_keyword (parser, RID_NAMESPACE, "`namespace'");
Lines 10485-10494 Link Here
10485
  else
10485
  else
10486
    identifier = NULL_TREE;
10486
    identifier = NULL_TREE;
10487
10487
10488
  /* Parse any specified attributes.  */
10489
  attribs = cp_parser_attributes_opt (parser);
10490
10488
  /* Look for the `{' to start the namespace.  */
10491
  /* Look for the `{' to start the namespace.  */
10489
  cp_parser_require (parser, CPP_OPEN_BRACE, "`{'");
10492
  cp_parser_require (parser, CPP_OPEN_BRACE, "`{'");
10490
  /* Start the namespace.  */
10493
  /* Start the namespace.  */
10491
  push_namespace (identifier);
10494
  push_namespace_with_attribs (identifier, attribs);
10492
  /* Parse the body of the namespace.  */
10495
  /* Parse the body of the namespace.  */
10493
  cp_parser_namespace_body (parser);
10496
  cp_parser_namespace_body (parser);
10494
  /* Finish the namespace.  */
10497
  /* Finish the namespace.  */
(-)gcc/c-pragma.c (-9 / +35 lines)
Lines 596-604 Link Here
596
typedef enum symbol_visibility visibility;
596
typedef enum symbol_visibility visibility;
597
DEF_VEC_I (visibility);
597
DEF_VEC_I (visibility);
598
DEF_VEC_ALLOC_I (visibility, heap);
598
DEF_VEC_ALLOC_I (visibility, heap);
599
static VEC (visibility, heap) *visstack;
599
600
601
/* Push the visibility indicated by STR onto the top of the #pragma
602
   visibility stack.  */
603
604
void
605
push_visibility (const char *str)
606
{
607
  VEC_safe_push (visibility, heap, visstack,
608
		 default_visibility);
609
  if (!strcmp (str, "default"))
610
    default_visibility = VISIBILITY_DEFAULT;
611
  else if (!strcmp (str, "internal"))
612
    default_visibility = VISIBILITY_INTERNAL;
613
  else if (!strcmp (str, "hidden"))
614
    default_visibility = VISIBILITY_HIDDEN;  
615
  else if (!strcmp (str, "protected"))
616
    default_visibility = VISIBILITY_PROTECTED;
617
  else
618
    GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
619
  visibility_options.inpragma = 1;
620
}
621
622
/* Pop a level of the #pragma visibility stack.  */
623
624
void
625
pop_visibility (void)
626
{
627
  default_visibility = VEC_pop (visibility, visstack);
628
  visibility_options.inpragma
629
    = VEC_length (visibility, visstack) != 0;
630
}  
631
600
/* Sets the default visibility for symbols to something other than that
632
/* Sets the default visibility for symbols to something other than that
601
   specified on the command line.  */
633
   specified on the command line.  */
634
602
static void
635
static void
603
handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
636
handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
604
{
637
{
Lines 606-612 Link Here
606
  tree x;
639
  tree x;
607
  enum cpp_ttype token;
640
  enum cpp_ttype token;
608
  enum { bad, push, pop } action = bad;
641
  enum { bad, push, pop } action = bad;
609
  static VEC (visibility, heap) *visstack;
610
 
642
 
611
  token = pragma_lex (&x);
643
  token = pragma_lex (&x);
612
  if (token == CPP_NAME)
644
  if (token == CPP_NAME)
Lines 624-638 Link Here
624
      if (pop == action)
656
      if (pop == action)
625
        {
657
        {
626
          if (!VEC_length (visibility, visstack))
658
          if (!VEC_length (visibility, visstack))
627
            {
659
	    GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
628
              GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
629
            }
630
          else
660
          else
631
            {
661
	    pop_visibility ();
632
	      default_visibility = VEC_pop (visibility, visstack);
633
	      visibility_options.inpragma
634
		= VEC_length (visibility, visstack) != 0;
635
            }
636
        }
662
        }
637
      else
663
      else
638
        {
664
        {
(-)gcc/c-pragma.h (+2 lines)
Lines 75-80 Link Here
75
   visibility is not supported on the host OS platform the
75
   visibility is not supported on the host OS platform the
76
   statements are ignored.  */
76
   statements are ignored.  */
77
#define HANDLE_PRAGMA_VISIBILITY 1
77
#define HANDLE_PRAGMA_VISIBILITY 1
78
extern void push_visibility (const char *);
79
extern void pop_visibility (void);
78
80
79
extern void init_pragma (void);
81
extern void init_pragma (void);
80
82

Return to bug 146817