Compilation of derived class from boost::spirit::qi::grammar failed with __declspec( dllexport )

huangapple go评论72阅读模式
英文:

Compilation of derived class from boost::spirit::qi::grammar failed with __declspec( dllexport )

问题

I am trying to implement a class that inherits from boost::spirit::qi::grammar and make it exportable in dynamic library:

#pragma once
#include <impexp.h>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>

using boost::spirit::ascii::space_type;
struct EXPORT_DLLCLASS Grammar : boost::spirit::qi::grammar<char const*, space_type>
{
   Grammar()
       : Grammar::base_type( expr )
   {
   }
   boost::spirit::qi::rule<char const*, space_type> expr, term;
};

I'm using EXPORT_DLLCLASS to specify __attribute__( ( visibility( "default" ) ) ) or __declspec( dllexport ) depending on the platform. Build succeeds under Linux platform, but I have problems with compilation under Windows platform with the following errors:

C:\.conan\oq2odq\1\include\boost/proto/extends.hpp(536,17):  error: call to implicitly-deleted default constructor of 'boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::qi::reference<const boost::spirit::qi::rule<const char *, boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0>, boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> > >, 0>'
              : proto_expr_()
                ^
C:\.conan\oq2odq\1\include\boost/proto/proto_fwd.hpp(377,16):  note: in instantiation of member function 'boost::proto::exprns_::extends<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::qi::reference<const boost::spirit::qi::rule<const char *, boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0>, boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> > >, 0>, boost::spirit::qi::grammar<const char *, boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0>, boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type>, boost::proto::domainns_::default_domain, 0>::extends' requested here
        struct extends;
               ^
C:\.conan\oq2odq\1\include\boost/proto/detail/preprocessed/expr_variadic.hpp(50,49):  note: default constructor of 'expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::qi::reference<const boost::spirit::qi::rule<const char *, boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0>, boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> > >, 0>' is implicitly deleted because field 'child0' has no default constructor
        typedef Arg0 proto_child0; proto_child0 child0;

Build succeeds if EXPORT_DLLCLASS is not specified. Any ideas?

英文:

I am trying to implement a class that inherits from boost::spirit::qi::grammar and make it exportable in dynamic library:

#pragma once
#include &lt;impexp.h&gt;
#include &lt;boost/spirit/include/qi.hpp&gt;
#include &lt;boost/spirit/include/phoenix.hpp&gt;
using boost::spirit::ascii::space_type;
struct EXPORT_DLLCLASS Grammar : boost::spirit::qi::grammar&lt; char const*, space_type &gt;
{
Grammar()
: Grammar::base_type( expr )
{
}
boost::spirit::qi::rule&lt; char const*, space_type &gt; expr, term;
};

I'm using EXPORT_DLLCLASS to specify __attribute__( ( visibility( &quot;default&quot; ) ) ) or __declspec( dllexport ) depending on the platform. Build succeeds under Linux platform, but I have problems with compilation under Windows platform with the following errors:

C:\.conan\oq2odq\1\include\boost/proto/extends.hpp(536,17):  error: call to implicitly-deleted default constructor of &#39;boost::proto::exprns_::expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::spirit::qi::reference&lt;const boost::spirit::qi::rule&lt;const char *, boost::proto::exprns_::expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::spirit::tag::char_code&lt;boost::spirit::tag::space, boost::spirit::char_encoding::ascii&gt; &gt;, 0&gt;, boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type&gt; &gt; &gt;, 0&gt;&#39;
: proto_expr_()
^
C:\.conan\oq2odq\1\include\boost/proto/proto_fwd.hpp(377,16):  note: in instantiation of member function &#39;boost::proto::exprns_::extends&lt;boost::proto::exprns_::expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::spirit::qi::reference&lt;const boost::spirit::qi::rule&lt;const char *, boost::proto::exprns_::expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::spirit::tag::char_code&lt;boost::spirit::tag::space, boost::spirit::char_encoding::ascii&gt; &gt;, 0&gt;, boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type&gt; &gt; &gt;, 0&gt;, boost::spirit::qi::grammar&lt;const char *, boost::proto::exprns_::expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::spirit::tag::char_code&lt;boost::spirit::tag::space, boost::spirit::char_encoding::ascii&gt; &gt;, 0&gt;, boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type&gt;, boost::proto::domainns_::default_domain, 0&gt;::extends&#39; requested here
struct extends;
^
C:\.conan\oq2odq\1\include\boost/proto/detail/preprocessed/expr_variadic.hpp(50,49):  note: default constructor of &#39;expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::spirit::qi::reference&lt;const boost::spirit::qi::rule&lt;const char *, boost::proto::exprns_::expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::spirit::tag::char_code&lt;boost::spirit::tag::space, boost::spirit::char_encoding::ascii&gt; &gt;, 0&gt;, boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type&gt; &gt; &gt;, 0&gt;&#39; is implicitly deleted because field &#39;child0&#39; has no default constructor
typedef Arg0 proto_child0; proto_child0 child0;

Build succeeds if EXPORT_DLLCLASS is not specified.
Any ideas?

答案1

得分: 2

