mir gelungen wie diese eine Klasse zu schreiben, das als nicht-statisches Attribut der Klasse definiert in einem Lambda-Erfassung:Erfassung dieses in Lambda-Attribut in einer Templat-Klasse vs nicht-Templat-Klasse
#include <memory>
#include <iostream>
#include <functional>
struct S
{
S()
{
std::cout << "S::S()[" << this << "]" << std::endl;
}
std::string y_{"hi mate"};
int x_;
std::function<void(int*)> del_{[this](int *ptr)
{
std::cout << "Deleting ptr[" << ptr << "] this[" << this << "] this->y_[" << this->y_ << "]" << std::endl;
}};
std::unique_ptr<decltype(x_), decltype(del_)> unique_{&x_, del_};
};
int main()
{
S s;
}
Diese kompiliert und scheint gut zu laufen.
jedoch mit einer Templat-Klasse, ist es nicht mehr funktioniert:
#include <memory>
#include <iostream>
#include <functional>
template <typename>
struct S
{
S()
{
std::cout << "S::S()[" << this << "]" << std::endl;
}
std::string y_{"hi mate"};
int x_;
std::function<void(int*)> del_{[this](int *ptr)
{
std::cout << "Deleting ptr[" << ptr << "] this[" << this << "] this->y_[" << this->y_ << "]" << std::endl;
}};
std::unique_ptr<decltype(x_), decltype(del_)> unique_{&x_, del_};
};
int main()
{
S<int> s;
}
$> g++ -std=c++1y custom_deleter_template.cpp
~/test custom_deleter_template.cpp: In instantiation of ‘struct S::’: custom_deleter_template.cpp:9:3: required from ‘S< >::S() [with = int]’ custom_deleter_template.cpp:24:10:
required from here custom_deleter_template.cpp:15:35: internal compiler error: in tsubst_copy, at cp/pt.c:12569
std::function del_{[this](int *ptr) ^Please submit a full bug report, with preprocessed source if appropriate. See for instructions. Preprocessed source stored into /tmp/pyro/ccxfNspM.out file, please attach this to your bugreport.
Vor Einreichung einer bugreport (was ich nicht tun kann, blockiert sie die Kontoerstellung), ist es normal, dass es kompiliert nicht, basierend auf was der Standard sagt?
Compiler ist g ++ (Ubuntu 4.9.2-0ubuntu1 ~ 14.04) 4.9.2, verwendete Flag -std = C++ 1y. Gleiches passiert mit dem Flag -std = C++ 11.
Interne Compilerfehler sind immer ein Fehler. Das sollte wie in [clang] (http://coliru.stacked-crooked.com/a/4e113357c1393eb6) kompiliert werden. – 0x499602D2
Ich kann mit GCC 4.9.2 unter OS X reproduzieren. – Cornstalks
kompiliert es in clang :). – pyro