public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64293] New: [C++14] explicit instantiation declaration suppresses instantiation of constexpr constructor
@ 2014-12-12 21:29 redi at gcc dot gnu.org
  2014-12-13 18:18 ` [Bug c++/64293] " ville.voutilainen at gmail dot com
  0 siblings, 1 reply; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2014-12-12 21:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64293

            Bug ID: 64293
           Summary: [C++14] explicit instantiation declaration suppresses
                    instantiation of constexpr constructor
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org

template <typename T>
struct Foo {
  constexpr Foo()  { }

  constexpr Foo(T const& val) {
    for (auto& el : _data) {
      el = val;
    }
  }

  T _data[2];
};

extern template struct Foo<int>;

#ifdef USE
Foo<int> f = 1;
#else
template struct Foo<int>;
#endif


When compiled with -std=gnu++14 this does not instantiate the constructor:

$ g++14 -c foo.cpp && nm -C foo.o
                 U Foo<int>::Foo(int const&)
0000000000000000 W Foo<int>::Foo()
0000000000000000 W Foo<int>::Foo()

And when compiled so it uses the constructor, the explicit instantiation
declaration suppresses the instantiation of that constructor:

$ g++14 -c foo.cpp -DUSE && nm -C foo.o
0000000000000038 t _GLOBAL__sub_I_f
0000000000000000 t __static_initialization_and_destruction_0(int, int)
                 U Foo<int>::Foo(int const&)
0000000000000000 B f

So neither the file that uses it nor the file that should define it has the
symbol, leading to a linker error.

The symbol is defined if:
- the constructors are not constexpr, or
- the constructor is not delegated to by the default constructor, or
- the constructor does not contain a loop, or
- the explicit instantation is not declared before being defined

Oddly, clang 3.4 has almost exactly the same bug, the only difference is that
the presence of the loop makes no difference, the constructor is not generated
even if the body is empty. Clang 3.5 generates the constructor as I expect.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/64293] [C++14] explicit instantiation declaration suppresses instantiation of constexpr constructor
  2014-12-12 21:29 [Bug c++/64293] New: [C++14] explicit instantiation declaration suppresses instantiation of constexpr constructor redi at gcc dot gnu.org
@ 2014-12-13 18:18 ` ville.voutilainen at gmail dot com
  0 siblings, 0 replies; 2+ messages in thread
From: ville.voutilainen at gmail dot com @ 2014-12-13 18:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64293

Ville Voutilainen <ville.voutilainen at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-12-13
                 CC|                            |ville.voutilainen at gmail dot com
     Ever confirmed|0                           |1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-12-13 18:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-12 21:29 [Bug c++/64293] New: [C++14] explicit instantiation declaration suppresses instantiation of constexpr constructor redi at gcc dot gnu.org
2014-12-13 18:18 ` [Bug c++/64293] " ville.voutilainen at gmail 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).