Reputation: 183
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?
Upvotes: 3
Views: 620
Reputation: 218138
Direct initialization doesn't allow an enum
to be initialized from int
with (..)
.
And since C++17:
list_initialization allows an enum
to be initialized from int
with {..}
:
Otherwise, if T is a enumeration type that is either scoped or unscoped with fixed underlying type, and if the braced-init-list has only one initializer, and if the conversion from the initializer to the underlying type is non-narrowing, and if the initialization is direct-list-initialization, then the enumeration is initialized with the result of converting the initializer to its underlying type.
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).
Upvotes: 2