public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "frrrwww at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/68070] New: Undefined reference to default constructor of member template class
Date: Fri, 23 Oct 2015 14:19:00 -0000	[thread overview]
Message-ID: <bug-68070-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 68070
           Summary: Undefined reference to default constructor of member
                    template class
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: frrrwww at gmail dot com
  Target Milestone: ---

Hello,

When compiling the following simple program with `g++ prog.cc -Wall -Wextra
-std=c++14`

-----
#include <vector>

template<typename Value>
struct A
{
    A() = default;
    std::vector<Value> m_content;
};

void func(A<int> a = {})
{
}

int main()
{
    func();
}
-----

We get the following error:

-----
/tmp/ccr6nbUo.o: In function `main':
prog.cc:(.text+0x1b): undefined reference to `std::vector<int,
std::allocator<int> >::vector()'
collect2: error: ld returned 1 exit status
-----

That error happens on gcc 4.9, 5.2 and 6.0, it does not happen on clang for
this specific code.

An alternative version of the code:

-----
#include <vector>

template<typename Value>
struct A
{
    A() = default;
    A(int) {}
    std::vector<Value> m_content;
};

struct B { A<int> a; };

void func(B b = {})
{
}

int main()
{
    func();
}
-----

gets this error:

-----
/tmp/ccvOFE5O.o: In function `main':
prog.cc:(.text+0x33): undefined reference to `A<int>::A()'
collect2: error: ld returned 1 exit status
-----


             reply	other threads:[~2015-10-23 14:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-23 14:19 frrrwww at gmail dot com [this message]
2015-10-25  1:59 ` [Bug c++/68070] " redi at gcc dot gnu.org
2021-08-12  2:17 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-68070-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).