为什么__VA_ARGS__变量宏扩展使用前向声明的std :: string与GCC 5.1一起爆炸?

时间:2015-05-27 11:28:04

标签: c++11 gcc

In file included from ./../folly/FBString.h:59:0,
                 from ./../folly/Conv.h:27,
                 from detail/CacheLocality.cpp:23:
./../folly/Traits.h:155:38: error: template argument 1 is invalid
   struct IsRelocatable<  __VA_ARGS__ > : std::true_type {};
                                      ^
./../folly/Traits.h:221:3: note: in expansion of macro 'FOLLY_ASSUME_RELOCATABLE'
   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1, T2, T3>) }                   \
   ^
./../folly/Traits.h:427:1: note: in expansion of macro 'FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3'
 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(std::basic_string);
 ^
./../folly/Traits.h:171:48: error: template argument 1 is invalid
   struct has_nothrow_constructor<  __VA_ARGS__ > : ::boost::true_type {};
                                                ^
./../folly/Traits.h:224:5: note: in expansion of macro 'FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR'
     FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(__VA_ARGS__<T1, T2, T3>) }
     ^
./../folly/Traits.h:427:1: note: in expansion of macro 'FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3'
 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(std::basic_string);
 ^
./../folly/Traits.h:155:38: error: template argument 1 is invalid
   struct IsRelocatable<  __VA_ARGS__ > : std::true_type {};
                                      ^
./../folly/Traits.h:213:3: note: in expansion of macro 'FOLLY_ASSUME_RELOCATABLE'
   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1, T2>) }               \
   ^
./../folly/Traits.h:429:1: note: in expansion of macro 'FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2'
 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::list);
 ^
./../folly/Traits.h:171:48: error: template argument 1 is invalid
   struct has_nothrow_constructor<  __VA_ARGS__ > : ::boost::true_type {};
                                                ^
./../folly/Traits.h:216:5: note: in expansion of macro 'FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR'
     FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(__VA_ARGS__<T1, T2>) }
     ^
./../folly/Traits.h:429:1: note: in expansion of macro 'FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2'
 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::list);
 ^
Makefile:1395: recipe for target 'detail/CacheLocality.lo' failed

对我来说,这看起来很好,但编译器抱怨。

1 个答案:

答案 0 :(得分:0)

所以上面的代码很简单。作为参考,愚蠢的是可以查找的开源代码,它在这里:

https://github.com/xnox/folly/commit/ca2e9c7f1b6bf92f1f67ae627692547710932577

核心问题是gcc声称“std :: string”是暧昧的......

然而,这听起来很疯狂......好吧,代码执行了std :: string的前向声明,但是双abi 98/11 libstdc ++通过内联命名空间将std :: string转移到std :: __ cxx11 :: string。因此,在“非内联命名空间转发从用户空间声明”之后,gcc开始将std :: string视为暧昧。显然这是破坏的行为,并且不得转发声明std :: string或任何std :: *的东西。