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/attribs.c (+8 lines)
Lines 250-255 Link Here
250
	    }
250
	    }
251
	}
251
	}
252
252
253
      if (TYPE_P (*anode)
254
	  && (flags & (int) ATTR_FLAG_TYPE_IN_PLACE)
255
	  && TYPE_SIZE (*anode) != NULL_TREE)
256
	{
257
	  warning (OPT_Wattributes, "type attributes ignored after type is already defined");
258
	  continue;
259
	}
260
253
      if (spec->handler != NULL)
261
      if (spec->handler != NULL)
254
	returned_attrs = chainon ((*spec->handler) (anode, name, args,
262
	returned_attrs = chainon ((*spec->handler) (anode, name, args,
255
						    flags, &no_add_attrs),
263
						    flags, &no_add_attrs),
(-)gcc/doc/extend.texi (-18 / +54 lines)
Lines 2335-2340 Link Here
2335
2335
2336
Not all ELF targets support this attribute.
2336
Not all ELF targets support this attribute.
2337
2337
2338
A C++ namespace declaration can also have the visibility attribute.
2339
This attribute applies only to the particular namespace body, not to
2340
other definitions of the same namespace; it is equivalent to using
2341
@samp{#pragma GCC visibility} before and after the namespace
2342
definition (@pxref{Visibility Pragmas}).
2343
2344
In C++, if a template argument has limited visibility, this
2345
restriction is implicitly propagated to the template instantiation.
2346
Otherwise, template instantiations and specializations default to the
2347
visibility of their template.
2348
2338
@item warn_unused_result
2349
@item warn_unused_result
2339
@cindex @code{warn_unused_result} attribute
2350
@cindex @code{warn_unused_result} attribute
2340
The @code{warn_unused_result} attribute causes a warning to be emitted
2351
The @code{warn_unused_result} attribute causes a warning to be emitted
Lines 2513-2522 Link Here
2513
An attribute specifier list may appear as part of a @code{struct},
2524
An attribute specifier list may appear as part of a @code{struct},
2514
@code{union} or @code{enum} specifier.  It may go either immediately
2525
@code{union} or @code{enum} specifier.  It may go either immediately
2515
after the @code{struct}, @code{union} or @code{enum} keyword, or after
2526
after the @code{struct}, @code{union} or @code{enum} keyword, or after
2516
the closing brace.  It is ignored if the content of the structure, union
2527
the closing brace.  The former syntax is preferred.
2517
or enumerated type is not defined in the specifier in which the
2518
attribute specifier list is used---that is, in usages such as
2519
@code{struct __attribute__((foo)) bar} with no following opening brace.
2520
Where attribute specifiers follow the closing brace, they are considered
2528
Where attribute specifiers follow the closing brace, they are considered
2521
to relate to the structure, union or enumerated type defined, not to any
2529
to relate to the structure, union or enumerated type defined, not to any
2522
enclosing declaration the type specifier appears in, and the type
2530
enclosing declaration the type specifier appears in, and the type
Lines 3180-3192 Link Here
3180
@cindex type attributes
3188
@cindex type attributes
3181
3189
3182
The keyword @code{__attribute__} allows you to specify special
3190
The keyword @code{__attribute__} allows you to specify special
3183
attributes of @code{struct} and @code{union} types when you define such
3191
attributes of @code{struct} and @code{union} types when you define
3184
types.  This keyword is followed by an attribute specification inside
3192
such types.  This keyword is followed by an attribute specification
3185
double parentheses.  Six attributes are currently defined for types:
3193
inside double parentheses.  Seven attributes are currently defined for
3186
@code{aligned}, @code{packed}, @code{transparent_union}, @code{unused},
3194
types: @code{aligned}, @code{packed}, @code{transparent_union},
3187
@code{deprecated} and @code{may_alias}.  Other attributes are defined for
3195
@code{unused}, @code{deprecated}, @code{visibility}, and
3188
functions (@pxref{Function Attributes}) and for variables
3196
@code{may_alias}.  Other attributes are defined for functions
3189
(@pxref{Variable Attributes}).
3197
(@pxref{Function Attributes}) and for variables (@pxref{Variable
3198
Attributes}).
3190
3199
3191
You may also specify any one of these attributes with @samp{__}
3200
You may also specify any one of these attributes with @samp{__}
3192
preceding and following its keyword.  This allows you to use these
3201
preceding and following its keyword.  This allows you to use these
Lines 3194-3207 Link Here
3194
macro of the same name.  For example, you may use @code{__aligned__}
3203
macro of the same name.  For example, you may use @code{__aligned__}
3195
instead of @code{aligned}.
3204
instead of @code{aligned}.
3196
3205
3197
You may specify the @code{aligned} and @code{transparent_union}
3206
You may specify type attributes either in a @code{typedef} declaration
3198
attributes either in a @code{typedef} declaration or just past the
3207
or in an enum, struct or union type declaration or definition.
3199
closing curly brace of a complete enum, struct or union type
3200
@emph{definition} and the @code{packed} attribute only past the closing
3201
brace of a definition.
3202
3208
3203
You may also specify attributes between the enum, struct or union
3209
For an enum, struct or union type, you may specify attributes either
3204
tag and the name of the type rather than after the closing brace.
3210
between the enum, struct or union tag and the name of the type, or
3211
just past the closing curly brace of the @emph{definition}.  The
3212
former syntax is preferred.
3205
3213
3206
@xref{Attribute Syntax}, for details of the exact syntax for using
3214
@xref{Attribute Syntax}, for details of the exact syntax for using
3207
attributes.
3215
attributes.
Lines 3450-3455 Link Here
3450
@option{-fstrict-aliasing}, which is on by default at @option{-O2} or
3458
@option{-fstrict-aliasing}, which is on by default at @option{-O2} or
3451
above in recent GCC versions.
3459
above in recent GCC versions.
3452
3460
3461
@item visibility
3462
3463
In C++, attribute visibility (@pxref{Function Attributes}) can also be
3464
applied to class, struct, union and enum types.  Unlike other type
3465
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.
3467
3453
@subsection ARM Type Attributes
3468
@subsection ARM Type Attributes
3454
3469
3455
On those ARM targets that support @code{dllimport} (such as Symbian
3470
On those ARM targets that support @code{dllimport} (such as Symbian
Lines 9226-9231 Link Here
9226
* Symbol-Renaming Pragmas::
9241
* Symbol-Renaming Pragmas::
9227
* Structure-Packing Pragmas::
9242
* Structure-Packing Pragmas::
9228
* Weak Pragmas::
9243
* Weak Pragmas::
9244
* Visibility Pragmas::
9229
@end menu
9245
@end menu
9230
9246
9231
@node ARM Pragmas
9247
@node ARM Pragmas
Lines 9466-9471 Link Here
9466
translation unit.
9482
translation unit.
9467
@end table
9483
@end table
9468
9484
9485
@node Visibility Pragmas
9486
@subsection Visibility Pragmas
9487
9488
@table @code
9489
@item #pragma GCC visibility push(@var{visibility})
9490
@itemx #pragma GCC visibility pop
9491
@cindex pragma, visibility
9492
9493
This pragma allows the user to set the visibility for multiple
9494
declarations without having to give each a visibility attribute
9495
@xref{Function Attributes}, for more information about visibility and
9496
the attribute syntax.
9497
9498
In C++, @samp{#pragma GCC visibility} affects only namespace-scope
9499
declarations.  Class members and template specializations are not
9500
affected; if you want to override the visibility for a particular
9501
member or instantiation, you must use an attribute.
9502
9503
@end table
9504
9469
@node Unnamed Fields
9505
@node Unnamed Fields
9470
@section Unnamed struct/union fields within structs/unions
9506
@section Unnamed struct/union fields within structs/unions
9471
@cindex struct
9507
@cindex struct
(-)gcc/doc/invoke.texi (-6 / +20 lines)
Lines 1585-1597 Link Here
1585
appear in the export table of a DSO and do not require a PLT indirection
1585
appear in the export table of a DSO and do not require a PLT indirection
1586
when used within the DSO@.  Enabling this option can have a dramatic effect
1586
when used within the DSO@.  Enabling this option can have a dramatic effect
1587
on load and link times of a DSO as it massively reduces the size of the
1587
on load and link times of a DSO as it massively reduces the size of the
1588
dynamic export table when the library makes heavy use of templates.  While
1588
dynamic export table when the library makes heavy use of templates.
1589
it can cause bloating through duplication of code within each DSO where
1590
it is used, often the wastage is less than the considerable space occupied
1591
by a long symbol name in the export table which is typical when using
1592
templates and namespaces.  For even more savings, combine with the
1593
@option{-fvisibility=hidden} switch.
1594
1589
1590
You may mark a method as having a visibility explicitly to negate the
1591
effect of the switch for that method.  For example, if you do want to
1592
compare pointers to a particular inline method, or the method has
1593
local static data, you might mark it as having default visibility.
1594
1595
@item -fno-weak
1595
@item -fno-weak
1596
@opindex fno-weak
1596
@opindex fno-weak
1597
Do not use weak symbol support, even if it is provided by the linker.
1597
Do not use weak symbol support, even if it is provided by the linker.
Lines 13157-13162 Link Here
13157
Note that due to ISO C++ specification requirements, operator new and
13157
Note that due to ISO C++ specification requirements, operator new and
13158
operator delete must always be of default visibility.
13158
operator delete must always be of default visibility.
13159
13159
13160
@samp{extern} declarations are not affected by @samp{-fvisibility}, so
13161
a lot of code can be recompiled with @samp{-fvisibility=hidden} with
13162
no modifications.  However, this means that calls to @samp{extern}
13163
functions with no explicit visibility will use the PLT, so it is more
13164
effective to use @samp{__attribute ((visibility))} and/or
13165
@samp{#pragma GCC visibility} to tell the compiler which @samp{extern}
13166
declarations should be treated as hidden.
13167
13168
Note that @samp{-fvisibility} does affect C++ vague linkage
13169
entities. This means that, for instance, an exception class that will
13170
be thrown between DSOs must be explicitly marked with default
13171
visibility so that the @samp{type_info} nodes will be unified between
13172
the DSOs.
13173
13160
An overview of these techniques, their benefits and how to use them
13174
An overview of these techniques, their benefits and how to use them
13161
is at @w{@uref{http://gcc.gnu.org/wiki/Visibility}}.
13175
is at @w{@uref{http://gcc.gnu.org/wiki/Visibility}}.
13162
13176
(-)gcc/flags.h (-3 / +4 lines)
Lines 58-72 Link Here
58
   debugging information.  */
58
   debugging information.  */
59
extern bool use_gnu_debug_info_extensions;
59
extern bool use_gnu_debug_info_extensions;
60
60
61
/* Enumerate visibility settings.  */
61
/* Enumerate visibility settings.  This is deliberately ordered from most
62
   to least visibility.  */
62
#ifndef SYMBOL_VISIBILITY_DEFINED
63
#ifndef SYMBOL_VISIBILITY_DEFINED
63
#define SYMBOL_VISIBILITY_DEFINED
64
#define SYMBOL_VISIBILITY_DEFINED
64
enum symbol_visibility
65
enum symbol_visibility
65
{
66
{
66
  VISIBILITY_DEFAULT,
67
  VISIBILITY_DEFAULT,
67
  VISIBILITY_INTERNAL,
68
  VISIBILITY_PROTECTED,
68
  VISIBILITY_HIDDEN,
69
  VISIBILITY_HIDDEN,
69
  VISIBILITY_PROTECTED
70
  VISIBILITY_INTERNAL
70
};
71
};
71
#endif
72
#endif
72
73
(-)gcc/tree.c (-8 lines)
Lines 3136-3149 Link Here
3136
  else if (code == FUNCTION_DECL)
3136
  else if (code == FUNCTION_DECL)
3137
    DECL_MODE (t) = FUNCTION_MODE;
3137
    DECL_MODE (t) = FUNCTION_MODE;
3138
3138
3139
  if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
3140
    {
3141
      /* Set default visibility to whatever the user supplied with
3142
	 visibility_specified depending on #pragma GCC visibility.  */
3143
      DECL_VISIBILITY (t) = default_visibility;
3144
      DECL_VISIBILITY_SPECIFIED (t) = visibility_options.inpragma;
3145
    }
3146
3147
  return t;
3139
  return t;
3148
}
3140
}
3149
3141
(-)gcc/tree.h (-3 / +3 lines)
Lines 1050-1056 Link Here
1050
   expressions.  */
1050
   expressions.  */
1051
#define TREE_OVERFLOW(NODE) ((NODE)->common.public_flag)
1051
#define TREE_OVERFLOW(NODE) ((NODE)->common.public_flag)
1052
1052
1053
/* In a VAR_DECL or FUNCTION_DECL,
1053
/* In a VAR_DECL, FUNCTION_DECL, NAMESPACE_DECL or TYPE_DECL,
1054
   nonzero means name is to be accessible from outside this module.
1054
   nonzero means name is to be accessible from outside this module.
1055
   In an IDENTIFIER_NODE, nonzero means an external declaration
1055
   In an IDENTIFIER_NODE, nonzero means an external declaration
1056
   accessible from outside this module was previously seen
1056
   accessible from outside this module was previously seen
Lines 2260-2268 Link Here
2260
enum symbol_visibility
2260
enum symbol_visibility
2261
{
2261
{
2262
  VISIBILITY_DEFAULT,
2262
  VISIBILITY_DEFAULT,
2263
  VISIBILITY_INTERNAL,
2263
  VISIBILITY_PROTECTED,
2264
  VISIBILITY_HIDDEN,
2264
  VISIBILITY_HIDDEN,
2265
  VISIBILITY_PROTECTED
2265
  VISIBILITY_INTERNAL
2266
};
2266
};
2267
#endif
2267
#endif
2268
2268
(-)gcc/testsuite/g++.old-deja/g++.pt/enum5.C (-2 / +2 lines)
Lines 1-4 Link Here
1
// { dg-do assemble  }
1
// { dg-do assemble  }
2
2
3
template <> // { dg-error "" } template declaration of enum
3
template <>
4
enum E {e};
4
enum E {e}; // { dg-error "" } template declaration of enum
(-)gcc/testsuite/g++.dg/ext/attrib9.C (-4 / +9 lines)
Lines 1-5 Link Here
1
class __attribute__((unused)) C;	//  { dg-warning "type attributes" }
1
class __attribute__((unused)) C;
2
struct __attribute__((unused)) S;	//  { dg-warning "type attributes" }
2
struct __attribute__((unused)) S;
3
union __attribute__((unused)) U;	//  { dg-warning "type attributes" }
3
union __attribute__((unused)) U;
4
enum e {};
4
enum e {};
5
enum __attribute__((unused)) e;		//  { dg-warning "type attributes" }
5
enum __attribute__((unused)) e;	// { dg-warning "already defined" }
6
7
struct __attribute((unused)) B *p;	//  { dg-warning "attributes" }
8
9
template <class T> struct A { };
10
struct __attribute((unused)) A<int>;	//  { dg-warning "attributes" }
(-)gcc/testsuite/g++.dg/ext/attrib14.C (-2 / +2 lines)
Lines 3-13 Link Here
3
// parsing of the class, causing some variants to have it and some not.
3
// parsing of the class, causing some variants to have it and some not.
4
4
5
struct __attribute__((bogus)) A
5
struct __attribute__((bogus)) A
6
{
6
{				// { dg-warning "ignored" "" }
7
    virtual ~A();
7
    virtual ~A();
8
    void foo(const A&);
8
    void foo(const A&);
9
    void bar(const A&);
9
    void bar(const A&);
10
};				// { dg-warning "ignored" "" }
10
};
11
11
12
void A::foo(const A&)   {}
12
void A::foo(const A&)   {}
13
void A::bar(const A& a) { foo(a); }
13
void A::bar(const A& a) { foo(a); }
(-)gcc/testsuite/g++.dg/ext/visibility/anon1.C (+10 lines)
Line 0 Link Here
1
// PR c++/21581
2
// Test for anonymous namespace internal linkage
3
4
// { dg-do compile }
5
// { dg-final { scan-assembler-not "globl.*_ZN.*1fEv" } }
6
7
namespace
8
{
9
  int f() { }
10
}
(-)gcc/testsuite/g++.dg/ext/visibility/anon2.C (+11 lines)
Line 0 Link Here
1
// Test for propagation of anonymous namespace internal linkage
2
3
// { dg-do compile }
4
// { dg-final { scan-assembler-not "globl.*_Z1fv" } }
5
6
namespace
7
{
8
  struct A { };
9
}
10
11
A f () { }
(-)gcc/testsuite/g++.dg/ext/visibility/redecl1.C (+7 lines)
Line 0 Link Here
1
// Test that we complain about redeclaration with different visibility
2
3
struct __attribute((visibility("hidden"))) B;
4
struct __attribute((visibility("default"))) B;	// { dg-warning "visibility" }
5
6
__attribute ((visibility ("hidden"))) void f();	// { dg-warning "previous" }
7
__attribute ((visibility ("default"))) void f(); // { dg-warning "visibility" }
(-)gcc/testsuite/g++.dg/ext/visibility/class1.C (+20 lines)
Line 0 Link Here
1
// PR c++/26905
2
// Init should not be hidden, so calling it should use the PLT.
3
4
// { dg-require-visibility "" }
5
// { dg-options "-fpic" }
6
// { dg-do compile { target i?86-*-* x86_64-*-* } }
7
// { dg-final { scan-assembler "InitEv@PLT" } }
8
9
#pragma GCC visibility push(hidden)
10
struct __attribute__ ((visibility ("default"))) nsINIParser
11
{
12
    static void Init();
13
};
14
15
__attribute__ ((visibility ("default")))
16
void
17
CheckCompatibility(void)
18
{
19
  nsINIParser::Init();
20
}
(-)gcc/testsuite/g++.dg/ext/visibility/template1.C (+35 lines)
Line 0 Link Here
1
// PR c++/19134
2
// -fvisibility-inlines-hidden doesn't apply to non-inline specializations
3
4
// { dg-require-visibility "" }
5
// { dg-options "-fvisibility-inlines-hidden" }
6
// { dg-final { scan-not-hidden "_ZN1AIiE3fooEv" } }
7
// { dg-final { scan-not-hidden "_ZN1AIiE3barEv" } }
8
// { dg-final { scan-hidden "_ZN1AIlE3fooEv" } }
9
// { dg-final { scan-hidden "_ZN1AIlE3barEv" } }
10
// { dg-final { scan-hidden "_ZN1AIcE3barEv" } }
11
12
template<class T>
13
struct A {
14
  void foo() {};
15
  __attribute ((visibility ("hidden"))) void bar();
16
};
17
18
// This has default visibility.
19
template<> void A<int>::foo() {}
20
21
// This has hidden visibility because of -fvisibility-inlines-hidden.
22
template<> inline void A<long>::foo() {}
23
// Force the inline out.
24
void f () { A<long> a; a.foo(); }
25
26
// This has default visibility.
27
template<> __attribute ((visibility ("default"))) void A<int>::bar() {}
28
29
// This inherits hidden visibility from its template.
30
template<> void A<long>::bar() { }
31
32
// This also has hidden visibility; #pragma vis doesn't affect class members.
33
#pragma GCC visibility push(default)
34
template<> void A<char>::bar() { }
35
#pragma GCC visibility pop
(-)gcc/testsuite/g++.dg/ext/visibility/fvisibility-override2.C (-1 / +1 lines)
Lines 6-12 Link Here
6
6
7
class Foo
7
class Foo
8
{
8
{
9
  __attribute__ ((visibility ("default"))) void method();
9
  __attribute__ ((visibility ("internal"))) void method();
10
};
10
};
11
11
12
void Foo::method() { }
12
void Foo::method() { }
(-)gcc/testsuite/g++.dg/ext/visibility/template2.C (+35 lines)
Line 0 Link Here
1
// PR c++/27000
2
// Implicitly instantiated templates should not be affected by
3
// #pragma visibility.
4
5
/* { dg-do compile } */
6
/* { dg-require-visibility "" } */
7
/* { dg-final { scan-not-hidden "_ZN1SIiED1Ev" } } */
8
/* { dg-final { scan-not-hidden "_ZN1SIiEC1ERKi" } } */
9
10
template <class T>
11
struct S
12
{
13
  S (const T &);
14
  ~S ();
15
  T t;
16
};
17
18
template <class T>
19
S<T>::S (const T &x)
20
{
21
  t = x;
22
}
23
24
template <class T>
25
S<T>::~S ()
26
{
27
}
28
29
#pragma GCC visibility push(hidden)
30
struct U
31
{
32
  S<int> s;
33
  U () : s (6) { }
34
} u;
35
#pragma GCC visibility pop
(-)gcc/testsuite/g++.dg/ext/visibility/template3.C (+22 lines)
Line 0 Link Here
1
// PR c++/17470
2
// Test that we can give visibility to explicit template instantiations
3
4
// { dg-require-visibility "" }
5
// { dg-final { scan-hidden "_ZN1AIlE1fEl" } }
6
// { dg-final { scan-hidden "_ZN1AIiE1fEi" } }
7
// { dg-final { scan-not-hidden "_ZN1AIcE1fEc" } }
8
// { dg-final { scan-hidden "_Z8identityIdET_S0_" } }
9
// { dg-final { scan-not-hidden "_Z8identityIiET_S0_" } }
10
11
template <class T> T identity(T t) { return t; }
12
template  __attribute__((visibility("hidden"))) double identity(double);
13
template int identity(int);
14
15
16
template <class T> struct A { void f (T); };
17
template <class T> void A<T>::f (T) { }
18
template struct __attribute ((visibility ("hidden"))) A<int>;
19
template<> struct  __attribute ((visibility ("hidden"))) A<long> { void f(long); };
20
// inherits hidden visibility from its class
21
void A<long>::f (long) { }
22
template struct A<char>;
(-)gcc/testsuite/g++.dg/ext/visibility/template4.C (+39 lines)
Line 0 Link Here
1
// Test for explicit visibility on template vs. #pragma vis at explicit
2
// instantiation/specialization point for plain function templates.
3
4
// { dg-require-visibility "" }
5
// { dg-final { scan-hidden "_Z3fooIdEvT_" } }
6
// { dg-final { scan-hidden "_Z3fooIlEvT_" } }
7
// { dg-final { scan-hidden "_Z3fooIcEvT_" } }
8
// { dg-final { scan-hidden "_Z3fooIiEvT_" } }
9
// { dg-final { scan-not-hidden "_Z3fooIfEvT_" } }
10
// { dg-final { scan-not-hidden "_Z3fooIsEvT_" } }
11
12
// { dg-final { scan-hidden "_Z3barIdEvT_" } }
13
// { dg-final { scan-hidden "_Z3barIlEvT_" } }
14
// { dg-final { scan-hidden "_Z3barIiEvT_" } }
15
// { dg-final { scan-hidden "_Z3barIcEvT_" } }
16
// { dg-final { scan-not-hidden "_Z3barIfEvT_" } }
17
// { dg-final { scan-not-hidden "_Z3barIsEvT_" } }
18
19
#pragma GCC visibility push(hidden)
20
template <class T> void bar(T) { }
21
#pragma GCC visibility pop
22
template void bar (long);
23
template<> void bar (double) { }
24
template __attribute ((visibility ("default"))) void bar (short);
25
template<> __attribute ((visibility ("default"))) void bar (float) { }
26
#pragma GCC visibility push(default)
27
template<> void bar(char) { }
28
template void bar(int);
29
#pragma GCC visibility pop
30
31
template <class T> __attribute ((visibility ("hidden"))) void foo(T) { }
32
template void foo (long);
33
template<> void foo (double) { }
34
template __attribute ((visibility ("default"))) void foo (short);
35
template<> __attribute ((visibility ("default"))) void foo (float) { }
36
#pragma GCC visibility push(default)
37
template<> void foo(char) { }
38
template void foo(int);
39
#pragma GCC visibility pop
(-)gcc/testsuite/g++.dg/ext/visibility/prop1.C (+23 lines)
Line 0 Link Here
1
// Test for propagation of visibility through template arguments
2
3
// { dg-do compile }
4
// { dg-require-visibility "" }
5
// { dg-final { scan-hidden "_Z1fIN1N1AEEvT_" } }
6
// { dg-final { scan-hidden "_Z1hIXadL_ZN1N1iEEEEvv" } }
7
8
namespace N __attribute ((__visibility__ ("hidden")))
9
{
10
  struct A { };
11
  int i;
12
}
13
14
template <class T> void f (T) { }
15
template <int *I> void h() { }
16
17
void g()
18
{
19
  N::A a;
20
  f(a);
21
  h<&N::i>();
22
}
23
(-)gcc/testsuite/g++.dg/ext/visibility/assign1.C (-3 / +4 lines)
Lines 6-16 Link Here
6
  B& operator=(const B&);
6
  B& operator=(const B&);
7
};
7
};
8
8
9
struct D : public B {
9
struct __attribute__((visibility("hidden"))) D : public B {
10
  // The implicit assignment operator should be hidden.
10
  // The implicit assignment operator should be hidden.
11
} __attribute__((visibility("hidden")));
11
};
12
12
13
D d1, d2;
13
__attribute__((visibility("hidden"))) D d1;
14
__attribute__((visibility("hidden"))) D d2;
14
15
15
void f() {
16
void f() {
16
  d1 = d2;
17
  d1 = d2;
(-)gcc/testsuite/g++.dg/ext/visibility/typeinfo1.C (+19 lines)
Line 0 Link Here
1
// PR c++/26984
2
// lazily generated typeinfos should not be affected by #pragma vis, but
3
// they should be affected by the visibility of the type they describe.
4
5
// { dg-require-visibility "" }
6
// { dg-options "-fvisibility-inlines-hidden" }
7
// { dg-final { scan-not-hidden "_ZTIPPi" } }
8
// { dg-final { scan-not-hidden "_ZTSPPi" } }
9
// { dg-final { scan-hidden "_ZTIP1A" } }
10
// { dg-final { scan-hidden "_ZTSP1A" } }
11
12
#include <typeinfo>
13
14
#pragma GCC visibility push(hidden)
15
const std::type_info* t = &(typeid(int **));
16
struct A { };
17
#pragma GCC visibility pop
18
19
const std::type_info* t2 = &(typeid(A *));
(-)gcc/testsuite/g++.dg/ext/visibility/virtual.C (-2 / +8 lines)
Lines 1-9 Link Here
1
/* Test that setting visibility for class affects virtual table. */
1
/* Test that setting visibility for class affects virtual table, VTT and
2
   type_info name and node. */
2
/* { dg-do compile } */
3
/* { dg-do compile } */
3
/* { dg-require-visibility "" } */
4
/* { dg-require-visibility "" } */
4
/* { dg-final { scan-hidden "ZTV3Foo" } } */
5
/* { dg-final { scan-hidden "ZTV3Foo" } } */
6
/* { dg-final { scan-hidden "ZTT3Foo" } } */
7
/* { dg-final { scan-hidden "ZTS3Foo" } } */
8
/* { dg-final { scan-hidden "ZTI3Foo" } } */
5
9
6
class __attribute__ ((visibility ("hidden"))) Foo
10
struct A { };
11
12
class __attribute__ ((visibility ("hidden"))) Foo: virtual public A
7
{
13
{
8
  virtual void method();
14
  virtual void method();
9
};
15
};
(-)gcc/testsuite/g++.dg/ext/visibility/warn1.C (+13 lines)
Line 0 Link Here
1
// Warn when a declaration is specified with greater visibility than that
2
// of its type.
3
4
// { dg-do compile }
5
// { dg-require-visibility "" }
6
// { dg-final { scan-hidden "_Z1fv" } }
7
8
namespace N __attribute ((__visibility__ ("hidden")))
9
{
10
  struct A { };
11
}
12
13
N::A f() { } // { dg-warning "visibility" "" }
(-)gcc/testsuite/g++.dg/ext/visibility/warn2.C (+19 lines)
Line 0 Link Here
1
// Complain when a class is specified with greater visibility than one of
2
// its members' types or bases, and when a declaration has greater
3
// visibility than its type.
4
5
// { dg-require-visibility "" }
6
7
namespace N __attribute ((__visibility__ ("hidden")))
8
{
9
  struct A { };
10
}
11
12
struct B
13
{				// { dg-warning "visibility" }
14
  N::A a;
15
};
16
17
B f () { }			// { dg-warning "visibility" }
18
19
struct C: public N::A { };	// { dg-warning "visibility" }
(-)gcc/testsuite/g++.dg/ext/visibility/warn3.C (+11 lines)
Line 0 Link Here
1
// Warn when a class member is specified to have greater visibility than
2
// its class.
3
4
// { dg-require-visibility "" }
5
6
struct __attribute ((visibility ("hidden"))) A
7
{
8
  __attribute ((visibility ("default"))) void f (); // { dg-warning "visibility" }
9
};
10
11
void A::f() { }
(-)gcc/testsuite/g++.dg/ext/visibility/warn4.C (+10 lines)
Line 0 Link Here
1
// Error if we try to give an instantiation visibility after it's already
2
// been instantiated.
3
4
// { dg-require-visibility "" }
5
6
template <class T> struct A { void f (T); };
7
template <class T> void A<T>::f (T) { }
8
9
A<double> ad;
10
template struct __attribute ((visibility ("hidden"))) A<double>; // { dg-error "already defined" }
(-)gcc/testsuite/g++.dg/template/anon2.C (+15 lines)
Line 0 Link Here
1
// PR c++/28279
2
// finish_static_data_member_decl was confused by the anonymous
3
// namespace causing TREE_PUBLIC to be unset
4
5
template<typename T>
6
struct is_pointer_impl {
7
    static const bool value = true;
8
};
9
10
namespace {
11
  class prefix_name_mapper {};
12
}
13
14
static const bool val = is_pointer_impl<prefix_name_mapper>::value;
15
(-)gcc/objcp/objcp-decl.c (-1 / +1 lines)
Lines 59-65 Link Here
59
  CLASSTYPE_DECLARED_CLASS (s) = 0;  /* this is a 'struct', not a 'class'.  */
59
  CLASSTYPE_DECLARED_CLASS (s) = 0;  /* this is a 'struct', not a 'class'.  */
60
  xref_basetypes (s, NULL_TREE);     /* no base classes here!  */
60
  xref_basetypes (s, NULL_TREE);     /* no base classes here!  */
61
61
62
  return begin_class_definition (s);
62
  return begin_class_definition (s, NULL_TREE);
63
}
63
}
64
64
65
tree 
65
tree 
(-)gcc/cp/class.c (+3 lines)
Lines 5047-5052 Link Here
5047
      DECL_SORTED_FIELDS (TYPE_MAIN_DECL (t)) = field_vec;
5047
      DECL_SORTED_FIELDS (TYPE_MAIN_DECL (t)) = field_vec;
5048
    }
5048
    }
5049
5049
5050
  /* Complain if one of the field types requires lower visibility.  */
5051
  constrain_class_visibility (t);
5052
5050
  /* Make the rtl for any new vtables we have created, and unmark
5053
  /* Make the rtl for any new vtables we have created, and unmark
5051
     the base types we marked.  */
5054
     the base types we marked.  */
5052
  finish_vtbls (t);
5055
  finish_vtbls (t);
(-)gcc/cp/decl.c (-4 / +9 lines)
Lines 1863-1868 Link Here
1863
1863
1864
	  SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
1864
	  SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
1865
1865
1866
	  /* Don't propagate visibility from the template to the
1867
	     specialization here.  We'll do that in determine_visibility if
1868
	     appropriate.  */
1869
	  DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
1870
1866
	  /* [temp.expl.spec/14] We don't inline explicit specialization
1871
	  /* [temp.expl.spec/14] We don't inline explicit specialization
1867
	     just because the primary template says so.  */
1872
	     just because the primary template says so.  */
1868
	}
1873
	}
Lines 3128-3133 Link Here
3128
  gcc_assert (global_namespace == NULL_TREE);
3133
  gcc_assert (global_namespace == NULL_TREE);
3129
  global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
3134
  global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
3130
				      void_type_node);
3135
				      void_type_node);
3136
  TREE_PUBLIC (global_namespace) = 1;
3131
  begin_scope (sk_namespace, global_namespace);
3137
  begin_scope (sk_namespace, global_namespace);
3132
3138
3133
  current_lang_name = NULL_TREE;
3139
  current_lang_name = NULL_TREE;
Lines 5281-5286 Link Here
5281
      else
5287
      else
5282
	abstract_virtuals_error (decl, type);
5288
	abstract_virtuals_error (decl, type);
5283
5289
5290
      /* This needs to happen after the linkage is set. */
5291
      determine_visibility (decl);
5292
5284
      if (TREE_CODE (decl) == FUNCTION_DECL
5293
      if (TREE_CODE (decl) == FUNCTION_DECL
5285
	  || TREE_TYPE (decl) == error_mark_node)
5294
	  || TREE_TYPE (decl) == error_mark_node)
5286
	/* No initialization required.  */
5295
	/* No initialization required.  */
Lines 5307-5316 Link Here
5307
		initialize_local_var (decl, init);
5316
		initialize_local_var (decl, init);
5308
	    }
