4

我正在构建一对工具gridlab-dHELICS,其中一个使用后者的共享库。在成功构建/安装 HELICS 后编译 gridlab-d 时,出现以下错误:

In file included from /usr/include/c++/7/bits/hashtable.h:35:0,
             from /usr/include/c++/7/unordered_map:47,
             from /home/ericsilk/.local/helics-2.3.0/include/helics/external/cereal/archives/../cereal.hpp:36,
             from /home/ericsilk/.local/helics-2.3.0/include/helics/external/cereal/archives/portable_binary.hpp:32,
             from /home/ericsilk/.local/helics-2.3.0/include/helics/application_api/ValueConverter_impl.hpp:20,
             from /home/ericsilk/.local/helics-2.3.0/include/helics/application_api/ValueConverter.hpp:65,
             from /home/ericsilk/.local/helics-2.3.0/include/helics/application_api/ValueFederate.hpp:11,
             from /home/ericsilk/.local/helics-2.3.0/include/helics/application_api/CombinationFederate.hpp:10,
             from connection/helics_msg.h:21,
             from connection/helics_msg.cpp:16:
/usr/include/c++/7/bits/hashtable_policy.h: In member function ‘std::size_t std::__detail::_Power2_rehash_policy::_M_next_bkt(std::size_t)’:
/usr/include/c++/7/bits/hashtable_policy.h:563:40: error: invalid operands of types ‘std::size_t {aka long unsigned int}’ and ‘double’ to binary ‘operator<<’
   const auto __max_bkt = size_t(1) << (__max_width * __CHAR_BIT__ - 1);
                          ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/hashtable.h:35:0,
             from /usr/include/c++/7/unordered_map:47,
             from /home/ericsilk/.local/helics-2.3.0/include/helics/external/cereal/archives/../cereal.hpp:36,
             from /home/ericsilk/.local/helics-2.3.0/include/helics/external/cereal/archives/portable_binary.hpp:32,
             from /home/ericsilk/.local/helics-2.3.0/include/helics/application_api/ValueConverter_impl.hpp:20,
             from /home/ericsilk/.local/helics-2.3.0/include/helics/application_api/ValueConverter.hpp:65,
             from /home/ericsilk/.local/helics-2.3.0/include/helics/application_api/ValueFederate.hpp:11,
             from /home/ericsilk/.local/helics-2.3.0/include/helics/application_api/CombinationFederate.hpp:10,
             from connection/helics_msg.h:21,
             from connection/init.cpp:16:
/usr/include/c++/7/bits/hashtable_policy.h: In member function ‘std::size_t std::__detail::_Power2_rehash_policy::_M_next_bkt(std::size_t)’:
/usr/include/c++/7/bits/hashtable_policy.h:563:40: error: invalid operands of types ‘std::size_t {aka long unsigned int}’ and ‘double’ to binary ‘operator<<’
   const auto __max_bkt = size_t(1) << (__max_width * __CHAR_BIT__ - 1);
                          ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

调查有问题的标题,这是它抱怨的代码:

// Return a bucket size no smaller than n (as long as n is not above the
// highest power of 2).
std::size_t
_M_next_bkt(std::size_t __n) noexcept
{
  const auto __max_width = std::min<size_t>(sizeof(size_t), 8);
  const auto __max_bkt = size_t(1) << (__max_width * __CHAR_BIT__ - 1);
  std::size_t __res = __clp2(__n);

  if (__res == __n)
__res <<= 1;

  if (__res == 0)
__res = __max_bkt;

  if (__res == __max_bkt)
// Set next resize to the max value so that we never try to rehash again
// as we already reach the biggest possible bucket number.
// Note that it might result in max_load_factor not being respected.
_M_next_resize = std::size_t(-1);
  else
_M_next_resize
  = __builtin_ceil(__res * (long double)_M_max_load_factor);

  return __res;
}

因此,似乎autoof 的类型__max_width被错误地推断为 typedouble而不是size_t(这应该可以从 of 的类型中简单地推断出来std::min<size_t>)。如果我复制标题,然后将其编辑为更改autosize_t,则错误消失,确认这一点。

有趣的是,以下程序编译时没有任何抱怨:

#include <iostream>
#include <algorithm>

int main()
{
    const auto __max_width = std::min<size_t>(sizeof(size_t), 8);
    const auto __max_bkt = size_t(1) << (__max_width * __CHAR_BIT__ - 1);

    std::cout << "__max_width: " << __max_width << std::endl;
    std::cout << "__max_bkt: " << __max_bkt << std::endl;

    return 0;
}

我在 Ubuntu 18.04 上,使用 gcc 7.4.0,虽然我在使用 clang 6.0.0 时遇到了同样的错误。我还确认这发生在 chroot 18.04 环境和另一台运行 WSL Ubuntu 18.04 的机器上。HELICS 是使用 Python 接口和 编译的HELICS_BUILD_CXX_SHARED_LIB,gridlab-d 是按照说明构建的。

很高兴提供额外的信息,任何帮助解决这个问题而不需要用户修改他们的标准标题将不胜感激。

更新:这是根文件的预处理输出helics_msg.cpp,带有它抱怨的特定功能。我没有看到任何会导致错误的宏有趣的业务。完整文件作为 gist位于此处,片段从第 72,722 行开始。它是一个大文件(> 95k 行)。

    std::size_t
    _M_next_bkt(std::size_t __n) noexcept
    {
      const auto __max_width = std::
# 562 "/usr/include/c++/7/bits/hashtable_policy.h"
                                   fmin
# 562 "/usr/include/c++/7/bits/hashtable_policy.h" 3
                                      <size_t>(sizeof(size_t), 8);
      const auto __max_bkt = size_t(1) << (__max_width * 8 - 1);
      std::size_t __res = __clp2(__n);

      if (__res == __n)
 __res <<= 1;

      if (__res == 0)
 __res = __max_bkt;

      if (__res == __max_bkt)



 _M_next_resize = std::size_t(-1);
      else
 _M_next_resize
   = __builtin_ceil(__res * (long double)_M_max_load_factor);

      return __res;
    }
4

1 回答 1

2

gridlab-d 重新定义minfmin

#define min fmin /**< min macro */

因此,无论何时platform.h被包含在内,min都会被fmin. 这只是一个有根据的猜测,因为我手头没有确切的包含图。

不幸的是,std::fmin总是会在整数值上返回一个双精度值。这是 gridlab-d 中的一个缺陷,应该报告——就像你已经做过的那样

于 2019-12-02T16:39:17.930 回答