Skip to content

<complex>: invalid conversions allowed #1256

@fsb4000

Description

@fsb4000

Describe the bug
Our inheritance implementation is allowing this to compile when it shouldn't.

Command-line test case

C:\Temp>type main.cpp
#include <complex>
#include <cassert>

int main ()
{
    const std::complex<long double> cd(2.5, 3.5);
    std::complex<float> cf = cd;
    assert(cf.real() == cd.real());
    assert(cf.imag() == cd.imag());
}

C:\Temp>cl /EHsc /W4 /WX main.cpp
Оптимизирующий компилятор Microsoft (R) C/C++ версии 19.28.29213 для x64
(C) Корпорация Майкрософт (Microsoft Corporation).  Все права защищены.

main.cpp
Microsoft (R) Incremental Linker Version 14.28.29213.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:main.exe
main.obj

C:\Temp>main.exe
C:\Temp>type main.cpp
#include <complex>
#include <cassert>

int main ()
{
    const std::complex<double> cd(2.5, 3.5);
    std::complex<float> cf = cd;
    assert(cf.real() == cd.real());
    assert(cf.imag() == cd.imag());
}

C:\Temp>cl /EHsc /W4 /WX main.cpp
Оптимизирующий компилятор Microsoft (R) C/C++ версии 19.28.29213 для x64
(C) Корпорация Майкрософт (Microsoft Corporation).  Все права защищены.

main.cpp
Microsoft (R) Incremental Linker Version 14.28.29213.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:main.exe
main.obj

C:\Temp>main.exe
C:\Temp>type main.cpp
#include <complex>
#include <cassert>

int main ()
{
    const std::complex<long double> cd(2.5, 3.5);
    std::complex<double> cf = cd;
    assert(cf.real() == cd.real());
    assert(cf.imag() == cd.imag());
}

C:\Temp>cl /EHsc /W4 /WX main.cpp
Оптимизирующий компилятор Microsoft (R) C/C++ версии 19.28.29213 для x64
(C) Корпорация Майкрософт (Microsoft Corporation).  Все права защищены.

main.cpp
Microsoft (R) Incremental Linker Version 14.28.29213.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:main.exe
main.obj

C:\Temp>main.exe

Expected behavior
Compile time error

STL version
Microsoft Visual Studio Community 2019 Preview Version 16.8.0 Preview 2.0

Additional context
Skipped libcxx test

# STL bug: Our inheritance implementation is allowing this to compile when it shouldn't.
std/numerics/complex.number/complex.special/double_long_double_implicit.compile.fail.cpp FAIL
std/numerics/complex.number/complex.special/float_double_implicit.compile.fail.cpp FAIL
std/numerics/complex.number/complex.special/float_long_double_implicit.compile.fail.cpp FAIL

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions