bug-bison
[Top][All Lists]
Advanced

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

Re: Can I use decltype?


From: Akim Demaille
Subject: Re: Can I use decltype?
Date: Mon, 22 Oct 2018 18:16:49 +0200

Hi!

> Le 22 oct. 2018 à 09:48, 長田偉伸 <address@hidden> a écrit :
> 
> [Description]
>  Please confirm the attached file
> 
> [Cause location]
>  $base = std::static_pointer_cast<decltype($base)::element_type>($sub);
> 
> [Error Message]
>  $ bison parser.yy; clang++-6.0 -std=c++17 -Wall -Wextra -g -O0 parser.cc
>  parser.yy:87:79: error:
> 'decltype(yylhs.value.as<std::shared_ptr<Baseclass> >())' (aka
> 'std::shared_ptr<Baseclass> &')
>        is not a class, namespace, or enumeration
>                          yylhs.value.as< std::shared_ptr<Baseclass> >
> () = std::static_pointer_cast<decltype(yylh…

Your file:

> rule1[base]
>       : rule2[sub]
>               {
>                       //
>                       // * Upcast from [Subclass] to [Baseclass]
>                       //
> 
>                       // 1) OK
>                       //$base = $sub;
> 
>                       // 2) OK
>                       //$base = std::static_pointer_cast<Baseclass>($sub);
> 
>                       // 3) OK
>                       //auto base{ $base };
>                       //$base = 
> std::static_pointer_cast<decltype(base)::element_type>($sub);
> 
>                       // 4) NG
>                       $base = 
> std::static_pointer_cast<decltype($base)::element_type>($sub);
>               }
>       ;

Wow…  Why are you looking for something so complex?  What is wrong with 1?

You need to get rid of the reference.  That’s what « 
’std::shared_ptr<Baseclass> &’ is not a class, namespace, or enumeration » is 
telling you:

$base = 
std::static_pointer_cast<std::remove_reference_t<decltype($base)>::element_type>($sub);

Cheers!


reply via email to

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