【发布时间】:2012-08-21 15:18:53
【问题描述】:
考虑以下代码:
#include <vector>
#include <boost/variant.hpp>
struct foo;
typedef boost::variant<foo> bar;
struct foo
{
std::vector<bar> baz;
};
int main ()
{
foo f;
return 0;
}
使用 Xcode 4.4 在 Mac OS X 上构建(我通过 Homebrew 安装了 boost 1.50.0):
-
clang++ test.cc:没有错误。 -
clang++ -stdlib=libc++ test.cc:没有错误。 -
clang++ -std=c++11 test.cc:没有错误。 -
clang++ -std=c++11 -stdlib=libc++ test.cc:很多错误!
/usr/local/include/boost/type_traits/has_nothrow_constructor.hpp:24:40: error: incomplete type 'foo' used in type trait expression
BOOST_STATIC_CONSTANT(bool, value = BOOST_HAS_NOTHROW_CONSTRUCTOR(T));
^
...snip...
test.cc:10:19: note: in instantiation of template class '...snip...' requested here
std::vector<bar> baz;
^
test.cc:8:8: note: definition of 'foo' is not complete until the closing '}'
struct foo
^
/usr/local/include/boost/mpl/next_prior.hpp:31:22: error: type 'int' cannot be used prior to '::' because it has no members
typedef typename T::next type;
^
test.cc:10:19: note: in instantiation of template class '...snip...' requested here
std::vector<bar> baz;
^
/usr/local/include/boost/mpl/sizeof.hpp:27:20: error: invalid application of 'sizeof' to an incomplete type 'foo'
: mpl::size_t< sizeof(T) >
^~~~~~~~~
test.cc:10:19: note: in instantiation of template class '...snip...' requested here
std::vector<bar> baz;
^
test.cc:8:8: note: definition of 'foo' is not complete until the closing '}'
struct foo
^
...big snip...
8 errors generated.
这里发生了什么?为什么我不能用指定的选项编译它?有没有办法解决这个问题?
【问题讨论】:
-
我认为在
typedef语句中使用未定义类型(foo)是不允许的。 -
你可以试试
typedef boost::variant<boost::recursive_wrapper<foo>> bar;。 -
@LucDanton 谢谢,这就是解决方案!发布答案,我会接受。
标签: c++ boost c++11 compiler-errors clang