Is this a bug in std::gcd?

dav*_*ave 17 c++ unsigned libstdc++ language-lawyer c++17

I've come across this behavior of std::gcd that I found unexpected:

#include <iostream>
#include <numeric>

int main()
{
    int      a = -120;
    unsigned b =  10;

    //both a and b are representable in type C
    using C = std::common_type<decltype(a), decltype(b)>::type;
    C ca = std::abs(a);
    C cb = b;
    std::cout << a << ' ' << ca << '\n';
    std::cout << b << ' ' << cb << '\n';

    //first one should equal second one, but doesn't
    std::cout << std::gcd(a, b) << std::endl;
    std::cout << std::gcd(std::abs(a), b) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

Run on compiler explorer

According to cppreference both calls to std::gcd should yield 10, as all preconditions are satisfied.

In particular, it is only required that the absolute values of both operands are representable in their common type:

If either |m| or |n| is not representable as a value of type std::common_type_t<M, N>, the behavior is undefined.

然而第一次调用返回2。我在这里错过了什么吗?gcc 和 clang 都是这样的。

Mar*_*low 12

看起来像是 libstc++ 中的一个错误。如果您添加-stdlib=libc++到 CE 命令行,您将获得:

-120 120
10 10
10
10
Run Code Online (Sandbox Code Playgroud)