确认,与 MSVC 19.34.31931 x64 (以及 GCC) 并排查看(尽管在 https://compiler-explorer.com/z/o67TYxdnf 上有略有不同的诊断):

C:/data/libraries/installed/x64-windows/include\boost/proto/extends.hpp(558):错误 C2440:'return':无法将类型从 'T *' 转换为 'boost::proto::detail::not_a_valid_type'
其中
[
T=const boost::spirit::qi::reference<const boost::spirit::qi::rule<const char *,boost::spirit::ascii::space_type,boost::spirit::unused_type,boost::spirit::unused_type,boost::spirit::unused_type>>
]
C:/data/libraries/installed/x64-windows/include\boost/proto/extends.hpp(558):注意:无法使用源类型执行构造函数,或构造函数重载分辨模糊
C:/data/libraries/installed/x64-windows/include\boost/proto/extends.hpp(558):注意:在编译类模板成员函数 'boost::proto::exprns_::extends<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term,0>,boost::spirit::qi::grammar<const char *,boost::spirit::ascii::space_type,boost::spirit::unused_type,boost::spirit::unused_type,boost::spirit::unused_type>,boost::proto::domainns_::default_domain,0>::operator boost::proto::detail::not_a_valid_type(void) const' 时
其中
[
T=boost::spirit::qi::reference<const boost::spirit::qi::rule<const char *,boost::spirit::ascii::space_type,boost::spirit::unused_type,boost::spirit::unused_type,boost::spirit::unused_type>>
]
C:/data/libraries/installed/x64-windows/include\boost/spirit/home/qi/nonterminal/grammar.hpp(32):注意:请参考正在编译的类模板实例化 'boost::proto::exprns_::extends<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term,0>,boost::spirit::qi::grammar<const char *,boost::spirit::ascii::space_type,boost::spirit::unused_type,boost::spirit::unused_type,boost::spirit::unused_type>,boost::proto::domainns_::default_domain,0>'
其中
[
T=boost::spirit::qi::reference<const boost::spirit::qi::rule<const char *,boost::spirit::ascii::space_type,boost::spirit::unused_type,boost::spirit::unused_type,boost::spirit::unused_type>>
]

(6):注意:请参考正在编译的类模板实例化 'boost::spirit::qi::grammar'
编译器返回:2

我认为这很可能是编译器问题。我建议将此问题报告给 Boost Proto 维护者:https://github.com/boostorg/proto/issues,以查明是否可以确认问题或提供解决方法。

英文:

Confirmed, see it side-by-side with MSVC 19.34.31931 x64 (and GCC) although with slightly different diagnostics on https://compiler-explorer.com/z/o67TYxdnf:

C:/data/libraries/installed/x64-windows/include\boost/proto/extends.hpp(558): error C2440: &#39;return&#39;: cannot convert from &#39;T *&#39; to &#39;boost::proto::detail::not_a_valid_type&#39;
with
[
T=const boost::spirit::qi::reference&lt;const boost::spirit::qi::rule&lt;const char *,boost::spirit::ascii::space_type,boost::spirit::unused_type,boost::spirit::unused_type,boost::spirit::unused_type&gt;&gt;
]
C:/data/libraries/installed/x64-windows/include\boost/proto/extends.hpp(558): note: No constructor could take the source type, or constructor overload resolution was ambiguous
C:/data/libraries/installed/x64-windows/include\boost/proto/extends.hpp(558): note: while compiling class template member function &#39;boost::proto::exprns_::extends&lt;boost::proto::exprns_::expr&lt;boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term&lt;T&gt;,0&gt;,boost::spirit::qi::grammar&lt;const char *,boost::spirit::ascii::space_type,boost::spirit::unused_type,boost::spirit::unused_type,boost::spirit::unused_type&gt;,boost::proto::domainns_::default_domain,0&gt;::operator boost::proto::detail::not_a_valid_type(void) const&#39;
with
[
T=boost::spirit::qi::reference&lt;const boost::spirit::qi::rule&lt;const char *,boost::spirit::ascii::space_type,boost::spirit::unused_type,boost::spirit::unused_type,boost::spirit::unused_type&gt;&gt;
]
C:/data/libraries/installed/x64-windows/include\boost/spirit/home/qi/nonterminal/grammar.hpp(32): note: see reference to class template instantiation &#39;boost::proto::exprns_::extends&lt;boost::proto::exprns_::expr&lt;boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term&lt;T&gt;,0&gt;,boost::spirit::qi::grammar&lt;const char *,boost::spirit::ascii::space_type,boost::spirit::unused_type,boost::spirit::unused_type,boost::spirit::unused_type&gt;,boost::proto::domainns_::default_domain,0&gt;&#39; being compiled
with
[
T=boost::spirit::qi::reference&lt;const boost::spirit::qi::rule&lt;const char *,boost::spirit::ascii::space_type,boost::spirit::unused_type,boost::spirit::unused_type,boost::spirit::unused_type&gt;&gt;
]
&lt;source&gt;(6): note: see reference to class template instantiation &#39;boost::spirit::qi::grammar&lt;const char *,boost::spirit::ascii::space_type,boost::spirit::unused_type,boost::spirit::unused_type,boost::spirit::unused_type&gt;&#39; being compiled
Compiler returned: 2

I think this is likely a compiler issue. I'd report it with the Boost Proto maintainers: https://github.com/boostorg/proto/issues to see whether they can confirm or suggest a workaround

huangapple
  • 本文由 发表于 2023年3月15日 20:01:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75744429.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定