【问题标题】:Why does __VA_ARGS__ variable macro expansion blows up with GCC 5.1 using forward-declared std::string?为什么 __VA_ARGS__ 变量宏扩展会在 GCC 5.1 中使用前向声明的 std::string 爆炸?
【发布时间】:2015-05-27 11:28:03
【问题描述】:
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

对我来说这看起来不错,但编译器会抱怨。

【问题讨论】:

  • 让我闯入你的系统,输入./../folly并检查代码。
  • 看起来不错的“这个”是什么?您的“问题”中的所有内容都是错误消息的转储。如果看起来不错,那么请保持原样,您将继续收到这些错误。
  • 添加了详细信息作为答案.....

标签: c++11 gcc


【解决方案1】:

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

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

核心问题是 gcc 声称“std::string”是模棱两可的......

但是这听起来很疯狂……好吧,代码做了一个 std::string 的前向声明,但是 dual-abi 98/11 libstdc++ 通过内联命名空间将 std::string 转移到 std::__cxx11::string。因此 gcc 在“来自用户空间的非内联命名空间前向声明”之后开始将 std::string 视为模棱两可。显然这是一种破坏行为,不应转发声明 std::string 或任何 std::* 内容。

【讨论】:

    猜你喜欢
    • 2012-08-01
    • 2014-06-21
    • 1970-01-01
    • 2021-11-01
    • 2011-07-06
    • 2010-09-07
    • 2018-02-17
    • 2021-09-09
    • 2017-12-05
    相关资源
    最近更新 更多