help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible to declare move constructor of basic_symbol as noexcept?


From: Akim Demaille
Subject: Re: Possible to declare move constructor of basic_symbol as noexcept?
Date: Sat, 30 Jan 2021 18:10:32 +0100

Hi Christian,

I don't know how I managed to not see your answer about this,
but I just discovered it, when I was about to ask for more
feedback...

> Le 19 janv. 2021 à 13:36, Christian Schoenebeck <schoenebeck@crudebyte.com> a 
> écrit :
>> diff --git a/data/skeletons/c++.m4 b/data/skeletons/c++.m4
>> index cfd4e6ed7..3496450e2 100644
>> --- a/data/skeletons/c++.m4
>> +++ b/data/skeletons/c++.m4
>> @@ -309,7 +309,9 @@ m4_define([b4_symbol_type_define],
>> 
>> #if 201103L <= YY_CPLUSPLUS
>>       /// Move constructor.
>> -      basic_symbol (basic_symbol&& that)
>> +      basic_symbol (basic_symbol&& that)]b4_variant_if([
>> +        YY_NOEXCEPT (]b4_type_foreach([b4_is_nothrow_move_constructible],
>> [[ +                     && ]])[)])[
>> 
>>         : Base (std::move (that))
>> 
>>         , value (]b4_variant_if([], [std::move
> 
> AFAICS you are conditionally inserting the C++ 'noexcept' qualifier to class 
> "basic_symbol"'s constructor (by using C++ type trait 
> std::is_nowthrow_move_constructible()), and at the same time you are still 
> always using std::move() below though.

I'm unsure which "conditionally" you are referring to.  The
macro YY_NOEXCEPT is conditioned by whether this is at least
C++11.  Which is useless in the present case since we are
already within "#if 201103L <= YY_CPLUSPLUS".  I'll simplify
that.

And the noexcept itself depends on whether all the types
support nothrow move-construction.

> that should be 
> either noexcept & std::move() otherwise no std::move() at all, at least with 
> recent compilers.

Really?  What mandates that?  I can see it is good style,
but the standard library is expected to use things such as
move_if_noexcept to relieve us from having to not define
move ctors in this case.

And if that's true, that would mean
I'd have to play ninja tricks (read sfinae) to do that, and I'm
no longer in that mood :(  If someone wants to tell me what is
expected in replacement of

> #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 ()
>      {
>        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

I might do it.  But I still have to check that the rest of the
skeleton would accept that.

> Not sure what your intention was to leave std::move() 
> unconditionally there, I guess for pre-C++11 compilers?

Not sure what you mean here.  I do not try to support compilers
that support move, but don't comply with "#if 201103L <= YY_CPLUSPLUS".

Cheers!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]