public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17470] New: Visibility attribute ignored for explicit template instantiation
@ 2004-09-13 21:37 austern at apple dot com
2004-09-13 23:40 ` [Bug c++/17470] " bangerth at dealii dot org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: austern at apple dot com @ 2004-09-13 21:37 UTC (permalink / raw)
To: gcc-bugs
[isolde:tmp]$ cat foo.cc
template <class T> T identity(T t) { return t; }
template int identity(int);
template __attribute__((visibility("default"))) double identity(double);
[isolde:tmp]$ /work/root.u/bin/g++ -fvisibility=hidden -c foo.cc
[isolde:tmp]$ nm -m foo.o
00000024 (__TEXT,__text) private external __Z8identityIdET_S0_
00000000 (absolute) private external __Z8identityIdET_S0_.eh
00000000 (__TEXT,__text) private external __Z8identityIiET_S0_
00000000 (absolute) private external __Z8identityIiET_S0_.eh
[isolde:tmp]$
--
Summary: Visibility attribute ignored for explicit template
instantiation
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: austern at apple dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: powerpc-apple-darwin7.5.0
GCC host triplet: powerpc-apple-darwin7.5.0
GCC target triplet: powerpc-apple-darwin7.5.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17470
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17470] Visibility attribute ignored for explicit template instantiation
2004-09-13 21:37 [Bug c++/17470] New: Visibility attribute ignored for explicit template instantiation austern at apple dot com
@ 2004-09-13 23:40 ` bangerth at dealii dot org
2004-09-14 2:20 ` austern at apple dot com
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2004-09-13 23:40 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-09-13 23:40 -------
May I remark that I would find it quite odd to have attributes
for functions on a template _instantiations_? I would think that
the attribute should be at either the declaration or the definition.
I understand that this precludes giving different instantiations
different visibility, but it would make the system somewhat less
odd...
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17470
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17470] Visibility attribute ignored for explicit template instantiation
2004-09-13 21:37 [Bug c++/17470] New: Visibility attribute ignored for explicit template instantiation austern at apple dot com
2004-09-13 23:40 ` [Bug c++/17470] " bangerth at dealii dot org
@ 2004-09-14 2:20 ` austern at apple dot com
2004-09-14 3:48 ` bangerth at dealii dot org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: austern at apple dot com @ 2004-09-14 2:20 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From austern at apple dot com 2004-09-14 02:20 -------
Tastes differ, I suppose! My own feeling is that it's unnatural, when declaring an unbounded set of
functions, to have to say that either all of them or none of them get exported. I find it more likely that
a dynamic library author would decide that a selected few specializations are the library's interface.
However, I don't insist on that point. What I do insist on: it's wrong for the compiler to silently ignore
the visibility attribute on explicit instantiations. Either it should be honored, or else it should be
documented and diagnosed as an error. Silently ignoring it is a nasty trap for users.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17470
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17470] Visibility attribute ignored for explicit template instantiation
2004-09-13 21:37 [Bug c++/17470] New: Visibility attribute ignored for explicit template instantiation austern at apple dot com
2004-09-13 23:40 ` [Bug c++/17470] " bangerth at dealii dot org
2004-09-14 2:20 ` austern at apple dot com
@ 2004-09-14 3:48 ` bangerth at dealii dot org
2004-12-13 20:47 ` efrias at syncad dot com
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2004-09-14 3:48 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-09-14 03:48 -------
That latter point is most certainly uncontested! :-)
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17470
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17470] Visibility attribute ignored for explicit template instantiation
2004-09-13 21:37 [Bug c++/17470] New: Visibility attribute ignored for explicit template instantiation austern at apple dot com
` (2 preceding siblings ...)
2004-09-14 3:48 ` bangerth at dealii dot org
@ 2004-12-13 20:47 ` efrias at syncad dot com
2004-12-22 20:54 ` nomis80 at nomis80 dot org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: efrias at syncad dot com @ 2004-12-13 20:47 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From efrias at syncad dot com 2004-12-13 20:46 -------
I just ran into this quirk too. It looks like you can work around by using
"#pragma GCC visibility push(default)" before the explicit instantiation and
then popping afterwards. I'd greatly prefer the __attribute__ syntax because
that would permit me to use one macro for porting __declspec(dllexport)
constructs from windows code. Even displaying a warning or error for the
ignored __attribute__ would've saved me some grief.
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |efrias at syncad dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17470
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17470] Visibility attribute ignored for explicit template instantiation
2004-09-13 21:37 [Bug c++/17470] New: Visibility attribute ignored for explicit template instantiation austern at apple dot com
` (3 preceding siblings ...)
2004-12-13 20:47 ` efrias at syncad dot com
@ 2004-12-22 20:54 ` nomis80 at nomis80 dot org
2004-12-22 20:57 ` nomis80 at nomis80 dot org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: nomis80 at nomis80 dot org @ 2004-12-22 20:54 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From nomis80 at nomis80 dot org 2004-12-22 20:54 -------
I just got hit with that bug and spent too much time figuring out what was
wrong. Here's my code, just to show an example of real-life usage:
//////////////////////////////////////////////////////////////////////////
/**
* Returns the unsigned version of \a number.
*/
template< class T >
T abs( T number )
{
// This is the default implementation, using comparison to zero and unary
// negation operator.
if ( number < 0 ) {
return -number;
}
return number;
}
// Here are some specific implementations.
template<> bool WRAP_API abs( bool number );
template<> char WRAP_API abs( char number );
template<> unsigned char WRAP_API abs( unsigned char number );
template<> short WRAP_API abs( short number );
template<> unsigned short WRAP_API abs( unsigned short number );
template<> int WRAP_API abs( int number );
template<> unsigned int WRAP_API abs( unsigned int number );
template<> long WRAP_API abs( long number );
template<> unsigned long WRAP_API abs( unsigned long number );
template<> float WRAP_API abs( float number );
template<> double WRAP_API abs( double number );
//////////////////////////////////////////////////////////////////////////
Please fix this bug!
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |s_gccbugzilla at nedprod dot
| |com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17470
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17470] Visibility attribute ignored for explicit template instantiation
2004-09-13 21:37 [Bug c++/17470] New: Visibility attribute ignored for explicit template instantiation austern at apple dot com
` (4 preceding siblings ...)
2004-12-22 20:54 ` nomis80 at nomis80 dot org
@ 2004-12-22 20:57 ` nomis80 at nomis80 dot org
2004-12-28 23:53 ` pinskia at gcc dot gnu dot org
2005-09-02 0:17 ` jmegq at radiance dot com
7 siblings, 0 replies; 9+ messages in thread
From: nomis80 at nomis80 dot org @ 2004-12-22 20:57 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |nomis80 at nomis80 dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17470
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17470] Visibility attribute ignored for explicit template instantiation
2004-09-13 21:37 [Bug c++/17470] New: Visibility attribute ignored for explicit template instantiation austern at apple dot com
` (5 preceding siblings ...)
2004-12-22 20:57 ` nomis80 at nomis80 dot org
@ 2004-12-28 23:53 ` pinskia at gcc dot gnu dot org
2005-09-02 0:17 ` jmegq at radiance dot com
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-12-28 23:53 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-12-28 23:52 -------
Confirmed.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2004-12-28 23:52:56
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17470
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/17470] Visibility attribute ignored for explicit template instantiation
2004-09-13 21:37 [Bug c++/17470] New: Visibility attribute ignored for explicit template instantiation austern at apple dot com
` (6 preceding siblings ...)
2004-12-28 23:53 ` pinskia at gcc dot gnu dot org
@ 2005-09-02 0:17 ` jmegq at radiance dot com
7 siblings, 0 replies; 9+ messages in thread
From: jmegq at radiance dot com @ 2005-09-02 0:17 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From jmegq at radiance dot com 2005-09-02 00:16 -------
Regarding macros -- I just found out about the _Pragma directive from C99, so at
least you can do something like this (paraphrasing some ACE code):
#define EXPORT_SINGLETON_DECLARE (SINGLETON_TYPE, CLASS, LOCK) \
_Pragma ("GCC visibility push(default)") \
template class SINGLETON_TYPE <CLASS, LOCK>; \
_Pragma ("GCC visibility pop")
#define IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) extern template
class SINGLETON_TYPE <CLASS, LOCK>;
Then define SINGLETON_DECLARE to depending on whether you're building the lib or
not.
A possible issue with this is that it must come before, say, a typedef of the
template type. The example below works on VS but not g++ (not that VS matters,
but I'm using code that does this):
typedef Singleton_T<Foo, Mutex> FOO_SINGLETON;
SINGLETON_DECLARE(Singleton_T, Foo, Mutex)
Instead, the SINGLETON_DECLARE needs to come before the typedef or it will get
hidden visibility on g++. I'm curious as to why the typedef causes the symbols
to get hidden visibility -- is that in spec, or is a bug?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17470
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2005-09-02 0:17 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-13 21:37 [Bug c++/17470] New: Visibility attribute ignored for explicit template instantiation austern at apple dot com
2004-09-13 23:40 ` [Bug c++/17470] " bangerth at dealii dot org
2004-09-14 2:20 ` austern at apple dot com
2004-09-14 3:48 ` bangerth at dealii dot org
2004-12-13 20:47 ` efrias at syncad dot com
2004-12-22 20:54 ` nomis80 at nomis80 dot org
2004-12-22 20:57 ` nomis80 at nomis80 dot org
2004-12-28 23:53 ` pinskia at gcc dot gnu dot org
2005-09-02 0:17 ` jmegq at radiance dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).