2

安装 ubuntu 18.04 后,我无法构建扭矩软件。Ubuntu 16.04 没有出现这样的错误。

make[4]: Entering directory '/home/socrates/torque-6.1.2/src/lib/Libattr'
g++ -DHAVE_CONFIG_H -I. -I../../../src/include  -I../../../src/include
`xml2-config --cflags` -Wno-implicit-fallthrough -std=gnu++11  
-g -fstack-protector -Wformat -Wformat-security -DFORTIFY_SOURCE=2
-W -Wall -Wextra -Wno-unused-parameter -Wno-long-long -Wpedantic -Werror -Wno-sign-compare
-MT req.o -MD -MP -MF .deps/req.Tpo -c -o req.o req.cpp  

req.cpp: In member function ‘int req::set_from_submission_string(char*, std::__cxx11::string&)’:  
req.cpp:1057:23: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]  

    else if (current != '\0')

                        ^~~~  
Makefile:521: recipe for target 'req.o' failed  
make[4]: *** [req.o] Error 1  
4

1 回答 1

4

Ubuntu 16.04 中的 g++ 默认为 C++03 编译器,如果参数-std未指定另一个 C++ 较新版本。Ubuntu 18.04 中的 g++ 默认为 C++14 编译器,指针与int(cast from char '\0') 的比较无效。

我认为指针if (current != '\0')所在的代码current是可疑的,可能是一个错误。它应该是

if (*current != '\0')

或者

if (current != 0)  // before C++11
if (current != nullptr) // since C++11
if (current) // for both before and since C++11

没有上下文 (MCVE) 就不可能决定要么使用current要么*current必须使用。

更新

我查看了 torque-6.1.2 代码。肯定有bug。

char       *current;
// ...
this->task_count = strtol(submission_str, &current, 10);
//...
if (*current == ':')
  current++;
else if (current != '\0') // BUG is here, it must be (*current != '\0')
  {
  error = "Invalid task specification";
  return(PBSE_BAD_PARAMETER);
  }
于 2018-05-12T06:09:53.853 回答