llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.31k stars 11.69k forks source link

initializer list {} fails for template instantiation + map + tuple +vector #47275

Open llvmbot opened 3 years ago

llvmbot commented 3 years ago
Bugzilla Link 47931
Version 11.0
OS All
Attachments fail exemple
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@kamleshbhalui,@zygoloid

Extended Description

this is a pretty specific bug, probably due to the explicit instantiation:

when having an initialisation list for a std::map<something1, std::tuple<something2, std::vector<something3>>> inside an explicitly instantiated function, there is a failure of type:

Undefined symbols for architecture x86_64: std::__1::allocator<unsigned long> > >::~tuple()

there is no reason why the attached code should fail to compile, and it actually works on gcc.

note: -remove the explicit instantiation and it works -replace the vector by a simple type like int and it works -remove the map and it works

I used clang++ -std=c++17 ./clangbug.cpp

sorry I'm new here let me know if anything else is needed

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 3 years ago

Reduced testcase:

template<typename T> struct wrap {
    wrap(int) {}
    ~wrap() {}
};

template<typename T> void f(wrap<int> *a) { *a = { 0 }; }

int main() { f<void>(nullptr); }

I imagine we're not properly rebuilding a non-dependent RHS of an assignment expression during template instantiation (perhaps because we transform it as an expression rather than as an initializer).