Skip to content

Unexpected undefined reference to implicitly declared destructor #39155

@llvmbot

Description

@llvmbot
Bugzilla Link 39808
Version unspecified
OS Linux
Attachments Source code, Preprocessed source
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@DougGregor,@zygoloid

Extended Description

Dear all,

When compiling the program below (which was stripped down to its bare mininum)

    #include <boost/container/static_vector.hpp>
  
    // Comment either of the lines marked as 1, 2, or 3 to make
    // the problem go away
    // Alternatively, uncomment line marked as 4 to make the
    // problem go away

    struct B final {
        B(void) { ; } // 1
    };

    struct A {
        boost::container::static_vector<B, 32> vec; // 2
        B elem; // 3
        // ~A() {} // 4
    };

    A *init(void) {
        return new A{};
    }

    void end(A *a) {
        delete a;
    }

    int main(void) {
        end(init());
        return 0;
    }

The result is an unexpected undefined reference to an implicitly declared destructor:

    clang++ -O0 -std=c++11 -I/opt/local/include -o a a.cpp
    /tmp/a-31ee39.o: In function `init()':
    a.cpp:(.text+0x62): undefined reference to `boost::container::static_vector<B, 32ul>::~static_vector()'
    /tmp/a-31ee39.o: In function `A::~A()':
    a.cpp:(.text._ZN1AD2Ev[_ZN1AD2Ev]+0x11): undefined reference to 
    `boost::container::static_vector<B, 32ul>::~static_vector()'
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am no C++ Jedi, but I can't understand why this would be the case. I am even more confused as to why commenting or uncommenting the lines as marked can eliminate the issue. For what is worth, g++ 7.3.0 has no problem compiling this code, whereas clang-6 and clang-7 show the same odd behavior. There is nothing special with boost either, as I tried several versions. The one I am currently using is 1.65.1.

If this behavior is expected, I'd be very happy if somebody could clarify this to me.

Kind regards,
Diego

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++clang:codegenIR generation bugs: mangling, exceptions, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions