Conversation started Feb 2, 2012 at 10:19.
Feb 2, 2012 10:19
btw, it's impossible to copy parsers in spirit, as impossible to use auto with them
they creates temporaries which dies after assignment
it's like auto foo = string("..").c_str();
@Abyx const auto& expression = expression; // no problem
@sehe try it with string("..").c_str()
@Abyx why? That has no relevance. More like
const auto& foo = string("..") + ".";
std::cout << foo.c_str() << std::endl; // fine
anyway I didn't read that question on spirit and don't know what it's about
@Abyx Ha. I did read it, and can hardly decide what it's about
@Abyx Tell me about this stuff. Yesterday I tracked a spirit karma bug down to a stale temp reference svn.boost.org/trac/boost/ticket/6126#comment:13
Feb 2, 2012 10:28
@sehe can't get how it works %)
@Abyx google (SO) lifetime extension of local const references to temporaries
It's one of the more obscure 'unintuitive' language features, but much of the language (including the whole machinery of expression templates in general) depends on this subtle feature
well.. maybe it's possible to catch spirit parsers with const auto&
I'd usually go for auto&& myself
@Abyx definitely so. Anyways, you can catch them with auto x = some_parser_expression
Feb 2, 2012 10:43
@sehe no, you can't use auto x =... with spirit.
@Abyx Remember, auto is a type specifier, so it declares a variable. So auto x = is not assignment but initialization. Case closed
it works with g++, but fails VC++. because of temporaries
@Abyx mmm. interesting. looking over
That talks about BOOST_AUTO. Is it an issue for MSVC 2010 with auto? It shouldn't be, methinks
there is the issue with auto in VC++
@Abyx oh. makes me happier I'm not using it ATM
@Abyx Link?
Feb 2, 2012 10:50
no link... maybe I still have some code reproducing it..
Oh, I see:
> I just tried this with MSVC10 Beta 2 and boost 1.41 beta 1. It works fantastic in debug builds, but for release builds I get an access violation inside qi::parse, no matter how simple or complex the grammar/rule. I don’t know if this is a codegen bug with MSVC, or if there’s undefined behavior occurring somewhere inside spirit, but this trick is effectively useless for me
That's all quite old of course. I may try my hand at this on my own VS2010 installation later
ah.. just reproduced with the code from that article
#include <boost/spirit/include/qi.hpp>

#include <iostream>
#include <string>

int main()
{
    using namespace boost::spirit::qi;

    auto comment_p = "/*" >> *(char_ - "*/") >> "*/";

    std::string str = "/*This is a comment*/";
    auto iter = str.begin();
    auto ok = parse(iter, str.end(), comment_p);

    return !(ok && iter == str.end());
}
let's try with const auto&..
.. same crash
auto&&?
@DeadMG still crashes
strange, that should be valid
Feb 2, 2012 10:55
@DeadMG depending on the amount of actual UB in the classes under test, but in principle, yes
sure, but I can't imagine any such UB
@DeadMG Just simple things, references to locals, missing returns, illegal casts. The stuff that may 'work' until you push it beyond the limits where compilers usually happened to 'do what you expect'
30 mins ago, by sehe
@Abyx Tell me about this stuff. Yesterday I tracked a spirit karma bug down to a stale temp reference https://svn.boost.org/trac/boost/ticket/6126#comment:13
@sehe ..tell what?
@DeadMG ^^ that is actually quite a good example of it, where it 'usually works' without problem/warning on most compilers, but is fundamentally broken
well, that specific code isn't broken at all
Feb 2, 2012 11:00
@Abyx references, lifetimes, UB in the context of expression templates and TMP
but anyways
right now, I'm more concerned with how incredibly depressing I find university
@DeadMG what code? Do you know exactly how Boost Proto and the Spirit terminals are implemented?
@sehe It doesn't matter.
the code as specified does not invoke UB
whether or not the Proto or Spirit stuff does is their problem, not mine
I believe there is a temporary object with can't be catched with auto&&. It's OK when while parser is an argument to parse or rule ctor, but something temporary destructs after attempt to assign parser to a local variable (or reference)
@Abyx Impossible.
the object is not, and can never be, aware of it's own lifetime
Feb 2, 2012 11:03
well... foo(string("...").c_str()) is OK, right ?
yes
unless foo caches the result, of course
but auto&& x = string("...").c_str(); is not
but you haven't actually taken a reference to the object at all
you've taken a reference to a reference to the object
I think there is something like that
the lifetime extension works exactly as you expect- it extends the lifetime of the result of the expression
Feb 2, 2012 11:05
they create temporary object and catch reference to it's member
well...
what about auto&& x = string(string("...").c_str()) ?
I guess that actually, there's nothing stopping them implementing it that way
I mean, colossally stupid, but nothing stopping it
in any case, you can trivially use a lambda to achieve the same effect
why stupid? spirit was invented before auto era
@DeadMG i never disagreed. See: in principle, yes
11 mins ago, by sehe
@DeadMG depending on the amount of actual UB in the classes under test, but in principle, yes
@Abyx Because C++ expressions should be value typed.
that's how the language is designed to operate
@sehe fair enough
and if they are going to use internal references and pointers, they should be to dynamically allocated memory
no, it hits performance
Feb 2, 2012 11:10
hahahahaha, yeah
anyway you can't meet that issue in C++03
because LL(k) backtracking parsers are so performance-aware
btw, rule with type-erasure probably uses dynamically allocated memory and can catch parsers
inline parser expressions have no need of such things anyway
my own expression template library can construct such things without any need for any references
@DeadMG +1
 
Conversation ended Feb 2, 2012 at 11:12.