public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57728] New: Explicit template instantiation with defaulted method causes missing symbol
@ 2013-06-26 14:43 bmerry at gmail dot com
2013-06-26 15:42 ` [Bug c++/57728] " redi at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: bmerry at gmail dot com @ 2013-06-26 14:43 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57728
Bug ID: 57728
Summary: Explicit template instantiation with defaulted method
causes missing symbol
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: bmerry at gmail dot com
Created attachment 30378
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30378&action=edit
Minimal test case
I don't claim to fully understand all the intricies of C++11, but the following
smells fishy to me. I am using a combination of features:
1. The = default syntax to restore implicit constructors/assignments that were
otherwise hidden (e.g. default constructor when there are no user-defined
constructors), in a templated class.
2. "extern template" in the header to suppress instantiation of a specific
instance, with an explicit instantiation in one translation unit.
In some cases (I assume depending on compiler eliding) this causes a link-time
error for the defaulted constructor. I have attached a minimal test case. I
don't know whether there is supposed to be a symbol or whether the compiler is
supposed to inline the default implementation, but currently there is a
mismatch.
System information: Ubuntu 12.04 with
gcc version 4.8.1 (Ubuntu 4.8.1-2ubuntu1~12.04)
Output (there's a more detailed log in the attachment with -v -save-temps):
g++-4.8 -std=c++11 -c defaulted.cpp
g++-4.8 -std=c++11 -c impl.cpp
g++-4.8 -std=c++11 -o defaulted defaulted.o impl.o
defaulted.o: In function `main':
defaulted.cpp:(.text+0x10): undefined reference to `A<int>::A()'
collect2: error: ld returned 1 exit status
make: *** [defaulted] Error 1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/57728] Explicit template instantiation with defaulted method causes missing symbol
2013-06-26 14:43 [Bug c++/57728] New: Explicit template instantiation with defaulted method causes missing symbol bmerry at gmail dot com
@ 2013-06-26 15:42 ` redi at gcc dot gnu.org
2013-06-26 15:46 ` bmerry at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2013-06-26 15:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57728
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-06-26
CC| |jason at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The explicit instantiation declaration suppresses the definition of A<int>::A()
in defaulted.o, but the explicit instantiation definition doesn't cause that
symbol to be emitted in impl.o, so when that constructor is not inlined there
is no definition.
As a single file:
template<typename T>
struct A
{
T x;
A() = default;
A(const A &other) = delete;
};
extern template class A<int>;
int main()
{
A<int> a;
}
This compiles with clang but not G++ because Clang doesn't create a reference
to A<int>::A() from main(), so it doesn't matter that the explicit
instantiation is not defined in the program.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/57728] Explicit template instantiation with defaulted method causes missing symbol
2013-06-26 14:43 [Bug c++/57728] New: Explicit template instantiation with defaulted method causes missing symbol bmerry at gmail dot com
2013-06-26 15:42 ` [Bug c++/57728] " redi at gcc dot gnu.org
@ 2013-06-26 15:46 ` bmerry at gmail dot com
2013-06-26 15:49 ` redi at gcc dot gnu.org
2013-08-04 12:03 ` paolo.carlini at oracle dot com
3 siblings, 0 replies; 5+ messages in thread
From: bmerry at gmail dot com @ 2013-06-26 15:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57728
--- Comment #2 from Bruce Merry <bmerry at gmail dot com> ---
(In reply to Jonathan Wakely from comment #1)
> The explicit instantiation declaration suppresses the definition of
> A<int>::A() in defaulted.o, but the explicit instantiation definition
> doesn't cause that symbol to be emitted in impl.o, so when that constructor
> is not inlined there is no definition.
That's more or less what I figured was happening. Can you clarify whether you
think this a GCC bug or just me misunderstanding the language? Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/57728] Explicit template instantiation with defaulted method causes missing symbol
2013-06-26 14:43 [Bug c++/57728] New: Explicit template instantiation with defaulted method causes missing symbol bmerry at gmail dot com
2013-06-26 15:42 ` [Bug c++/57728] " redi at gcc dot gnu.org
2013-06-26 15:46 ` bmerry at gmail dot com
@ 2013-06-26 15:49 ` redi at gcc dot gnu.org
2013-08-04 12:03 ` paolo.carlini at oracle dot com
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2013-06-26 15:49 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57728
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's a bug
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/57728] Explicit template instantiation with defaulted method causes missing symbol
2013-06-26 14:43 [Bug c++/57728] New: Explicit template instantiation with defaulted method causes missing symbol bmerry at gmail dot com
` (2 preceding siblings ...)
2013-06-26 15:49 ` redi at gcc dot gnu.org
@ 2013-08-04 12:03 ` paolo.carlini at oracle dot com
3 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-04 12:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57728
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |edward.hades at gmail dot com
--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
*** Bug 58078 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-08-04 12:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-26 14:43 [Bug c++/57728] New: Explicit template instantiation with defaulted method causes missing symbol bmerry at gmail dot com
2013-06-26 15:42 ` [Bug c++/57728] " redi at gcc dot gnu.org
2013-06-26 15:46 ` bmerry at gmail dot com
2013-06-26 15:49 ` redi at gcc dot gnu.org
2013-08-04 12:03 ` paolo.carlini at oracle 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).