auto typed parser expressions in file scope

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

auto typed parser expressions in file scope

Nick Stokes
I have a code bit that looks like this

namespace {
auto rule1 = double_ % ',';
// other rules
}

void foo (const std::string& s) {
     std::vector<double> v;

     // [1] parse using the file-scope rule 
     phrase_parse( s.begin(), s.end(), rule1, space, v );

     // [2] parse using inline rule
     //phrase_parse( s.begin(), s.end(), double_%',', space, v );    

     // [3] parse using function scope rule
     //auto rule = double_%',';
     //phrase_parse( s.begin(), s.end(), rule, space, v );    
}


The compilation is fine with either one of the 3-versions.  But the first version generates a run-time segv, somewhere down in the stack of phrase_parse. The other two are fine at runtime.  If I change auto to qi::rule<iter, space_type> in the file scope, then the segv goes away. 


For the purposes of this reaching out for help, I attempted to isolate the code into a self-contained unit.  However, the I am unable to reproduce the segv in this manner.  So I apologize I am unable to post a proper reproducible example.  

This was using Boost 1.49, with Visual Studio 2012.  I attached the relevant stack trace. 

Is there some inherent problem with using auto with parser expressions like this?

Thanks,
Nick


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general

auto-rule-stack-trace.txt (23K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: auto typed parser expressions in file scope

Lee Clagett-2
On Thu, Apr 30, 2015 at 4:23 PM, Nick Stokes <[hidden email]> wrote:
I have a code bit that looks like this

namespace {
auto rule1 = double_ % ',';
// other rules
}

void foo (const std::string& s) {
     std::vector<double> v;

     // [1] parse using the file-scope rule 
     phrase_parse( s.begin(), s.end(), rule1, space, v );

     // [2] parse using inline rule
     //phrase_parse( s.begin(), s.end(), double_%',', space, v );    

     // [3] parse using function scope rule
     //auto rule = double_%',';
     //phrase_parse( s.begin(), s.end(), rule, space, v );    
}


The compilation is fine with either one of the 3-versions.  But the first version generates a run-time segv, somewhere down in the stack of phrase_parse. The other two are fine at runtime.  If I change auto to qi::rule<iter, space_type> in the file scope, then the segv goes away. 


For the purposes of this reaching out for help, I attempted to isolate the code into a self-contained unit.  However, the I am unable to reproduce the segv in this manner.  So I apologize I am unable to post a proper reproducible example.  

This was using Boost 1.49, with Visual Studio 2012.  I attached the relevant stack trace. 

Is there some inherent problem with using auto with parser expressions like this?

Thanks,
Nick


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general



Lee

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: auto typed parser expressions in file scope

Nick Stokes

On Thu, Apr 30, 2015 at 4:38 PM, Lee Clagett <[hidden email]> wrote:
On Thu, Apr 30, 2015 at 4:23 PM, Nick Stokes <[hidden email]> wrote:
I have a code bit that looks like this
[..]




Ah, thanks!  So it seems like  something like the following would work on C++11: 

auto rule1 = boost::proto::deep_copy( double_ % ',' ); 

?


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: auto typed parser expressions in file scope

Michael Powell-2
On Thu, Apr 30, 2015 at 5:35 PM, Nick Stokes
<[hidden email]> wrote:

>
> On Thu, Apr 30, 2015 at 4:38 PM, Lee Clagett <[hidden email]> wrote:
>>
>> On Thu, Apr 30, 2015 at 4:23 PM, Nick Stokes
>> <[hidden email]> wrote:
>>>
>>> I have a code bit that looks like this
>>> [..]
>>
>>
>> I think you have hit this scenario described on stackoverflow : [
>> http://stackoverflow.com/questions/24318149/segmentation-fault-only-in-optimized-builds-in-boost-spirit-qi-grammar-initializ
>> ].
>>
>
>
> Ah, thanks!  So it seems like  something like the following would work on
> C++11:
>
> auto rule1 = boost::proto::deep_copy( double_ % ',' );
>
> ?

I haven't tested myself, but certainly the last time I checked,
generous use of the auto keyword is the going recommendation it seems.
In circumstances where you need the type for key reasons, of course,
go ahead and strongly type, otherwise, auto is perfectly legitimate,
AFAIK.

> ------------------------------------------------------------------------------
> One dashboard for servers and applications across Physical-Virtual-Cloud
> Widest out-of-the-box monitoring support with 50+ applications
> Performance metrics, stats and reports that give you Actionable Insights
> Deep dive visibility with transaction tracing using APM Insight.
> http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
> _______________________________________________
> Spirit-general mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/spirit-general
>

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general