5317
	    }
5309
5318
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
5314
	  /* If a variable is defined, and then a subsequent
5319
	  /* If a variable is defined, and then a subsequent
5315
	     definition with external linkage is encountered, we will
5320
	     definition with external linkage is encountered, we will
5316
	     get here twice for the same variable.  We want to avoid
5321
	     get here twice for the same variable.  We want to avoid
(-)gcc/cp/method.c (+3 lines)
Lines 163-168 Link Here
163
  DECL_DECLARED_INLINE_P (thunk) = 0;
163
  DECL_DECLARED_INLINE_P (thunk) = 0;
164
  /* Nor has it been deferred.  */
164
  /* Nor has it been deferred.  */
165
  DECL_DEFERRED_FN (thunk) = 0;
165
  DECL_DEFERRED_FN (thunk) = 0;
166
  /* Nor is it a template instantiation.  */
167
  DECL_USE_TEMPLATE (thunk) = 0;
168
  DECL_TEMPLATE_INFO (thunk) = NULL;
166
169
167
  /* Add it to the list of thunks associated with FUNCTION.  */
170
  /* Add it to the list of thunks associated with FUNCTION.  */
168
  TREE_CHAIN (thunk) = DECL_THUNKS (function);
171
  TREE_CHAIN (thunk) = DECL_THUNKS (function);
