std::ostringstream with floats behaves different with Embarcadero's CLANG compiler

114 Views Asked by At

I am facing a very odd behaviour of the Embarcadero C++ Builder when using the CLANG compiler.

The example is very simple:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    std::wostringstream woss;

    woss << std::wstring(L"N°1: ") << (int) 1234;
    woss << '\r' << '\n';
    woss << std::wstring(L"N°2: ") << (float) 12.34;

    Memo1->Lines->Add( woss.str().c_str() );

    std::ostringstream oss;

    oss << std::string("N°3: ") << (int) 4567;
    oss << '\r' << '\n';
    oss << std::string("N°4: ") << (float) 45.67;

    Memo1->Lines->Add( oss.str().c_str() );
}

As long as the code is compiled with Borlands classic compiler, it prints exactly what I am expecting:

  • N°1: 1234
  • N°2: 12.34
  • N°3: 4567
  • N°4: 45.67

However, as soon as I switch to the CLANG compiler (bcc32c) (by unchecking "use classic compiler" in the settings dialog) I get the following result:

  • N°1: 1234
  • N°2: -0
  • N°3: 4567
  • N°4: -0

Edit: please ignore the issue with the std::string - the important thing is the false floating point number.

(Not only that the float numbers get crushed, there seems also to be an issue with the interpretation of regular std::string's.)

What is the problem with bcc32c and how can I handle this?

I am using Embarcadero C++ Builder 10.0 (Seattle) for the WIN32 target platform.

thank you

1

There are 1 best solutions below

1
On

Just right after I have written my post I stumbled accross this article on the embarcadero website:

https://quality.embarcadero.com/browse/RSP-12643

It seems to be a well known bug in Embarcadero C++ Builder which has already been fixed in its Update 1 release.

Unfortunately I have no access to this Bugfix because I have "only" purchased the Enterprise Version, but did not pay the extra fee for the subscription pack, which is mandatory when you want to have their bugs fixed.