“无可行转化”与柠檬为ang,但有效的g ++ [英] "no viable conversion" with lemon for clang but valid for g++

查看:197
本文介绍了“无可行转化”与柠檬为ang,但有效的g ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我尝试在我们的项目中加入柠檬图书馆。
大多数开发人员在Windows上,他们使用MSVC编译,但我负责(这部分)使用gcc和clang进行编译。

Currently, I try to incorporate lemon library in our project. Most developers are on Windows, they compile with MSVC, but I am in charge (for this part) to compile with gcc and clang.

gcc不能重现的错误,我设法减少代码:

I came across an error with clang that gcc does not reproduce and I managed to reduce the code:

#include <lemon/dfs.h>

int main() {
    lemon::ListDigraph g{};
    lemon::ListDigraph::Node node = g.nodeFromId(42);
    lemon::Dfs<lemon::ListDigraph> dfs{g};
    lemon::SimplePath<lemon::ListDigraph> path = dfs.path(node);
    return 0;
}  

使用gcc,没有错误。

With gcc, no errors.

/usr/bin/g++-5 -std=c++11 -Wall -O3  -I${SRC_ROOT}/external/lemon/latest -I${BIN_ROOT}/lemon -o ${TMP_ROOT}/core/src/core.cpp.o -c ${SRC_ROOT}/core/src/core.cpp

但是用clang:

/usr/bin/clang++-3.7 -std=c++11 -Wall -stdlib=libc++ -O3 -I${SRC_ROOT}/external/lemon/latest -I${BIN_ROOT}/lemon -o ${TMP_ROOT}/core/src/core.cpp.o -c ${SRC_ROOT}/core/src/core.cpp

In file included from ${SRC_ROOT}/core/src/core.cpp:1:
In file included from ${SRC_ROOT}/external/lemon/latest/lemon/dfs.h:31:
${SRC_ROOT}/external/lemon/latest/lemon/path.h:408:23: error: no viable
      conversion from 'typename PredMapPath<ListDigraph, NodeMap<Arc> >::RevArcIt' to
      'lemon::ListDigraphBase::Arc'
        data[index] = it;;
                      ^~

注意


  • SRC_ROOT BIN_ROOT TMP_ROOT 被替换为可读性

  • 代码片段不会工作,但应该编译(我将更正真正的大代码)

  • 我真的需要真正的源代码的c ++ 11功能。

  • gcc li>
  • clang 3.7

  • .1

  • SRC_ROOT, BIN_ROOT, TMP_ROOT are replaced for readability
  • the snippet source code won't work, but should compile (I will correct the real big code)
  • I really need the c++11 features for the real source code.
  • gcc 5
  • clang 3.7
  • lemon 1.3.1

问题

    $
  • 如何解决这个错误?


  • Did I forget to clang a flag?
  • Does lemon is fully compatible with clang?
  • How to solve this error?

推荐答案

这是一个 double dispatch 相关问题


中的代码 http://lemon.cs.elte.hu/hg/lemon/file/9fd86ec2cb81/lemon /path.h#l443

template <typename CPath>
void buildRev(const CPath& path) {
    int len = path.length();
    data.resize(len);
    int index = len;
    for (typename CPath::RevArcIt it(path); it != INVALID; ++it) {
        --index;
        data[index] = it;; // sic!
    }
}

依赖于此用户定义的 cast-operator

http:// lemon .cs.elte.hu / hg / lemon / file / 9fd86ec2cb81 / lemon / bits / path_dump.h#l139

operator const typename Digraph::Arc() const {
    return path->predMatrixMap(path->source, current);
}

但分配表达式的左手类型

but the left hand type of the assigment expression

http:/ /lemon.cs.elte.hu/hg/lemon/file/9fd86ec2cb81/lemon/list_graph.h#l89

class Arc {
    friend class ListDigraphBase;
    friend class ListDigraph;
protected:
    int id;
    explicit Arc(int pid) { id = pid;}
public:
    Arc() {}
    Arc (Invalid) { id = -1; }
    bool operator==(const Arc& arc) const {return id == arc.id;}
    bool operator!=(const Arc& arc) const {return id != arc.id;}
    bool operator<(const Arc& arc) const {return id < arc.id;}
};

没有自定义赋值运算符,但是clang尝试匹配的单参数自定义ctor对右侧的转换。

doesn't have a custom assignment operator, but a single-argument custom ctor that clang tries to match against conversions of the right side. And fails.

修改上述右侧的 lemon / path.h,第#443行
with a simple explicit cast operator invocation

Patching the right side of above shown lemon/path.h, line #443 with an simple explicit cast operator invocation

   data[index] =  it.operator const typename Digraph::Arc();; 

使代码至少用clang(3.5)编译。

makes the code at least compile with clang (3.5).

柠檬 - 开发者必须决定这是否是期望的行为;应为此提交错误报告。

The lemon-developers must decide whether this is desired behavior; a bug report should be filed for this.

这篇关于“无可行转化”与柠檬为ang,但有效的g ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