(-)gcc/cp/rtti.c (+4 lines)
Lines 1145-1150 Link Here
1145
  ti->name = get_identifier (real_name);
1145
  ti->name = get_identifier (real_name);
1146
  ti->vtable = NULL_TREE;
1146
  ti->vtable = NULL_TREE;
1147
1147
1148
  /* Pretend this is public so determine_visibility doesn't give vtables
1149
     internal linkage.  */
1150
  TREE_PUBLIC (TYPE_MAIN_DECL (ti->type)) = 1;
1151
1148
  va_end (ap);
1152
  va_end (ap);
1149
}
1153
}
1150
1154
(-)gcc/cp/tree.c (-1 / +26 lines)
Lines 1394-1399 Link Here
1394
    }
1394
    }
1395
}
1395
}
1396
1396
1397
/* Returns true if decl is within an anonymous namespace, however deeply
1398
   nested, or false otherwise.  */
1399
1400
bool
1401
decl_anon_ns_mem_p (tree decl)
1402
{
1403
  while (1)
1404
    {
1405
      if (decl == NULL_TREE)
1406
	return false;
1407
      if (TREE_CODE (decl) == NAMESPACE_DECL
1408
	  && DECL_NAME (decl) == NULL_TREE)
1409
	return true;
1410
      /* Classes and namespaces inside anonymous namespaces have
1411
         TREE_PUBLIC == 0, so we can shortcut the search.  */
1412
      else if (TYPE_P (decl))
1413
	return (TREE_PUBLIC (TYPE_NAME (decl)) == 0);
1414
      else if (TREE_CODE (decl) == NAMESPACE_DECL)
1415
	return (TREE_PUBLIC (decl) == 0);
1416
      else
1417
	decl = DECL_CONTEXT (decl);
1418
    }
1419
}
1420
1397
/* Return truthvalue of whether T1 is the same tree structure as T2.
1421
/* Return truthvalue of whether T1 is the same tree structure as T2.
1398
   Return 1 if they are the same. Return 0 if they are different.  */
