C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Versatility -- Classes change at runtime

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sun, 31 Jul 2022 11:03:23 +0100
On Sun, Jul 31, 2022 at 5:43 AM Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>>
> > Start with a new syntax, because right now the vtables are in read-only
> > memory. You must somehow signal the compiler that they should be modifiable.
>
> To be clear: you must signal in code.
>
> Compiler options are out of scope in this list. If you just want a compiler
> extension, make a suggestion to the implementations you care about.


Well then we should discuss whether this should change.

Perhaps a very limited number of compiler options should be part of
the C++ standard. Freedom of syntax could abide the following regex:

       (?:--|-|\/)cplusplus_([A-z0-9_]+)(?:(?:=|:)((?:\+|-)|(?:[:A-z0-9_]+(?:,[:A-z0-9_]+)*))?)

The 1st capture group is the name of the option, and the 2nd capture
group is what you've set it to. See this regex in action with examples
here:

        https://regex101.com/r/PgCjUS/1

This regex accepts the following three syntaxes:

        -cplusplus_polymorphic_class=::MyNamespace::MyClass,::OtherNamespace::OtherClass
        --cplusplus_polymorphic_class=::MyNamespace::MyClass,::OtherNamespace::OtherClass
        /cplusplus_polymorphic_class:::MyNamespace::MyClass,::OtherNamespace::OtherClass

If you're willing to suffer the overhead of having all classes be
polymorphic then do this:

        --cplusplus_polymorphic_class=+

And if you want to turn the feature off completely then do:

        --cplusplus_polymorphic_class=-

These command line options are accumulative from left to right, so if you do:

        --cplusplus_polymorphic_class=BufferedOstream
--cplusplus_polymorphic_class=HyperOstream

then it's the same as doing:

        --cplusplus_polymorphic_class=BufferedOstream,HyperOstream

However if you use "+" to turn it on fully, or if you use "-" to turn
it off fully, then these two options wipe out the previous one's. So
for example if you do:

        my_favourite_compiler --cplusplus_polymorphic_class=+
--cplusplus_polymorphic_class=BufferedOstream
--cplusplus_polymorphic_class=-

Then it's the same as doing:

        my_favourite_compiler --cplusplus_polymorphic_class=-

So maybe we should have compiler options in future C++ standards to
achieve higher levels of versatility.

By the way, C++ programmers writing code today in 2022 have to use
some compiler options to get their standard-compliant code to compile.
For example if I want to use "std::thread" in the GNU compiler (g++)
then I have to compile with "-pthread".

Received on 2022-07-31 10:03:33