public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/51426] New: explicit instantiation declaration without definition @ 2011-12-05 18:41 mkp76 at wp dot pl 2011-12-05 18:55 ` [Bug c++/51426] " redi at gcc dot gnu.org ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: mkp76 at wp dot pl @ 2011-12-05 18:41 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51426 Bug #: 51426 Summary: explicit instantiation declaration without definition Classification: Unclassified Product: gcc Version: 4.6.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: mkp76@wp.pl The below code can be compiled (with -std=C++0x option). -------------------------- template <typename T> struct A { }; extern template struct A<int>; int main() { A<int> a; } -------------------------- According to C++11 standard (14.7 paragraph 5) it shouldn't "an explicit instantiation definition shall appear at most once in a program" I was trying to test 'extern templates' based on Bjarne Stroustrup's page: http://www2.research.att.com/~bs/C++0xFAQ.html#extern-templates Regards, Marcin ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/51426] explicit instantiation declaration without definition 2011-12-05 18:41 [Bug c++/51426] New: explicit instantiation declaration without definition mkp76 at wp dot pl @ 2011-12-05 18:55 ` redi at gcc dot gnu.org 2011-12-05 23:46 ` paolo.carlini at oracle dot com ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: redi at gcc dot gnu.org @ 2011-12-05 18:55 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51426 --- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-05 18:54:11 UTC --- I don't see what that paragraph has to do with it - the explicit instantiation definition appears zero times, zero is less than one. The relevant text is 14.7.2 p11 "An entity that is the subject of an explicit instantiation declaration and that is also used in a way that would otherwise cause an implicit instantiation (14.7.1) in the translation unit shall be the subject of an explicit instantiation definition somewhere in the program; otherwise the program is ill-formed, no diagnostic required." The program is ill-formed, no diagnostic required. If you change it so there's something that actually needs a definition you'll get a linker error: template <typename T> struct A { A() { } }; extern template struct A<int>; int main() { A<int> a; } I don't see a bug here ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/51426] explicit instantiation declaration without definition 2011-12-05 18:41 [Bug c++/51426] New: explicit instantiation declaration without definition mkp76 at wp dot pl 2011-12-05 18:55 ` [Bug c++/51426] " redi at gcc dot gnu.org @ 2011-12-05 23:46 ` paolo.carlini at oracle dot com 2011-12-06 0:33 ` redi at gcc dot gnu.org 2011-12-06 17:49 ` mkp76 at wp dot pl 3 siblings, 0 replies; 5+ messages in thread From: paolo.carlini at oracle dot com @ 2011-12-05 23:46 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51426 Paolo Carlini <paolo.carlini at oracle dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |INVALID --- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-12-05 23:46:34 UTC --- Closing. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/51426] explicit instantiation declaration without definition 2011-12-05 18:41 [Bug c++/51426] New: explicit instantiation declaration without definition mkp76 at wp dot pl 2011-12-05 18:55 ` [Bug c++/51426] " redi at gcc dot gnu.org 2011-12-05 23:46 ` paolo.carlini at oracle dot com @ 2011-12-06 0:33 ` redi at gcc dot gnu.org 2011-12-06 17:49 ` mkp76 at wp dot pl 3 siblings, 0 replies; 5+ messages in thread From: redi at gcc dot gnu.org @ 2011-12-06 0:33 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51426 --- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-06 00:32:48 UTC --- (In reply to comment #0) > The below code can be compiled (with -std=C++0x option). By the way, the program compiles without -std=c++0x, GCC has supported extern templates since at least GCC 2.95 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/51426] explicit instantiation declaration without definition 2011-12-05 18:41 [Bug c++/51426] New: explicit instantiation declaration without definition mkp76 at wp dot pl ` (2 preceding siblings ...) 2011-12-06 0:33 ` redi at gcc dot gnu.org @ 2011-12-06 17:49 ` mkp76 at wp dot pl 3 siblings, 0 replies; 5+ messages in thread From: mkp76 at wp dot pl @ 2011-12-06 17:49 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51426 --- Comment #4 from Marcin Pytel <mkp76 at wp dot pl> 2011-12-06 17:49:06 UTC --- I did some more testing. I was using eclipse and it adds some compilation flags. The cause is optimization. When you add empty ctor there's the linker error. But when you compile with -O2 there's no error. When I added something to ctor (cout) I got linker error even with O2. Marcin ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-12-06 17:49 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-12-05 18:41 [Bug c++/51426] New: explicit instantiation declaration without definition mkp76 at wp dot pl 2011-12-05 18:55 ` [Bug c++/51426] " redi at gcc dot gnu.org 2011-12-05 23:46 ` paolo.carlini at oracle dot com 2011-12-06 0:33 ` redi at gcc dot gnu.org 2011-12-06 17:49 ` mkp76 at wp dot pl
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).