inconsistent parser behaviour

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

inconsistent parser behaviour

Philipp Schwaha-2
Hi Guys,

I encountered inconsistent behaviour when refactoring a parser.
The extraction of the code is in the attachment and should be self

The essence is that I have a simple parser consisting of:
 byte_(0xFF) >> byte_
It behaves differently depending on if this is passed into the parse
function inline or if it is returned via a function.

such as:
auto generate() -> decltype(byte_(0xFF) >> byte_) {
  return (byte_(0xFF) >> byte_) ;

or wrapped in a function object:
struct dummy {
  using type = decltype(byte_(0xFF) >> byte_) ;
  type generate() const {
    return (byte_(0xFF) >> byte_) ;
} ;

When testing using input of the form:
  std::array<unsigned char, 2> const connect_test = { { 0xFF, 0x00 } } ;

the inline specification always succeeds parsing, but for the returned
values this is not (always) the case, surprisingly g++ and clang++ do
not agree on behaviour.

 parse(start, end(connect_test), (byte_(0xFF) >> byte_)) ;
 parse(start, end(connect_test), wrap.generate()) ;
 parse(start, end(connect_test), generate()) ;

g++ -Wall -pedantic -std=c++11 submit.cpp -o submit && ./submit
1       0
function object
0       2
0       2

clang++ -Wall -pedantic -std=c++11 submit.cpp -o submit && ./submit
1       0
function object
1       0
0       2

I have the feeling I'm going into undefined behaviour land somewhere.
Any ideas what I missed and how to get consistent behaviour, preferably
so that it parses successfully.

Cheers & thanks

Check out the vibrant tech community on one of the world's most
engaging tech sites,!
Spirit-general mailing list
[hidden email]

submit.cpp (1K) Download Attachment