On Sunday, 26 April 2015 at 20:21:32 UTC, Ali Çehreli wrote:
Yes, a bug for floating types only. It seems that not the common type but the first type is used among floating point types. I wrote a short program to prove it to myself:

import std.traits;
import std.typetuple;
import std.format;

auto foo(A, B)(int n)
{
    if (n) {
        return A(0);

    } else {

        return B(0);
    }
}

void main()
{
    alias types = TypeTuple!(float, double, real);

    foreach (A; types) {
        foreach (B; types) {
            alias ReturnType = typeof(foo!(A, B)(0));

            pragma(msg, format("%s %s -> %s%s",
                               A.stringof, B.stringof,
                               ReturnType.stringof,
(is (ReturnType == CommonType!(A, B))
                                ? ""
                                : " <-- BUG")));
        }
    }
}

float float -> float
float double -> float <-- BUG
float real -> float <-- BUG
double float -> double
double double -> double
double real -> double <-- BUG
real float -> real
real double -> real
real real -> real

Ali

https://issues.dlang.org/show_bug.cgi?id=14506

Reply via email to