x3语法中无用的编译器错误 [英] Unhelpful compiler errors in x3 grammar

查看:110
本文介绍了x3语法中无用的编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下用于简单机器人命令语言的Spirit x3语法在Windows Visual Studio 17中生成编译器错误.对于此项目,我需要将警告级别编译为4(/W4),并将警告视为错误(/WX). ).

The following Spirit x3 grammar for a simple robot command language generates compiler errors in Windows Visual Studio 17. For this project, I am required to compile with the warning level to 4 (/W4) and treat warnings as errors (/WX).

警告C4127条件表达式为 常量SpiritTest e:\ data \ boost \ boost_1_65_1 \ boost \ spirit \ home \ x3 \ char \ detail \ cast_char.hpp 29
错误C2039插入":不是以下成员 'boost :: spirit :: x3 :: unused_type'SpiritTest e:\ data \ boost \ boost_1_65_1 \ boost \ spirit \ home \ x3 \ core \ detail \ parse_into_container.hpp 259错误C2039'end':不是成员 'boost :: spirit :: x3 :: unused_type'SpiritTest e:\ data \ boost \ boost_1_65_1 \ boost \ spirit \ home \ x3 \ core \ detail \ parse_into_container.hpp 259错误C2039'empty':不是成员 'boost :: spirit :: x3 :: unused_type'SpiritTest e:\ data \ boost \ boost_1_65_1 \ boost \ spirit \ home \ x3 \ core \ detail \ parse_into_container.hpp 254错误C2039'begin':不属于 'boost :: spirit :: x3 :: unused_type'SpiritTest e:\ data \ boost \ boost_1_65_1 \ boost \ spirit \ home \ x3 \ core \ detail \ parse_into_container.hpp 259

Warning C4127 conditional expression is constant SpiritTest e:\data\boost\boost_1_65_1\boost\spirit\home\x3\char\detail\cast_char.hpp 29
Error C2039 'insert': is not a member of 'boost::spirit::x3::unused_type' SpiritTest e:\data\boost\boost_1_65_1\boost\spirit\home\x3\core\detail\parse_into_container.hpp 259 Error C2039 'end': is not a member of 'boost::spirit::x3::unused_type' SpiritTest e:\data\boost\boost_1_65_1\boost\spirit\home\x3\core\detail\parse_into_container.hpp 259 Error C2039 'empty': is not a member of 'boost::spirit::x3::unused_type' SpiritTest e:\data\boost\boost_1_65_1\boost\spirit\home\x3\core\detail\parse_into_container.hpp 254 Error C2039 'begin': is not a member of 'boost::spirit::x3::unused_type' SpiritTest e:\data\boost\boost_1_65_1\boost\spirit\home\x3\core\detail\parse_into_container.hpp 259

很明显,我的语法有问题,但是错误消息完全没有帮助.我发现,如果我删除语法的最后一行中的Kleene星号(*参数为正参数),错误消失了,但是我得到了很多这样的警告:

Clearly, something is wrong with my grammar, but the error messages are completely unhelpful. I have found that if I remove the Kleene star in the last line of the grammar (*parameter to just parameter) the errors disappear, but then I get lots of warnings like this:

警告C4459声明数字"隐藏全局 声明SpiritTest e:\ data \ boost \ boost_1_65_1 \ boost \ spirit \ home \ x3 \ support \ numeric_utils \ detail \ extract_int.hpp 174 警告C4127条件表达式为常量SpiritTest e:\ data \ boost \ boost_1_65_1 \ boost \ spirit \ home \ x3 \ char \ detail \ cast_char.hpp 29

Warning C4459 declaration of 'digit' hides global declaration SpiritTest e:\data\boost\boost_1_65_1\boost\spirit\home\x3\support\numeric_utils\detail\extract_int.hpp 174 Warning C4127 conditional expression is constant SpiritTest e:\data\boost\boost_1_65_1\boost\spirit\home\x3\char\detail\cast_char.hpp 29

#include <string>
#include <iostream>

#include <boost/config/warning_disable.hpp>
#include <boost/spirit/home/x3.hpp>

namespace x3 = boost::spirit::x3;

//
// Grammar for simple command language
//

namespace scl
    {
    using boost::spirit::x3::char_;
    using boost::spirit::x3::double_;
    using boost::spirit::x3::int_;
    using boost::spirit::x3::lexeme;
    using boost::spirit::x3::lit;
    using boost::spirit::x3::no_case;

    auto    valid_identifier_chars = char_ ("a-zA-Z_");
    auto    quoted_string = '"' >> *(lexeme [~char_ ('"')]) >> '"';
    auto    keyword_value_chars = char_ ("a-zA-Z0-9$_.");

    auto    qual = lexeme [!(no_case [lit ("no")]) >> +valid_identifier_chars] >> -('=' >> (quoted_string | int_ | double_ | +keyword_value_chars));
    auto    neg_qual = lexeme [no_case [lit ("no")] >> +valid_identifier_chars];
    auto    qualifier = lexeme ['/' >> (qual | neg_qual)];

    auto    verb = +valid_identifier_chars >> *qualifier;
    auto    parameter = +keyword_value_chars >> *qualifier;
    auto    command = verb >> *parameter;
    };  // End namespace scl

using namespace std;                                    // Must be after Boost stuff!

int
main ()

{
vector <string> input = 
    {
    "show/out=\"somefile.txt\" motors/all cameras/full",
    "start/speed=5 motors arm1 arm2/speed=2.5/track arm3",
    "rotate camera1/notrack/axis=y/angle=45"
    };

    //
    // Parse each of the strings in the input vector
    //

    for (string str : input)
        {
        auto    b = str.begin ();
        auto    e = str.end ();


        cout << "Parsing: " << str << endl;
        x3::phrase_parse (b, e, scl::command, x3::space);

        if (b != e)
            {
            cout << "Error, only parsed to position: " << b - str.begin () << endl;
            }

        }   // End for

    return 0;
}                           // End main

推荐答案

自Boost 1.65起存在回归,导致某些规则出现问题,这些规则可能传播到容器类型属性中.

There is a regression since Boost 1.65 that causes problems with some rules that potentially propagate into container type attributes.

在没有实际绑定属性的情况下实例化时,它们将分派到错误的重载.发生这种情况时,将有一个名为unused_type的模拟"属性类型.您看到的错误表明unused_type被当作一种具体的属性类型来对待,并且显然不会生效.

They dispatch to the wrong overload when instantiated without an actual bound attribute. When this happens there is a "mock" attribute type called unused_type. The errors you are seeing indicate that unused_type is being treated as if it were a concrete attribute type, and clearly that won't fly.

回归已在 https://github.com/boostorg/spirit/commit/中修复. ee4943d5891bdae0706fb616b908e3bf528e0dfa

通过Boost 1.64编译可以看到它是回归:

You can see that it's a regression by compiling with Boost 1.64:

提升1.65会破坏它 GCC

Boost 1.65 breaks it GCC and Clang again

现在,最新的开发应该可以修复它,但是您可以简单地复制补丁文件,甚至只是7行补丁.

Now, latest develop is supposed to fix it, but you can simply copy the patched file, even just the 7-line patch.

当我链接重复的问题时

All of the above was already available when I linked the duplicate question How to make a recursive rule in boost spirit x3 in VS2017, which highlights the same regression

评论

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