I'm using Embarcader C++Builder 10.4.2 with the Clang32 compiler in the IDE to build a VCL Windows 32-bit app.
I used to use ()
initializers for my own TColor
constants when I used the old "Classic" compiler. But the Clang32 compiler doesn't accept this. The Clang32 does accept the same initialize value, but with the C++ 17 (and earlier I think) {}
intializers.
Thanks Remy for advice: I should have included error message in my original posting. The error message reported by the Clang32 compiler is:
[C++ Error] Unit1.cpp(15, 13): cannot initialize a variable of type 'const System::Uitypes::TColor' with an rvalue of type 'int'
I don't understand why Clang32 doesn't like the ()
initializer syntax. Can anyone explain please?
Code example attached:
#include <vcl.h>
const TColor MeterBarBezelRimColour{0x00DDDDDD}; // works with Clang32 - (too "modern" for Classic compiler)
const TColor AnotherBezelRimColour(0x00CCCCCC); // give an error with Clang32 (but does work for Classic compiler).
// WHY is this not accepted by Clang?
Direct initialization doesn't allow an
enum
to be initialized fromint
with(..)
.And since C++17:
list_initialization allows an
enum
to be initialized fromint
with{..}
:Clang is right to accept
{..}
(since C++17) and reject the(..)
construct.Your "Classic" compiler is wrong in that regard (pre-C++17, it should reject both).