1422
   Return 1 if they are the same. Return 0 if they are different.  */
1399
1423
Lines 2176-2182 Link Here
2176
     template instantiations have internal linkage (in the object
2200
     template instantiations have internal linkage (in the object
2177
     file), but the symbols should still be treated as having external
2201
     file), but the symbols should still be treated as having external
2178
     linkage from the point of view of the language.  */
2202
     linkage from the point of view of the language.  */
2179
  if (TREE_CODE (decl) != TYPE_DECL && DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl))
2203
  if (TREE_CODE (decl) != TYPE_DECL && DECL_LANG_SPECIFIC (decl)
2204
      && DECL_COMDAT (decl))
2180
    return lk_external;
2205
    return lk_external;
2181
2206
2182
  /* Things in local scope do not have linkage, if they don't have
2207
  /* Things in local scope do not have linkage, if they don't have
(-)gcc/cp/cp-tree.h (-1 / +4 lines)
Lines 3984-3989 Link Here
3984
extern tree coerce_delete_type			(tree);
3984
extern tree coerce_delete_type			(tree);
3985
extern void comdat_linkage			(tree);
3985
extern void comdat_linkage			(tree);
3986
extern void determine_visibility		(tree);
3986
extern void determine_visibility		(tree);
3987
extern void constrain_class_visibility		(tree);
3988
extern void update_member_visibility		(tree);
3987
extern void import_export_decl			(tree);
3989
extern void import_export_decl			(tree);
3988
extern tree build_cleanup			(tree);
3990
extern tree build_cleanup			(tree);
3989
extern tree build_offset_ref_call_from_tree	(tree, tree);
3991
extern tree build_offset_ref_call_from_tree	(tree, tree);
Lines 4299-4305 Link Here
4299
extern void finish_translation_unit		(void);
4301
extern void finish_translation_unit		(void);
4300
extern tree finish_template_type_parm		(tree, tree);
4302
extern tree finish_template_type_parm		(tree, tree);
4301
extern tree finish_template_template_parm       (tree, tree);
4303
extern tree finish_template_template_parm       (tree, tree);
4302
extern tree begin_class_definition		(tree);
4304
extern tree begin_class_definition		(tree, tree);
4303
extern void finish_template_decl		(tree);
4305
extern void finish_template_decl		(tree);
4304
extern tree finish_template_type		(tree, tree, int);
4306
extern tree finish_template_type		(tree, tree, int);
4305
extern tree finish_base_specifier		(tree, tree, bool);
4307
extern tree finish_base_specifier		(tree, tree, bool);
Lines 4381-4386 Link Here
4381
extern tree break_out_target_exprs		(tree);
4383
extern tree break_out_target_exprs		(tree);
4382
extern tree get_type_decl			(tree);
4384
extern tree get_type_decl			(tree);
4383
extern tree decl_namespace_context		(tree);
4385
extern tree decl_namespace_context		(tree);
4386
extern bool decl_anon_ns_mem_p			(tree);
4384
extern tree lvalue_type				(tree);
4387
extern tree lvalue_type				(tree);
4385
extern tree error_type				(tree);
4388
extern tree error_type				(tree);
4386
extern int varargs_function_p			(tree);
4389
extern int varargs_function_p			(tree);
(-)gcc/cp/pt.c (-10 / +20 lines)
Lines 2147-2159 Link Here
2147
	     template it specializes.  */
2147
	     template it specializes.  */
2148
	  TREE_PRIVATE (decl) = TREE_PRIVATE (gen_tmpl);
2148
	  TREE_PRIVATE (decl) = TREE_PRIVATE (gen_tmpl);
2149
	  TREE_PROTECTED (decl) = TREE_PROTECTED (gen_tmpl);
2149
	  TREE_PROTECTED (decl) = TREE_PROTECTED (gen_tmpl);
2150
	  /* The specialization has the same visibility as the
2150
2151
	     template it specializes.  */
2152
	  if (DECL_VISIBILITY_SPECIFIED (gen_tmpl))
2153
	    {
2154
	      DECL_VISIBILITY_SPECIFIED (decl) = 1;
2155
	      DECL_VISIBILITY (decl) = DECL_VISIBILITY (gen_tmpl);
2156
	    }
