[Bug c++/86135] At run time, when the constructor tries to construct an objects element with a initializer-list (using c++11 style) is giving segmentation fault. The old style of initialize with pa
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 --- Comment #12 from Sabetay Toros --- Created attachment 44272 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44272&action=edit Testi case for crashed initialiazer list
[Bug c++/86135] At run time, when the constructor tries to construct an objects element with a initializer-list (using c++11 style) is giving segmentation fault. The old style of initialize with pa
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 --- Comment #11 from Sabetay Toros --- Here is my test case. The issue is in line 30. Please change the line commented with direct initilization. It wont crash. If you are right list initializers is not usable. I hope you have an answer. #include using namespace std;#include #include #include #include #include #include #include template void Draw(ostream& os, const T& Entry) { os << Entry << endl;} struct TObject { template TObject(T e) : Self(make_shared>(move(e))) {} friend void Draw(ostream& os, const TObject& Entry) { Entry.Self->ModelDraw(os); } private : struct TConcept { virtual ~TConcept() = default; virtual void ModelDraw(ostream& os) const = 0; }; shared_ptr Self; template struct TModel final : TConcept { TModel(T e) : Data { move(e) } { } // It seems the issue is in this line, initiliazer list C++11 version does not work //TModel(T e) : Data ( move(e) ) { } // C++98 style is working. void ModelDraw(ostream& os) const { Draw(os, Data); } T Data; }; };class TMyClass {public : string s; TMyClass(string e) : s(move(e)) {}; friend void Draw(ostream& os, const TMyClass& E) { os << E.s << endl; }};using TDocument = vector;void Draw(ostream& os, const TDocument& vDoc) { os << " Document Print --" << endl; for(const auto& e: vDoc) Draw(os,e); os << endl;}using THistory = vector;TDocument& GetCurrent(THistory& vHstry) { return vHstry.back();}void SaveHistory(THistory& vHstry) { vHstry.push_back(vHstry.back());}int main(int argc, char** argv) { TDocument vDoc; THistory vHstry(1); GetCurrent(vHstry).emplace_back(1); GetCurrent(vHstry).emplace_back(3.2); GetCurrent(vHstry).emplace_back(" This is a try"); GetCurrent(vHstry).emplace_back(" My Class "); GetCurrent(vHstry).emplace_back(GetCurrent(vHstry)); Draw(cout , GetCurrent(vHstry)); return 0;} On Wed, Jun 13, 2018 at 11:04 PM, redi at gcc dot gnu.org < gcc-bugzi...@gcc.gnu.org> wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 > > --- Comment #10 from Jonathan Wakely --- > You didn't provide a proper testcase so nobody can possibly explain why > your > code crashes. > > If it's similar to the code in comment 3 then > model_t> > tries to construct a vector from a vector using > list-init > which chooses the initializer_list constructor because object_t can be > constructed from vector. It's the same bug 85577. > > -- > You are receiving this mail because: > You reported the bug. >
[Bug c++/86135] At run time, when the constructor tries to construct an objects element with a initializer-list (using c++11 style) is giving segmentation fault. The old style of initialize with pa
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 --- Comment #10 from Jonathan Wakely --- You didn't provide a proper testcase so nobody can possibly explain why your code crashes. If it's similar to the code in comment 3 then model_t> tries to construct a vector from a vector using list-init which chooses the initializer_list constructor because object_t can be constructed from vector. It's the same bug 85577.
[Bug c++/86135] At run time, when the constructor tries to construct an objects element with a initializer-list (using c++11 style) is giving segmentation fault. The old style of initialize with pa
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 --- Comment #9 from Sabetay Toros --- I´ve examined your link. This is not the same case as you are stating. I am not initializing a vector with an initializer list, rather I am trying to initialize only one object member with a universal initialiazer. And all modern C++ books suggest not to use C++98 style initiliazers, just because they are confusing. After constructing the object I am putting to a vector. This is very very simple case. And besides what is your solution to this issue. How the user will be able to find that kind of errors. In these cases gcc must not give a runtime error message but compiler error message. On Wed, Jun 13, 2018 at 9:00 PM, redi at gcc dot gnu.org < gcc-bugzi...@gcc.gnu.org> wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 > > --- Comment #8 from Jonathan Wakely --- > http://en.cppreference.com/w/cpp/language/list_initialization#Notes shows > a > similar example, demonstrating the different behaviour for initializer_list > constructors. std::vector has an initializer-list constructor, so trying to > move-construct a vector when object_t can be constructed from > std::vector will result in infinite recursion. > > This special case only applies to list-initialization, because it's > related to > constructors taking a std::initializer_list. It's totally wrong to say that > list-init and direct-init must do the same thing in the presence of > initializer-list constructors. If they did the same thing there would have > been > no need to introduce list-initialization syntax in the first place. > > -- > You are receiving this mail because: > You reported the bug. >
[Bug c++/86135] At run time, when the constructor tries to construct an objects element with a initializer-list (using c++11 style) is giving segmentation fault. The old style of initialize with pa
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 --- Comment #8 from Jonathan Wakely --- http://en.cppreference.com/w/cpp/language/list_initialization#Notes shows a similar example, demonstrating the different behaviour for initializer_list constructors. std::vector has an initializer-list constructor, so trying to move-construct a vector when object_t can be constructed from std::vector will result in infinite recursion. This special case only applies to list-initialization, because it's related to constructors taking a std::initializer_list. It's totally wrong to say that list-init and direct-init must do the same thing in the presence of initializer-list constructors. If they did the same thing there would have been no need to introduce list-initialization syntax in the first place.
[Bug c++/86135] At run time, when the constructor tries to construct an objects element with a initializer-list (using c++11 style) is giving segmentation fault. The old style of initialize with pa
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 --- Comment #7 from Jonathan Wakely --- (In reply to Sabetay Toros from comment #6) > the rules may be different but results must be the same. No, that's not true. The point of the different rules is to do different things. > There is a flaw here. If gcc is right in *list-initialization * then direct > initialization is wrong and should give the same result, No.
[Bug c++/86135] At run time, when the constructor tries to construct an objects element with a initializer-list (using c++11 style) is giving segmentation fault. The old style of initialize with pa
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 --- Comment #6 from Sabetay Toros --- Hi, *Because the rules for direct-initialization (with parentheses) andlist-initialization (with braces) are different. Different rules meansdifferent things happen. * the rules may be different but results must be the same. There is a flaw here. If gcc is right in *list-initialization * then direct initialization is wrong and should give the same result, the segmentation fault. But it is not giving an error and it is working as expected. If Clang is running both version without an error, sorry you can not defend this. It cant be a biased result for achieving the initialization of a member. On Wed, Jun 13, 2018 at 7:04 PM, redi at gcc dot gnu.org < gcc-bugzi...@gcc.gnu.org> wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 > > --- Comment #5 from Jonathan Wakely --- > (In reply to Sabetay Toros from comment #4) > > If it is not a bug then why the parenthesis version is working. > > Because the rules for direct-initialization (with parentheses) and > list-initialization (with braces) are different. Different rules means > different things happen. > > > Moreover Strastroup advice is to use the initializer list version in > > constructing objects not the parenthesis. > > That's not always good advice. > > > Besides Clang does not suffer with that kind of error. Both styles are > > working. > > Clang does not follow the standard correctly in this respect. > > -- > You are receiving this mail because: > You reported the bug. >
[Bug c++/86135] At run time, when the constructor tries to construct an objects element with a initializer-list (using c++11 style) is giving segmentation fault. The old style of initialize with pa
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 --- Comment #5 from Jonathan Wakely --- (In reply to Sabetay Toros from comment #4) > If it is not a bug then why the parenthesis version is working. Because the rules for direct-initialization (with parentheses) and list-initialization (with braces) are different. Different rules means different things happen. > Moreover Strastroup advice is to use the initializer list version in > constructing objects not the parenthesis. That's not always good advice. > Besides Clang does not suffer with that kind of error. Both styles are > working. Clang does not follow the standard correctly in this respect.
[Bug c++/86135] At run time, when the constructor tries to construct an objects element with a initializer-list (using c++11 style) is giving segmentation fault. The old style of initialize with pa
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 --- Comment #4 from Sabetay Toros --- *" --- Comment #2 from Jonathan Wakely http://gnu.org/>> ---This is not a bug, GCC is correct. With list-initialization the compiler doesnot always select a copy/move constructor even when the argument is the sametype as the object being constructed. "* If it is not a bug then why the parenthesis version is working. Moreover Strastroup advice is to use the initializer list version in constructing objects not the parenthesis. Besides Clang does not suffer with that kind of error. Both styles are working. Sabetay On Wed, Jun 13, 2018 at 5:52 PM, redi at gcc dot gnu.org < gcc-bugzi...@gcc.gnu.org> wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 > > Jonathan Wakely changed: > >What|Removed |Added > > > Status|WAITING |RESOLVED > Resolution|--- |DUPLICATE > > --- Comment #2 from Jonathan Wakely --- > This is not a bug, GCC is correct. With list-initialization the compiler > does > not always select a copy/move constructor even when the argument is the > same > type as the object being constructed. > > *** This bug has been marked as a duplicate of bug 85577 *** > > -- > You are receiving this mail because: > You reported the bug. >
[Bug c++/86135] At run time, when the constructor tries to construct an objects element with a initializer-list (using c++11 style) is giving segmentation fault. The old style of initialize with pa
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 --- Comment #3 from Jonathan Wakely --- Based on the names I'm assuming your code is the same as a case I analysed recently, which reduces to: #include #include struct object_t { template object_t(T object) : obj{std::make_shared>(std::move(object))} { } struct concept_t { virtual ~concept_t() = default; }; template struct model_t : concept_t { model_t(T value) : _data{std::move(value)} {} T _data; }; std::shared_ptr obj; }; int main() { std::vector d; std::vector d2; d.push_back(d2); } This crashes with a stack overflow, due to Core DR 2137. GCC appears to be implementing the standard correctly.
[Bug c++/86135] At run time, when the constructor tries to construct an objects element with a initializer-list (using c++11 style) is giving segmentation fault. The old style of initialize with pa
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 Jonathan Wakely changed: What|Removed |Added Status|WAITING |RESOLVED Resolution|--- |DUPLICATE --- Comment #2 from Jonathan Wakely --- This is not a bug, GCC is correct. With list-initialization the compiler does not always select a copy/move constructor even when the argument is the same type as the object being constructed. *** This bug has been marked as a duplicate of bug 85577 ***
[Bug c++/86135] At run time, when the constructor tries to construct an objects element with a initializer-list (using c++11 style) is giving segmentation fault. The old style of initialize with pa
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86135 Marek Polacek changed: What|Removed |Added Status|UNCONFIRMED |WAITING Last reconfirmed||2018-06-13 CC||mpolacek at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #1 from Marek Polacek --- Can you please provide a working stand-alone testcase? Thanks.