r/cpp • • Oct 25 '26

C++ profiles for initialization and invalidation: WIP implementation prototypes already exist in GCC/Clang

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p4415r0.pdf

In this paper it can be seen some interesting profiles progress for prototypes in Gcc and Clang.

20 Upvotes

29 comments sorted by

View all comments

Show parent comment

7

u/pjmlp Oct 25 '26

Depends on how its rules are configured, it appears very little are enabled on your case.

https://www.sonarsource.com/knowledge/languages/cpp

Regarding annotations, I also don't mind, however that was exactly the arguments used by the profiles crowd against Safe C++, to the point they explicitly mentioned viral annotations should not be part of C++'s vision for its future.

Turns out they need annotations after all.

8

u/c0r3ntin Oct 25 '26

isn't it funny that we have a policy that would prevent us to add const to the language today?

7

u/pdimov2 Oct 25 '26

And noexcept.

4

u/13steinj Oct 25 '26

And override. Or should that have been an attribute? Why are attributes "ignorable" again?

8

u/pdimov2 Oct 25 '26

Override could have been an attribute, yes. It's not viral, not part of the type system, and its only purpose is to emit a diagnostic.

const and noexcept are part of the type system, and are therefore viral.

The interesting thing about noexcept was that it wasn't initially part of the type system (hence viral), and was later changed to be. This is a hint that after we add the annotations that we weren't going to add, we will very likely discover that they belong in the type system as well.

3

u/MFHava WG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 Oct 25 '26

Or should that have been an attribute?

It shouldn't. Attributes are a failed experiment and several of them - at the least no_unique_address and noreturn should be keywords.

3

u/13steinj Oct 25 '26

Wooooosh.

I would argue there are things that should have been attributes and things that shouldn't be, but only because of this idea that attributes are meant to be ignorable, which I think is the root of the issue.

2

u/foonathan Oct 26 '26

I think stuff like deprecated, maybe_unused, etc. which only affect diagnostics are perfectly fine as attributes.

But override and also constinit, which also only affect diagnostics, should have been attributes too.

3

u/MFHava WG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 Oct 26 '26

An invalid override is not a diagnostic, it's a compilation error, that's an important feature.

-2

u/germandiago Oct 25 '26

How viral you think they will be based on your experience?

7

u/pjmlp Oct 25 '26

A lot, as proven by e.g. SAL annotations on VC++, because they need semantics that aren't available in regular C++.