2157
	  /* If DECL is a friend declaration, declared using an
2151
	  /* If DECL is a friend declaration, declared using an
2158
	     unqualified name, the namespace associated with DECL may
2152
	     unqualified name, the namespace associated with DECL may
2159
	     have been set incorrectly.  For example, in:
2153
	     have been set incorrectly.  For example, in:
Lines 3605-3613 Link Here
3605
3599
3606
      if (!constant_address_p)
3600
      if (!constant_address_p)
3607
	{
3601
	{
3608
	    error ("%qE is not a valid template argument for type %qT "
3602
	  error ("%qE is not a valid template argument for type %qT "
3609
		  "because it is not a constant pointer", expr, type);
3603
		 "because it is not a constant pointer", expr, type);
3610
	    return NULL_TREE;
3604
	  return NULL_TREE;
3611
	}
3605
	}
3612
    }
3606
    }
3613
  /* [temp.arg.nontype]/5, bullet 3
3607
  /* [temp.arg.nontype]/5, bullet 3
Lines 4793-4798 Link Here
4793
	   code that generates debugging information will crash.  */
4787
	   code that generates debugging information will crash.  */
4794
	DECL_IGNORED_P (TYPE_STUB_DECL (t)) = 1;
4788
	DECL_IGNORED_P (TYPE_STUB_DECL (t)) = 1;
4795
4789
4790
      /* Possibly limit visibility based on template args.  */
4791
      TREE_PUBLIC (type_decl) = 1;
4792
      determine_visibility (type_decl);
4793
4796
      POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
4794
      POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
4797
    }
4795
    }
4798
  timevar_pop (TV_NAME_LOOKUP);
4796
  timevar_pop (TV_NAME_LOOKUP);
Lines 6608-6613 Link Here
6608
	  SET_DECL_FRIEND_CONTEXT (r,
6606
	  SET_DECL_FRIEND_CONTEXT (r,
6609
				   tsubst (DECL_FRIEND_CONTEXT (t),
6607
				   tsubst (DECL_FRIEND_CONTEXT (t),
6610
					    args, complain, in_decl));
6608
					    args, complain, in_decl));
6609
6610
	/* Possibly limit visibility based on template args.  */
6611
	DECL_VISIBILITY (r) = VISIBILITY_DEFAULT;
6612
	DECL_VISIBILITY_SPECIFIED (r) = 0;
6613
	determine_visibility (r);
6611
      }
6614
      }
6612
      break;
6615
      break;
6613
6616
Lines 6804-6809 Link Here
6804
	if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL))
6807
	if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL))
6805
	  SET_DECL_RTL (r, NULL_RTX);
6808
	  SET_DECL_RTL (r, NULL_RTX);
6806
	DECL_SIZE (r) = DECL_SIZE_UNIT (r) = 0;
6809
	DECL_SIZE (r) = DECL_SIZE_UNIT (r) = 0;
6810
	if (TREE_CODE (r) == VAR_DECL)
6811
	  {
6812
	    /* Possibly limit visibility based on template args.  */
6813
	    DECL_VISIBILITY (r) = VISIBILITY_DEFAULT;
6814
	    DECL_VISIBILITY_SPECIFIED (r) = 0;
6815
	    determine_visibility (r);
6816
	  }
6807
6817
6808
	if (!local_p)
6818
	if (!local_p)
6809
	  {
6819
	  {
(-)gcc/cp/semantics.c (-1 / +4 lines)
Lines 2151-2157 Link Here
2151
/* Begin a class definition, as indicated by T.  */
2151
/* Begin a class definition, as indicated by T.  */
2152
2152
2153
tree
2153
tree
2154
begin_class_definition (tree t)
2154
begin_class_definition (tree t, tree attributes)
2155
{
2155
{
2156
  if (t == error_mark_node)
2156
  if (t == error_mark_node)
2157
    return error_mark_node;
2157
    return error_mark_node;
Lines 2190-2195 Link Here
2190
  maybe_process_partial_specialization (t);
2190
  maybe_process_partial_specialization (t);
2191
  pushclass (t);
2191
  pushclass (t);
2192
  TYPE_BEING_DEFINED (t) = 1;
2192
  TYPE_BEING_DEFINED (t) = 1;
2193
2194
  cplus_decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
2195
2193
  if (flag_pack_struct)
2196
  if (flag_pack_struct)
2194
    {
2197
    {
2195
      tree v;
2198
      tree v;
(-)gcc/cp/name-lookup.c (-1 / +10 lines)
Lines 3032-3038 Link Here
3032
      /* Make a new namespace, binding the name to it.  */
3032
      /* Make a new namespace, binding the name to it.  */
3033
      d = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
3033
      d = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
3034
      DECL_CONTEXT (d) = FROB_CONTEXT (current_namespace);
3034
      DECL_CONTEXT (d) = FROB_CONTEXT (current_namespace);
3035
      TREE_PUBLIC (d) = 1;
3035
      /* The name of this namespace is not visible to other translation
3036
	 units if it is an anonymous namespace or member thereof.  */
3037
      if (anon || decl_anon_ns_mem_p (current_namespace))
3038
	TREE_PUBLIC (d) = 0;
3039
      else
3040
	TREE_PUBLIC (d) = 1;
3036
      pushdecl (d);
3041
      pushdecl (d);
3037
      if (anon)
3042
      if (anon)
3038
	{
3043
	{
Lines 4972-4977 Link Here
4972
  gcc_assert (TREE_CODE (decl) == TYPE_DECL);
4977
  gcc_assert (TREE_CODE (decl) == TYPE_DECL);
4973
  TYPE_STUB_DECL (type) = decl;
4978
  TYPE_STUB_DECL (type) = decl;
4974
4979
4980
  /* Set type visibility now if this is a forward declaration.  */
4981
  TREE_PUBLIC (decl) = 1;
4982
  determine_visibility (decl);
4983
4975
  POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, type);
4984
  POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, type);
4976
}
4985
}
4977
4986
(-)gcc/cp/decl2.c (-65 / +257 lines)
Lines 754-761 Link Here
754
				tree asmspec_tree,
754
				tree asmspec_tree,
755
				int flags)
755
				int flags)
756
{
756
{
757
  gcc_assert (TREE_PUBLIC (decl));
758
759
  DECL_CONTEXT (decl) = current_class_type;
757
  DECL_CONTEXT (decl) = current_class_type;
760
758
761
  /* We cannot call pushdecl here, because that would fill in the
759
  /* We cannot call pushdecl here, because that would fill in the
Lines 765-771 Link Here
765
  if (!asmspec_tree && current_class_type)
763
  if (!asmspec_tree && current_class_type)
766
    DECL_INITIAL (decl) = error_mark_node;
764
    DECL_INITIAL (decl) = error_mark_node;
767
765
768
  if (! processing_template_decl)
766
  if (! processing_template_decl && TREE_PUBLIC (decl))
769
    note_vague_linkage_var (decl);
767
    note_vague_linkage_var (decl);
770
768
771
  if (LOCAL_CLASS_P (current_class_type))
769
  if (LOCAL_CLASS_P (current_class_type))
Lines 1578-1583 Link Here
1578
  return true;
1576
  return true;
1579
}
1577
}
1580
1578
1579
/* A special return value from type_visibility meaning internal
1580
   linkage.  */
1581
1582
enum { VISIBILITY_STATIC = VISIBILITY_INTERNAL+1 };
1583
1584
/* walk_tree helper function for type_visibility.  */
1585
1586
static tree
1587
min_vis_r (tree *tp, int *walk_subtrees, void *data)
1588
{
1589
  int *vis_p = (int *)data;
1590
  if (! TYPE_P (*tp))
1591
    {
1592
      *walk_subtrees = 0;
1593
    }
1594
  else if (CLASS_TYPE_P (*tp))
1595
    {
1596
      if (!TREE_PUBLIC (TYPE_MAIN_DECL (*tp)))
1597
	{
1598
	  *vis_p = VISIBILITY_STATIC;
1599
	  return *tp;
1600
	}
1601
      else if (CLASSTYPE_VISIBILITY (*tp) > *vis_p)
1602
	*vis_p = CLASSTYPE_VISIBILITY (*tp);
1603
    }
1604
  return NULL;
1605
}
1606
1607
/* Returns the visibility of TYPE, which is the minimum visibility of its
1608
   component types.  */
1609
1610
static int
1611
type_visibility (tree type)
1612
{
1613
  int vis = VISIBILITY_DEFAULT;
1614
  walk_tree_without_duplicates (&type, min_vis_r, &vis);
1615
  return vis;
1616
}
1617
1618
/* Limit the visibility of DECL to VISIBILITY.  SPECIFIED is true if the
1619
   constraint comes from an attribute or pragma; REASON is the source of
1620
   the constraint.  */
1621
1622
static bool
1623
constrain_visibility (tree decl, int visibility, bool specified,
1624
		      const char *reason)
1625
{
1626
  if (visibility == VISIBILITY_STATIC)
1627
    {
1628
      TREE_PUBLIC (decl) = 0;
1629
      DECL_INTERFACE_KNOWN (decl) = 1;
1630
      if (DECL_LANG_SPECIFIC (decl))
1631
	DECL_NOT_REALLY_EXTERN (decl) = 1;
1632
    }
1633
  else if (visibility > DECL_VISIBILITY (decl))
1634
    {
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;
1639
      if (!DECL_VISIBILITY_SPECIFIED (decl))
1640
	DECL_VISIBILITY_SPECIFIED (decl) = specified;
1641
      return true;
1642
    }
1643
  return false;
1644
}
1645
1646
/* Constrain the visibility of DECL based on the visbility of its template
1647
   arguments.  */
1648
1649
static void
1650
constrain_visibility_for_template (tree decl, tree targs)
1651
{
1652
  /* If this is a template instantiation, check the innermost
1653
     template args for visibility constraints.  The outer template
1654
     args are covered by the class check.  */
1655
  tree args = INNERMOST_TEMPLATE_ARGS (targs);
1656
  int i;
1657
  for (i = TREE_VEC_LENGTH (args); i > 0; --i)
1658
    {
1659
      int vis = 0;
1660
1661
      tree arg = TREE_VEC_ELT (args, i-1);
1662
      if (TYPE_P (arg))
1663
	vis = type_visibility (arg);
1664
      else if (TREE_TYPE (arg) && POINTER_TYPE_P (TREE_TYPE (arg)))
1665
	{
1666
	  STRIP_NOPS (arg);
1667
	  if (TREE_CODE (arg) == ADDR_EXPR)
1668
	    arg = TREE_OPERAND (arg, 0);
1669
	  if (TREE_CODE (arg) == VAR_DECL
1670
	      || TREE_CODE (arg) == FUNCTION_DECL)
1671
	    {
1672
	      if (! TREE_PUBLIC (arg))
1673
		vis = VISIBILITY_STATIC;
1674
	      else
1675
		vis = DECL_VISIBILITY (arg);
1676
	    }
1677
	}
1678
      if (vis)
1679
	constrain_visibility (decl, vis, false, "template parameter");
1680
    }
1681
}
1682
1581
/* Like c_determine_visibility, but with additional C++-specific
1683
/* Like c_determine_visibility, but with additional C++-specific
1582
   behavior.
1684
   behavior.
1583
1685
Lines 1589-1601 Link Here
1589
1691
1590
   Note that because namespaces have multiple independent definitions,
1692
   Note that because namespaces have multiple independent definitions,
1591
   namespace visibility is handled elsewhere using the #pragma visibility
1693
   namespace visibility is handled elsewhere using the #pragma visibility
1592
   machinery rather than by decorating the namespace declaration.  */
1694
   machinery rather than by decorating the namespace declaration.
1593
1695
1696
   The goal is for constraints from the type to give a diagnostic, and
1697
   other constraints to be applied silently.  */
1698
1594
void
1699
void
1595
determine_visibility (tree decl)
1700
determine_visibility (tree decl)
1596
{
1701
{
1597
  tree class_type;
1702
  tree class_type = NULL_TREE;
1703
  bool use_template;
1598
1704
1705
  /* Remember that all decls get VISIBILITY_DEFAULT when built.  */
1706
1599
  /* Only relevant for names with external linkage.  */
1707
  /* Only relevant for names with external linkage.  */
1600
  if (!TREE_PUBLIC (decl))
1708
  if (!TREE_PUBLIC (decl))
1601
    return;
1709
    return;
Lines 1605-1614 Link Here
1605
     maybe_clone_body.  */
1713
     maybe_clone_body.  */
1606
  gcc_assert (!DECL_CLONED_FUNCTION_P (decl));
1714
  gcc_assert (!DECL_CLONED_FUNCTION_P (decl));
1607
1715
1608
  /* Give the common code a chance to make a determination.  */
1716
  if (TREE_CODE (decl) == TYPE_DECL)
1609
  if (c_determine_visibility (decl))
1717
    {
1610
    return;
1718
      if (CLASS_TYPE_P (TREE_TYPE (decl)))
1719
	use_template = CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl));
1720
      else if (TYPE_TEMPLATE_INFO (TREE_TYPE (decl)))
1721
	use_template = 1;
1722
      else
1723
	use_template = 0;
1724
    }
1725
  else if (DECL_LANG_SPECIFIC (decl))
1726
    use_template = DECL_USE_TEMPLATE (decl);
1727
  else
1728
    use_template = 0;
1611
1729
1730
  /* Anything that is exported must have default visibility.  */
1731
  if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
1732
      && lookup_attribute ("dllexport",
1733
			   TREE_CODE (decl) == TYPE_DECL
1734
			   ? TYPE_ATTRIBUTES (TREE_TYPE (decl))
1735
			   : DECL_ATTRIBUTES (decl)))
1736
    {
1737
      DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
1738
      DECL_VISIBILITY_SPECIFIED (decl) = 1;
1739
    }
1740
1612
  /* If DECL is a member of a class, visibility specifiers on the
1741
  /* If DECL is a member of a class, visibility specifiers on the
1613
     class can influence the visibility of the DECL.  */
1742
     class can influence the visibility of the DECL.  */
1614
  if (DECL_CLASS_SCOPE_P (decl))
1743
  if (DECL_CLASS_SCOPE_P (decl))
Lines 1619-1624 Link Here
1619
    class_type = TREE_TYPE (DECL_NAME (decl));
1748
    class_type = TREE_TYPE (DECL_NAME (decl));
1620
  else
1749
  else
1621
    {
1750
    {
1751
      /* Not a class member.  */
1752
1622
      /* Virtual tables have DECL_CONTEXT set to their associated class,
1753
      /* Virtual tables have DECL_CONTEXT set to their associated class,
1623
	 so they are automatically handled above.  */
1754
	 so they are automatically handled above.  */
1624
      gcc_assert (TREE_CODE (decl) != VAR_DECL
1755
      gcc_assert (TREE_CODE (decl) != VAR_DECL
Lines 1626-1704 Link Here
1626
1757
1627
      if (DECL_FUNCTION_SCOPE_P (decl))
1758
      if (DECL_FUNCTION_SCOPE_P (decl))
1628
	{
1759
	{
1760
	  /* Local statics and classes get the visibility of their
1761
	     containing function.  */
1629
	  tree fn = DECL_CONTEXT (decl);
1762
	  tree fn = DECL_CONTEXT (decl);
1630
	  DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn);
1763
	  DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn);
1631
	  DECL_VISIBILITY_SPECIFIED (decl) = DECL_VISIBILITY_SPECIFIED (fn);
1764
	  DECL_VISIBILITY_SPECIFIED (decl) = DECL_VISIBILITY_SPECIFIED (fn);
1765
1766
	  /* Local classes in templates have CLASSTYPE_USE_TEMPLATE set,
1767
	     but have no TEMPLATE_INFO, so don't try to check it.  */
1768
	  use_template = 0;
1632
	}
1769
	}
1770
      else if (TREE_CODE (decl) == VAR_DECL && DECL_TINFO_P (decl))
1771
	{
1772
	  /* tinfo visibility is based on the type it's for.  */
1773
	  constrain_visibility
1774
	    (decl, type_visibility (TREE_TYPE (DECL_NAME (decl))),
1775
	     false, "type");
1776
	}
1777
      else if (use_template)
1778
	/* Template instantiations and specializations get visibility based
1779
	   on their template unless they override it with an attribute.  */;
1780
      else if (! DECL_VISIBILITY_SPECIFIED (decl))
1781
	{
1782
	  /* Set default visibility to whatever the user supplied with
1783
	     #pragma GCC visibility or a namespace visibility attribute.  */
1784
	  DECL_VISIBILITY (decl) = default_visibility;
1785
	  DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma;
1786
	}
1787
    }
1633
1788
1634
      /* Entities not associated with any class just get the
1789
  if (use_template)
1635
	 visibility specified by their attributes.  */
1790
    {
1636
      return;
1791
      tree tinfo = (TREE_CODE (decl) == TYPE_DECL
1792
		    ? TYPE_TEMPLATE_INFO (TREE_TYPE (decl))
1793
		    : DECL_TEMPLATE_INFO (decl));
1794
      tree args = TI_ARGS (tinfo);
1795
      int depth = TMPL_ARGS_DEPTH (args);
1796
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))
1800
	{
1801
	  tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo));
1802
	  DECL_VISIBILITY (decl) = DECL_VISIBILITY (pattern);
1803
	}
1804
1805
      /* FIXME should TMPL_ARGS_DEPTH really return 1 for null input? */
1806
      if (args && depth > template_class_depth (class_type))
1807
	/* Don't let it have more visibility than its template type
1808
	   arguments.  */
1809
	constrain_visibility_for_template (decl, args);
1637
    }
1810
    }
1638
1811
1639
  /* By default, static data members and function members receive
1640
     the visibility of their containing class.  */
1641
  if (class_type)
1812
  if (class_type)
1642
    {
1813
    determine_visibility_from_class (decl, class_type);
1643
      determine_visibility_from_class (decl, class_type);
1644
1814
1645
      /* Give the target a chance to override the visibility associated
1815
  /* Don't let it have more visibility than its type.  */
1646
	 with DECL.  */
1816
  if (TREE_CODE (decl) != TYPE_DECL)
1647
      if (TREE_CODE (decl) == VAR_DECL
1817
    if (constrain_visibility (decl, type_visibility (TREE_TYPE (decl)),
1648
	  && (DECL_TINFO_P (decl)
1818
			      false, "type"))
1649
	      || (DECL_VTABLE_OR_VTT_P (decl)
1819
      warning (OPT_Wattributes, "\
1650
		  /* Construction virtual tables are not exported because
1820
%q+D declared with greater visibility than its type",
1651
		     they cannot be referred to from other object files;
1821
	       decl);
1652
		     their name is not standardized by the ABI.  */
1822
1653
		  && !DECL_CONSTRUCTION_VTABLE_P (decl)))
1823
  if (decl_anon_ns_mem_p (decl))
1654
	  && TREE_PUBLIC (decl)
1824
    /* Names in an anonymous namespace get internal linkage.
1655
	  && !DECL_REALLY_EXTERN (decl)
1825
       This might change once we implement export.  */
1656
	  && DECL_VISIBILITY_SPECIFIED (decl)
1826
    constrain_visibility (decl, VISIBILITY_STATIC,
1657
	  && (!class_type || !CLASSTYPE_VISIBILITY_SPECIFIED (class_type)))
1827
			  false, "namespace");
1658
	targetm.cxx.determine_class_data_visibility (decl);
1659
    }      
1660
}
1828
}
1661
1829
1830
/* By default, static data members and function members receive
1831
   the visibility of their containing class.  */
1832
1662
static void
1833
static void
1663
determine_visibility_from_class (tree decl, tree class_type)
1834
determine_visibility_from_class (tree decl, tree class_type)
1664
{
1835
{
1665
  if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
1836
  if (visibility_options.inlines_hidden
1666
      && lookup_attribute ("dllexport", TYPE_ATTRIBUTES (class_type)))
1837
      /* Don't do this for inline templates; specializations might not be
1667
    {
1838
	 inline, and we don't want them to inherit the hidden
1668
      DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
1839
	 visibility.  We'll set it here for all inline instantiations.  */
1669
      DECL_VISIBILITY_SPECIFIED (decl) = 1;
1840
      && !processing_template_decl
1670
    }
1841
      && ! DECL_VISIBILITY_SPECIFIED (decl)
1671
  else if (TREE_CODE (decl) == FUNCTION_DECL
1842
      && TREE_CODE (decl) == FUNCTION_DECL
1672
	   && DECL_DECLARED_INLINE_P (decl)
1843
      && DECL_DECLARED_INLINE_P (decl))
1673
	   && visibility_options.inlines_hidden)
