English 中文(简体)
部族暴徒? 静态功能称为汇编错误,但不存在结构上的差异。
原标题:clang bug? Ambiguous function call compilation errors, yet there is no amiguity present

过去9个小时,我一直在打着我的头部。

我只与M3处理器(ARM)一道安装了一个新的MacBookPro,并安装了所有的指挥系统工具,包括clang

clang++> is mistaking a bian/code> declaration within a group and its definition out the category as two separate functions, debeit with same signature.

我已把我有问题的法典尽可能减少,以揭露汇编错误的原因。 我相信,这意味着<条码>clang<>/代码>是错的,因为我手写的是C++,但从未这样做——该法典还汇编了对我其他Macs和Loplin的罚款。

我删除并重列了所有指挥系统工具。 Sam。

这里是光带法:

#include <iostream>

namespace gml {
    template <typename T>
    concept Numeric = requires (T value) {
        T{};
        // lots of stuff...
    };
    template <Numeric T>
    class tensor {
        // lots more stuff...
    public:
        tensor() = default; // constructs an empty tensor
        template <Numeric U, Numeric V>
        friend bool operator==(const tensor<U>&, const tensor<V>&);
    };
    template <Numeric U, Numeric V>
    bool operator==(const tensor<U>& t1, const tensor<V>& t2) {
        return true;
    }
}

int main() {
    gml::tensor<long double> t;
    gml::tensor<long double> t3;
    std::cout << std::boolalpha << "t == t3: " << (t == t3) << std::endl;
    return 0;
}

......并在此是我从以上所述汇编错误:

test.cpp:26:54: error: use of overloaded operator  ==  is ambiguous (with operand types  gml::tensor<long double>  and  gml::tensor<long double> )
    std::cout << std::boolalpha << "t == t3: " << (t == t3) << std::endl;
                                                   ~ ^  ~~
test.cpp:15:21: note: candidate function [with U = long double, V = long double]
        friend bool operator==(const tensor<U>&, const tensor<V>&);
                    ^
test.cpp:18:10: note: candidate function [with U = long double, V = long double]
    bool operator==(const tensor<U> &t1, const tensor<V> &t2) {
         ^
1 error generated.

如果有人能让我对此有所了解,我将非常感激。

P.S.,我用<代码>clang++-std=c++20 测试.cpp-o test和运行clang++-version印刷:

Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin23.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
问题回答

这似乎是一种pple,而且该方案非常了解情况。 所有其他3名汇编者(gcc、部族和msvc)compiles 该方案只是罚款。

作为对pple-lang的环绕,你可以仅仅界定班级模板中的朋友模板:

namespace gml {
    template <Numeric T>
    class tensor {
        
    public:
        //other code as before
        template <Numeric U, Numeric V>
        friend bool operator==(const tensor<U>&, const tensor<V>&) //provide definition here inside class
        {
            return true;  
        }
    };
    
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签