Re: Possible to declare move constructor of basic_symbol as noexcept?
Adrian <[email protected]> Thu, 7 Jan 2021 11:42:15 -0500
| Newsgroups | gmane.comp.parsers.bison.general |
|---|---|
| Message-ID | <CAL_yH3giCfR-NQdwVA004GKkLqqbXXEr1A7CcuOKJrErQfgAMw@mail.gmail.com> |
I meant potentially throwing destructor* (is a bad thing to do) On Thu, Jan 7, 2021 at 4:40 AM Adrian <[email protected]> wrote: > > Hi Akim, > > Yes, that was what I was referring to. Since > basic_symbol(basic_symbol&&) calls semantic_type::move<T>, a concern > is if that might throw. But I checked semantic_type::move<T> calls > semantic_type::emplace<T, U...> which is what calls the constructor, > semantic_type::as<T> which is already declared noexcept, and > semantic_type::destroy<T> which calls the destructor of T, which I > think could be throwing, but pretty sure having a potentially throwing > constructor is a Very Bad Thing To Do. > > Another concern is the need for the <type_traits> header for > std::is_nothrow_move_constructible, which is/can be implemented in > terms of std::is_nothrow_constructible, which I don't think can be > implemented without intrinsics? Since Bison currently doesn't depend > on (as far as I could find) <type_traits>, introducing this dependency > for such a niche case is probably undesirable. Maybe it could only be > enabled with a Bison declaration, but then that's extra maintenance > baggage. So I wasn't sure if this would be something you would be open > to > > Thanks for your time! > > Kind regards, > Adrian > > On Thu, Jan 7, 2021 at 12:30 AM Akim Demaille <[email protected]> wrote: > > > > Hi Adrian, > > > > > Le 6 janv. 2021 à 20:43, Adrian <[email protected]> a écrit : > > > > > > Hello, > > > > > > Is there any possibility we can declare the move constructor of > > > basic_symbol as noexcept (if the semantic_types are noexcept > > > moveable)? > > > > > > I have a semantic value that is non-copyable (moveable only) and I > > > want an std::vector<symbol_type>. std::vector only calls the move > > > constructor when resizing if the move constructor is declared noexcept > > > > > > It seems to me that the issue might be that you would require all of > > > the semantic types to be noexcept moveable. You would need a > > > (potentially huge) noexcept predicate, but since it's generated code > > > maybe it's ok > > > > My C++ is rusting. What exactly are you asking for? From > > > > > #if 201103L <= YY_CPLUSPLUS > > > /// Move constructor. > > > basic_symbol (basic_symbol&& that) > > > : Base (std::move (that)) > > > , value () > > > { > > > switch (this->kind ()) > > > { > > > case symbol_kind::S_NUMBER: // NUMBER > > > value.move< int > (std::move (that.value)); > > > break; > > > > > > case symbol_kind::S_TEXT: // TEXT > > > case symbol_kind::S_item: // item > > > value.move< std::string > (std::move (that.value)); > > > break; > > > > > > case symbol_kind::S_list: // list > > > value.move< std::vector<std::string> > (std::move (that.value)); > > > break; > > > > > > default: > > > break; > > > } > > > > > > } > > > #endif > > > > to go to > > > > > #if 201103L <= YY_CPLUSPLUS > > > /// Move constructor. > > > basic_symbol (basic_symbol&& that) > > > noexcept ( > > > std::is_nothrow_move_constructible< int >::value > > > && std::is_nothrow_move_constructible< std::string >::value > > > && std::is_nothrow_move_constructible< std::vector<std::string> >::value > > > > > > ) > > > : Base (std::move (that)) > > > , value () > > > > right?