1844
    DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1674
    {
1845
1675
      /* Don't change it if it has been set explicitly by user.  */
1846
  /* The decl can't have more visibility than its class.  */
1676
      if (!DECL_VISIBILITY_SPECIFIED (decl))
1847
  constrain_visibility (decl, CLASSTYPE_VISIBILITY (class_type),
1677
	{
1848
			CLASSTYPE_VISIBILITY_SPECIFIED (class_type),
1678
	  DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1849
			"class");
1679
	  DECL_VISIBILITY_SPECIFIED (decl) = 1;
1850
1680
	}
1851
  /* Give the target a chance to override the visibility associated
1681
    }
1852
     with DECL.  */
1682
  else if (CLASSTYPE_VISIBILITY_SPECIFIED (class_type))
1853
  if (TREE_CODE (decl) == VAR_DECL
1683
    {
1854
      && (DECL_TINFO_P (decl)
1684
      DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type);
1855
	  || (DECL_VTABLE_OR_VTT_P (decl)
1685
      DECL_VISIBILITY_SPECIFIED (decl) = 1;
1856
	      /* Construction virtual tables are not exported because
1686
    }
1857
		 they cannot be referred to from other object files;
1687
  else if (TYPE_CLASS_SCOPE_P (class_type))
1858
		 their name is not standardized by the ABI.  */
1688
    determine_visibility_from_class (decl, TYPE_CONTEXT (class_type));
1859
	      && !DECL_CONSTRUCTION_VTABLE_P (decl)))
1689
  else if (TYPE_FUNCTION_SCOPE_P (class_type))
1860
      && TREE_PUBLIC (decl)
1690
    {
1861
      && !DECL_REALLY_EXTERN (decl)
1691
      tree fn = TYPE_CONTEXT (class_type);
1862
      && DECL_VISIBILITY_SPECIFIED (decl)
1692
      DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn);
1863
      && (!class_type || !CLASSTYPE_VISIBILITY_SPECIFIED (class_type)))
1693
      DECL_VISIBILITY_SPECIFIED (decl) = DECL_VISIBILITY_SPECIFIED (fn);
1864
    targetm.cxx.determine_class_data_visibility (decl);
1694
    }
1695
  else if (!DECL_VISIBILITY_SPECIFIED (decl))
1696
    {
1697
      DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type);
1698
      DECL_VISIBILITY_SPECIFIED (decl) = 0;
1699
    }
1700
}
1865
}
1701
1866
1867
/* Constrain the visibility of a class TYPE based on the visibility of its
1868
   field types.  Warn if any fields require lesser visibility.  */
1869
1870
void
1871
constrain_class_visibility (tree type)
1872
{
1873
  tree decl = TYPE_MAIN_DECL (type);
1874
  tree binfo = TYPE_BINFO (type);
1875
  tree t;
1876
  int i;
1877
1878
  for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
1879
    if (TREE_CODE (t) == FIELD_DECL)
1880
      if (constrain_visibility (decl, type_visibility (TREE_TYPE (t)),
1881
				false, "field type"))
1882
	warning (OPT_Wattributes, "\
1883
%qT declared with greater visibility than the type of its field %qD",
1884
		 type, t);
1885
1886
  for (i = 0; BINFO_BASE_ITERATE (binfo, i, t); ++i)
1887
    if (constrain_visibility (decl, type_visibility (TREE_TYPE (t)),
1888
			      false, "base type"))
1889
      warning (OPT_Wattributes, "\
1890
%qT declared with greater visibility than its base %qT",
1891
	       type, TREE_TYPE (t));
1892
}
1893
1702
/* DECL is a FUNCTION_DECL or VAR_DECL.  If the object file linkage
1894
/* DECL is a FUNCTION_DECL or VAR_DECL.  If the object file linkage
1703
   for DECL has not already been determined, do so now by setting
1895
   for DECL has not already been determined, do so now by setting
1704
   DECL_EXTERNAL, DECL_COMDAT and other related flags.  Until this
1896
   DECL_EXTERNAL, DECL_COMDAT and other related flags.  Until this
(-)gcc/cp/parser.c (-29 / +47 lines)
Lines 9411-9417 Link Here
9411
      if (declarator != cp_error_declarator)
9411
      if (declarator != cp_error_declarator)
9412
	{
9412
	{
9413
	  decl = grokdeclarator (declarator, &decl_specifiers,
9413
	  decl = grokdeclarator (declarator, &decl_specifiers,
9414
				 NORMAL, 0, NULL);
9414
				 NORMAL, 0, &decl_specifiers.attributes);
9415
	  /* Turn access control back on for names used during
9415
	  /* Turn access control back on for names used during
9416
	     template instantiation.  */
9416
	     template instantiation.  */
9417
	  pop_deferring_access_checks ();
9417
	  pop_deferring_access_checks ();
Lines 9560-9581 Link Here
9560
  switch (keyword)
9560
  switch (keyword)
