[spirit] range_p and signedness of char

The following test program doesn't work like I would expect. #include <iostream> #include <string> #include <boost/spirit/core.hpp> int main () { using namespace std; using namespace boost::spirit; typedef rule<scanner<string::iterator> > rule_t; string s; s += char(0x81); cout << (char(0x80) < char(0xFF)) << endl; rule_t test = range_p(0x80, 0xFF); // (*) parse_info<string::iterator> info = parse(s.begin(), s.end(), test); if (info.hit) cout << "Hit!" << endl; else cout << "Not hit." << endl; return 0; } This is the program output. [pedro@localhost http_client]$ $HOME/.local/gcc-3.4.4/bin/g++ -g -I ../../../.. -Wall -Wextra test.cpp -fsigned-char && ./a.out 1 Not hit. [pedro@localhost http_client]$ $HOME/.local/gcc-3.4.4/bin/g++ -g -I ../../../.. -Wall -Wextra test.cpp -funsigned-char && ./a.out 1 Hit! [pedro@localhost http_client]$ $HOME/.local/gcc-3.4.4/bin/gcc -v Reading specs from /home/pedro/.local/gcc-3.4.4/lib/gcc/i686-pc-linux-gnu/3.4.4/specs Configured with: ../configure --prefix=/home/pedro/.local/gcc-3.4.4 --enable-languages=c,c++ Thread model: posix gcc version 3.4.4 -- Pedro Lamarão

Pedro Lamarão wrote:
The following test program doesn't work like I would expect.
Another form of the same phenomenon: [pedro@localhost http_client]$ cat test.cpp #include <iostream> #include <string> #include <boost/spirit/core.hpp> int main () { using namespace std; using namespace boost::spirit; typedef rule<scanner<string::iterator> > rule_t; string s; s += char(0x80); cout << boolalpha << (char(0x80) < char(0x7F)) << endl; rule_t test_hit = range_p(0x80, 0x7F); parse_info<string::iterator> info = parse(s.begin(), s.end(), test_hit); if (info.hit) cout << "Hit!" << endl; else cout << "Not hit." << endl; return 0; } [pedro@localhost http_client]$ export LANG=C [pedro@localhost http_client]$ $HOME/.local/gcc-3.4.4/bin/g++ -g -I ../../../.. -Wall -Wextra test.cpp -fsigned-char && ./a.out true a.out: ../../../../boost/spirit/core/primitives/primitives.hpp:148: boost::spirit::range<CharT>::range(CharT, CharT) [with CharT = int]: Assertion `!(last < first)' failed. Aborted -- Pedro Lamarão

Pedro Lamarão wrote:
Pedro Lamarão wrote:
The following test program doesn't work like I would expect.
There's a mailing list for spirit: https://lists.sourceforge.net/lists/listinfo/spirit-general Please post there. Thanks! Cheers, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net

Joel de Guzman wrote:
Well, since this is an easy one... Try changing rule_t test_hit = range_p(0x80, 0x7F); to rule_t test_hit = range_p(char(0x80), char(0x7F)); Why? Because range_p(0x80, 0x7F) returns a range<int>, not a range<char> that you are expecting. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
participants (2)
-
Joel de Guzman
-
Pedro Lamarão