C++ Logo

std-proposals

Advanced search

Re: New attribute to change the default specifiers and qualifiers

From: Vinícius Costa <ocostavinicius_at_[hidden]>
Date: Wed, 20 Jan 2021 14:33:37 +0100
Hi again

The main goal of the proposal is to change the default specifiers and
qualifiers as per the developer's discretion. The idea of using an
attribute can be changed. We could use another keyword just like enum vs
enum class, for instance.

Anyways... the idea is pretty much the same as the 'epoch' thing. Maybe the
standard could start changing only the defaults, as Arthur said, and then
move on with more difficult/complex stuff.

I'll contact Vittorio Romeo (the guy who proposed the epochs) to try to get
more information on it.

Thanks
Vinicius


On Tue, 19 Jan 2021 at 22:39, Brian Bi via Std-Proposals <
std-proposals_at_[hidden]> wrote:

>
> On Tue, Jan 19, 2021 at 2:28 PM Bo Persson via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> On 2021-01-19 at 15:35, Vinícius Costa via Std-Proposals wrote:
>> > Hi!
>> >
>> > I'd like to propose a new attribute to change the default specifiers
>> and
>> > qualifiers in a given scope.
>> >
>> > Often there's a lot of boilerplate code involved because the default
>> > specifiers and qualifiers are not the "correct" ones (stress on the
>> > quotation marks).
>> > So we need to explicitly make variables const, functions const,
>> noexcept
>> > or final, etc.
>> >
>> > It would be a lot simpler to have a way to switch the default
>> specifiers
>> > and qualifiers, making them more permissive or stricter.
>> >
>> > The idea is to create an attribute that would apply to a scope. With
>> > that, we won't mess with back-compatibility and it would allow an easy
>> > migration towards the new standard.
>> > Furthermore, it would help to enforce some good practices like
>> > const-correctness.
>> >
>> > For example, the following two codes will be the same.
>> >
>> > namespace example [[strict]] {
>> > class Foo : public Bar
>> > {
>> > void do_it(double *ptr) override
>> > {
>> > int x = /* some initialization code here*/
>> > /* more code here */
>> > }
>> > };
>> > }
>> >
>> > namespace example {
>> > class Foo final : public Bar
>> > {
>> > void do_it(double * __restrict ptr) const noexcept override final
>> > {
>> > const int x = /* some initialization code here*/
>> > /* more code here */
>> > }
>> > };
>> > }
>> >
>>
>> The committee seems to not want attributes to change the meaning of
>> programs. If a compiler ignores [[noreturn]] or [[nodiscard]] or
>> [[gnu::special]], the program still works the same (although perhaps
>> using less optimal code).
>>
>
> I've been told that the rule about attributes is not "attributes cannot
> change the meaning of programs" but rather "an implementation that ignores
> the attribute can still be conforming". So you can have a weak form of
> [[strict]]: the compiler can be allowed to warn if a variable's value is
> modified or bound to a non-const reference.
>
>
>>
>> Here [[strict]] really affects the meaning!
>>
>> Also, if I want all the specifiers - except final - how do I do that? :-)
>>
>>
>> Bo Persson
>>
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
>
>
> --
> *Brian Bi*
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2021-01-20 07:33:51