9561
    {
9561
    {
9562
    case RID_ENUM:
9562
    case RID_ENUM:
9563
      /* 'enum' [identifier] '{' introduces an enum-specifier;
9563
      /* Look for the enum-specifier.  */
9564
	 'enum' <anything else> introduces an elaborated-type-specifier.  */
9564
      type_spec = cp_parser_enum_specifier (parser);
9565
      if (cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_OPEN_BRACE
9565
      /* If that worked, we're done.  */
9566
	  || (cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_NAME
9566
      if (type_spec)
9567
	      && cp_lexer_peek_nth_token (parser->lexer, 3)->type
9568
		 == CPP_OPEN_BRACE))
9569
	{
9567
	{
9570
	  if (parser->num_template_parameter_lists)
9571
	    {
9572
	      error ("template declaration of %qs", "enum");
9573
	      cp_parser_skip_to_end_of_block_or_statement (parser);
9574
	      type_spec = error_mark_node;
9575
	    }
9576
	  else
9577
	    type_spec = cp_parser_enum_specifier (parser);
9578
9579
	  if (declares_class_or_enum)
9568
	  if (declares_class_or_enum)
9580
	    *declares_class_or_enum = 2;
9569
	    *declares_class_or_enum = 2;
9581
	  if (decl_specs)
9570
	  if (decl_specs)
Lines 10077-10082 Link Here
10077
					 /*type_p=*/true,
10066
					 /*type_p=*/true,
10078
					 is_declaration);
10067
					 is_declaration);
10079
  /* For everything but enumeration types, consider a template-id.  */
10068
  /* For everything but enumeration types, consider a template-id.  */
10069
  /* For an enumeration type, consider only a plain identifier.  */
10080
  if (tag_type != enum_type)
10070
  if (tag_type != enum_type)
10081
    {
10071
    {
10082
      bool template_p = false;
10072
      bool template_p = false;
Lines 10108-10114 Link Here
10108
	type = TREE_TYPE (decl);
10098
	type = TREE_TYPE (decl);
10109
    }
10099
    }
10110
10100
10111
  /* For an enumeration type, consider only a plain identifier.  */
10112
  if (!type)
10101
  if (!type)
10113
    {
10102
    {
10114
      identifier = cp_parser_identifier (parser);
10103
      identifier = cp_parser_identifier (parser);
Lines 10236-10246 Link Here
10236
	  else
10225
	  else
10237
	    ts = ts_global;
10226
	    ts = ts_global;
10238
10227
10239
	  /* Warn about attributes. They are ignored.  */
10240
	  if (attributes)
10241
	    warning (OPT_Wattributes,
10242
		     "type attributes are honored only at type definition");
10243
10244
	  template_p = 
10228
	  template_p = 
10245
	    (parser->num_template_parameter_lists
10229
	    (parser->num_template_parameter_lists
10246
	     && (cp_parser_next_token_starts_class_definition_p (parser)
10230
	     && (cp_parser_next_token_starts_class_definition_p (parser)
Lines 10253-10258 Link Here
10253
	  type = xref_tag (tag_type, identifier, ts, template_p);
10237
	  type = xref_tag (tag_type, identifier, ts, template_p);
10254
	}
10238
	}
10255
    }
10239
    }
10240
10241
  /* Allow attributes on forward declarations of classes.  */
10242
  if (attributes)
10243
    {
10244
      if (tag_type != enum_type && CLASSTYPE_TEMPLATE_INSTANTIATION (type)
10245
	  && ! processing_explicit_instantiation)
10246
	warning (OPT_Wattributes,
10247
		 "attributes ignored on template instantiation");
10248
      else if (is_declaration && cp_parser_declares_only_class_p (parser))
10249
	cplus_decl_attributes (&type, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
10250
      else
10251
	warning (OPT_Wattributes,
10252
		 "attributes ignored on elaborated-type-specifier that is not a forward declaration");
10253
    }
10254
10256
  if (tag_type != enum_type)
10255
  if (tag_type != enum_type)
10257
    cp_parser_check_class_key (tag_type, type);
10256
    cp_parser_check_class_key (tag_type, type);
10258
10257
Lines 10269-10295 Link Here
10269
     enum identifier [opt] { enumerator-list [opt] }
10268
     enum identifier [opt] { enumerator-list [opt] }
10270
10269
10271
   GNU Extensions:
10270
   GNU Extensions:
10272
     enum identifier [opt] { enumerator-list [opt] } attributes
10271
     enum attributes[opt] identifier [opt] { enumerator-list [opt] }
10272
       attributes[opt]
10273
10273
10274
   Returns an ENUM_TYPE representing the enumeration.  */
10274
   Returns an ENUM_TYPE representing the enumeration, or NULL_TREE
10275
   if the token stream isn't an enum-specifier after all.  */
10275
10276
10276
static tree
10277
static tree
10277
cp_parser_enum_specifier (cp_parser* parser)
10278
cp_parser_enum_specifier (cp_parser* parser)
10278
{
10279
{
10279
  tree identifier;
10280
  tree identifier;
10280
  tree type;
10281
  tree type;
10282
  tree attributes;
10281
10283
10284
  /* Parse tentatively so that we can back up if we don't find a
10285
     enum-specifier.  */
10286
  cp_parser_parse_tentatively (parser);
10287
10282
  /* Caller guarantees that the current token is 'enum', an identifier
10288
  /* Caller guarantees that the current token is 'enum', an identifier
10283
     possibly follows, and the token after that is an opening brace.
10289
     possibly follows, and the token after that is an opening brace.
10284
     If we don't have an identifier, fabricate an anonymous name for
10290
     If we don't have an identifier, fabricate an anonymous name for
10285
     the enumeration being defined.  */
10291
     the enumeration being defined.  */
10286
  cp_lexer_consume_token (parser->lexer);
10292
  cp_lexer_consume_token (parser->lexer);
10287
10293
10294
  attributes = cp_parser_attributes_opt (parser);
10295
10288
  if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
10296
  if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
10289
    identifier = cp_parser_identifier (parser);
10297
    identifier = cp_parser_identifier (parser);
10290
  else
10298
  else
10291
    identifier = make_anon_name ();
10299
    identifier = make_anon_name ();
10292
10300
10301
  /* Look for the `{' but don't consume it yet.  */
10302
  if (!cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
10303
    cp_parser_simulate_error (parser);
10304
10305
  if (!cp_parser_parse_definitely (parser))
10306
    return NULL_TREE;
10307
10293
  /* Issue an error message if type-definitions are forbidden here.  */
10308
  /* Issue an error message if type-definitions are forbidden here.  */
10294
  cp_parser_check_type_definition (parser);
10309
  cp_parser_check_type_definition (parser);
10295
10310
Lines 10301-10306 Link Here
10301
  /* Consume the opening brace.  */
10316
  /* Consume the opening brace.  */
10302
  cp_lexer_consume_token (parser->lexer);
10317
  cp_lexer_consume_token (parser->lexer);
10303
10318
10319
  if (type == error_mark_node)
10320
    {
10321
      cp_parser_skip_to_end_of_block_or_statement (parser);
10322
      return error_mark_node;
10323
    }
10324
10304
  /* If the next token is not '}', then there are some enumerators.  */
10325
  /* If the next token is not '}', then there are some enumerators.  */
10305
  if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_BRACE))
10326
  if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_BRACE))
10306
    cp_parser_enumerator_list (parser, type);
10327
    cp_parser_enumerator_list (parser, type);
Lines 12909-12915 Link Here
12909
      scope = CP_DECL_CONTEXT (TYPE_MAIN_DECL (type));
12930
      scope = CP_DECL_CONTEXT (TYPE_MAIN_DECL (type));
12910
      old_scope = push_inner_scope (scope);
12931
      old_scope = push_inner_scope (scope);
12911
    }
12932
    }
12912
  type = begin_class_definition (type);
12933
  type = begin_class_definition (type, attributes);
12913
12934
12914
  if (type == error_mark_node)
12935
  if (type == error_mark_node)
12915
    /* If the type is erroneous, skip the entire body of the class.  */
12936
    /* If the type is erroneous, skip the entire body of the class.  */
Lines 12926-12935 Link Here
12926
  has_trailing_semicolon = (token->type == CPP_SEMICOLON);
12947
  has_trailing_semicolon = (token->type == CPP_SEMICOLON);
12927
  /* Look for trailing attributes to apply to this class.  */
12948
  /* Look for trailing attributes to apply to this class.  */
12928
  if (cp_parser_allow_gnu_extensions_p (parser))
12949
  if (cp_parser_allow_gnu_extensions_p (parser))
12929
    {
12950
    attributes = cp_parser_attributes_opt (parser);
12930
      tree sub_attr = cp_parser_attributes_opt (parser);
12931
      attributes = chainon (attributes, sub_attr);
12932
    }
12933
  if (type != error_mark_node)
12951
  if (type != error_mark_node)
12934
    type = finish_struct (type, attributes);
12952
    type = finish_struct (type, attributes);
12935
  if (nested_name_specifier_p)
12953
  if (nested_name_specifier_p)
(-)gcc/c-decl.c (-6 / +4 lines)
Lines 3448-3465 Link Here
3448
  /* If #pragma weak was used, mark the decl weak now.  */
3448
  /* If #pragma weak was used, mark the decl weak now.  */
3449
  maybe_apply_pragma_weak (decl);
3449
  maybe_apply_pragma_weak (decl);
3450
3450
3451
  /* If this is a variable definition, determine its ELF visibility.  */
3452
  if (TREE_CODE (decl) == VAR_DECL 
3453
      && TREE_STATIC (decl) 
3454
      && !DECL_EXTERNAL (decl))
3455
    c_determine_visibility (decl);
3456
3457
  /* Output the assembler code and/or RTL code for variables and functions,
3451
  /* Output the assembler code and/or RTL code for variables and functions,
3458
     unless the type is an undefined structure or union.
3452
     unless the type is an undefined structure or union.
3459
     If not, it will get done when the type is completed.  */
3453
     If not, it will get done when the type is completed.  */
3460
3454
3461
  if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
3455
  if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
3462
    {
3456
    {
3457
      /* Determine the ELF visibility.  */
3458
      if (TREE_PUBLIC (decl))
3459
	c_determine_visibility (decl);
3460
3463
      /* This is a no-op in c-lang.c or something real in objc-act.c.  */
3461
      /* This is a no-op in c-lang.c or something real in objc-act.c.  */
3464
      if (c_dialect_objc ())
3462
      if (c_dialect_objc ())
3465
	objc_check_decl (decl);
3463
	objc_check_decl (decl);
(-)gcc/varasm.c (-1 / +1 lines)
Lines 4955-4961 Link Here
4955
default_assemble_visibility (tree decl, int vis)
4955
default_assemble_visibility (tree decl, int vis)
4956
{
4956
{
4957
  static const char * const visibility_types[] = {
4957
  static const char * const visibility_types[] = {
4958
    NULL, "internal", "hidden", "protected"
4958
    NULL, "protected", "hidden", "internal"
4959
  };
4959
  };
4960
4960
4961
  const char *name, *type;
4961
  const char *name, *type;
(-)gcc/c-common.c (-20 / +44 lines)
Lines 4805-4825 Link Here
4805
static tree
4805
static tree
4806
handle_visibility_attribute (tree *node, tree name, tree args,
4806
handle_visibility_attribute (tree *node, tree name, tree args,
4807
			     int ARG_UNUSED (flags),
4807
			     int ARG_UNUSED (flags),
4808
			     bool *no_add_attrs)
4808
			     bool *ARG_UNUSED (no_add_attrs))
4809
{
4809
{
4810
  tree decl = *node;
4810
  tree decl = *node;
4811
  tree id = TREE_VALUE (args);
4811
  tree id = TREE_VALUE (args);
4812
  enum symbol_visibility vis;
4812
4813
4813
  *no_add_attrs = true;
4814
4815
  if (TYPE_P (*node))
4814
  if (TYPE_P (*node))
4816
    {
4815
    {
4817
      if (TREE_CODE (*node) != RECORD_TYPE && TREE_CODE (*node) != UNION_TYPE)
4816
      if (TREE_CODE (*node) == ENUMERAL_TYPE)
4818
       {
4817
	/* OK */;
4819
         warning (OPT_Wattributes, "%qE attribute ignored on non-class types",
4818
      else if (TREE_CODE (*node) != RECORD_TYPE && TREE_CODE (*node) != UNION_TYPE)
4820
		  name);
4819
	{
4821
         return NULL_TREE;
4820
	  warning (OPT_Wattributes, "%qE attribute ignored on non-class types",
4822
       }
4821
		   name);
4822
	  return NULL_TREE;
4823
	}
4824
      else if (TYPE_FIELDS (*node))
4825
	{
4826
	  error ("%qE attribute ignored because %qT is already defined",
4827
		 name, *node);
4828
	  return NULL_TREE;
4829
	}
4823
    }
4830
    }
4824
  else if (decl_function_context (decl) != 0 || !TREE_PUBLIC (decl))
4831
  else if (decl_function_context (decl) != 0 || !TREE_PUBLIC (decl))
4825
    {
4832
    {
Lines 4848-4870 Link Here
4848
    }
4855
    }
4849
4856
4850
  if (strcmp (TREE_STRING_POINTER (id), "default") == 0)
4857
  if (strcmp (TREE_STRING_POINTER (id), "default") == 0)
4851
    DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
4858
    vis = VISIBILITY_DEFAULT;
4852
  else if (strcmp (TREE_STRING_POINTER (id), "internal") == 0)
4859
  else if (strcmp (TREE_STRING_POINTER (id), "internal") == 0)
4853
    DECL_VISIBILITY (decl) = VISIBILITY_INTERNAL;
4860
    vis = VISIBILITY_INTERNAL;
4854
  else if (strcmp (TREE_STRING_POINTER (id), "hidden") == 0)
4861
  else if (strcmp (TREE_STRING_POINTER (id), "hidden") == 0)
4855
    DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
4862
    vis = VISIBILITY_HIDDEN;
4856
  else if (strcmp (TREE_STRING_POINTER (id), "protected") == 0)
4863
  else if (strcmp (TREE_STRING_POINTER (id), "protected") == 0)
4857
    DECL_VISIBILITY (decl) = VISIBILITY_PROTECTED;
4864
    vis = VISIBILITY_PROTECTED;
4858
  else
4865
  else
4859
    error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
4866
    {
4867
      error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
4868
      vis = VISIBILITY_DEFAULT;
4869
    }
4870
4871
  if (DECL_VISIBILITY_SPECIFIED (decl)
4872
      && vis != DECL_VISIBILITY (decl)
4873
      && lookup_attribute ("visibility", (TYPE_P (*node)
4874
					  ? TYPE_ATTRIBUTES (*node)
4875
					  : DECL_ATTRIBUTES (decl))))
4876
    error ("%qD redeclared with different visibility", decl);
4877
4878
  DECL_VISIBILITY (decl) = vis;
4860
  DECL_VISIBILITY_SPECIFIED (decl) = 1;
4879
  DECL_VISIBILITY_SPECIFIED (decl) = 1;
4861
4880
4862
  /* For decls only, go ahead and attach the attribute to the node as well.
4881
  /* Go ahead and attach the attribute to the node as well.  This is needed
4863
     This is needed so we can determine whether we have VISIBILITY_DEFAULT
4882
     so we can determine whether we have VISIBILITY_DEFAULT because the
4864
     because the visibility was not specified, or because it was explicitly
4883
     visibility was not specified, or because it was explicitly overridden
4865
     overridden from the class visibility.  */
4884
     from the containing scope.  */
4866
  if (DECL_P (*node))
4867
    *no_add_attrs = false;
4868
4885
4869
  return NULL_TREE;
4886
  return NULL_TREE;
4870
}
4887
}
Lines 4901-4906 Link Here
4901
      return true;
4918
      return true;
4902
    }
4919
    }
4903
4920
4921
  /* Set default visibility to whatever the user supplied with
4922
     visibility_specified depending on #pragma GCC visibility.  */
4923
  if (!DECL_VISIBILITY_SPECIFIED (decl))
4924
    {
4925
      DECL_VISIBILITY (decl) = default_visibility;
4926
      DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma;
4927
    }
4904
  return false;
4928
  return false;
4905
}
4929
}
4906
4930

Return to bug 146817