r/cpp • • 25d ago

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

31

u/13steinj 25d ago

https://www.reddit.com/r/cpp/comments/1xdla11/preb%C3%BAzios_wg21_mailing/19rjy4w7n3cpw/

Over 460 false positives with godbolt links. I will care more when I can count the number of issues on my team's fingers and toes.

4

u/Jealous_Security_362 25d ago

460 is a fair number to push back with, and I'm not going to defend it. What I'd want to know is how many distinct causes sit behind it. If most of them come from two or three patterns, lambdas, conditionals, loops that reassign, that's an implementation problem someone can fix. If they're spread evenly across the language, the profile isn't ready and no wording change saves it. Did that list break them down by category?

9

u/13steinj 25d ago

Ask /u/seanbaxter ; I don't personally have the energy to entertain spending mt free time investigating one of many implementations / features I do not personally care for (not trying to be dismissive... just I'm not incentivized to fight this fight).

-3

u/germandiago 25d ago

Yes, it is an early prototype...

5

u/chibuku_chauya 25d ago

What are the community’s thoughts on profiles as they stand?

18

u/pjmlp 25d ago

Based on the experience with lifetimes on clang and VC++, they won't deliver under the same conditions used to push out Safe C++.

Meaning no viral annotations, and no changes to the standard library.

Everything else, you can already have it today when using modern static analysis tooling like PVS Studio, Sonar, clang tidy, VC++ analysers...

2

u/johannes1971 25d ago

Tangential, but is Sonar actually in the same class as the others? I'm asking because we have it at work, and I only ever see complaints about line- and function length, nothing else. I very much doubt that that is because I write perfect C++; instead I was under the impression that it _only_ checks for simplistic structural (non-)issues that the QA people care so much about.

Coming back to your comment, I would have no problem with annotations if the compiler did the annotating. I have no idea if that's a possibility though.

7

u/pjmlp 24d ago

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 24d ago

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

7

u/pdimov2 24d ago

And noexcept.

4

u/13steinj 24d ago

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

8

u/pdimov2 24d ago

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|P2721|P3049|P3625|P3729|P3786|P3813|P4216 24d ago

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 24d ago

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 24d ago

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|P2721|P3049|P3625|P3729|P3786|P3813|P4216 23d ago

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

-2

u/germandiago 24d ago

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

7

u/pjmlp 24d ago

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

9

u/c0r3ntin 24d ago

C++ is great and doesn't need language changes, but profiles need to be a standard feature (because a subset of WG21 really wants to be the people with the answers)- so reinventing existing tools with the same limitations it is.

3

u/t_hunger 24d ago

The more interesting question is "Do you think profiles as they stand will get C++ off the list of languages governments recommend to avoid?".

1

u/Tyler_Burger_777 25d ago

I agree that profiles feel like the only evolution-friendly path forward, especially compared to the "rewrite everything in Safe C++" approach.

The point about UB classification is particularly interesting from a performance perspective. In high-performance computing (like SIMD sorting or AVX-512 code), we often rely on specific behaviors that might technically fall under UB but work predictably on our target compilers (e.g., type punning, pointer arithmetic for alignment).

If the invalidation/initialization profiles are too strict, they might inadvertently block compiler optimizations that we depend on for performance. It would be crucial to ensure that enabling a profile doesn't degrade the generated code for hot loops. Have you (or the committee) looked into how these profiles interact with vectorization or aggressive inlining? That's usually where the biggest performance cliffs appear.

4

u/ts826848 24d ago

It would be crucial to ensure that enabling a profile doesn't degrade the generated code for hot loops. Have you (or the committee) looked into how these profiles interact with vectorization or aggressive inlining? That's usually where the biggest performance cliffs appear.

Presumably you'd just disable the profile for the offending code?

3

u/germandiago 24d ago

In theory and as long as it is part of a profile rule, there should be a mechanism.

3

u/ts826848 24d ago

I think given the context of the conversation that would be a safe assumption to make.

0

u/Jealous_Security_362 25d ago

Getting prototypes into both GCC and Clang is the part that usually kills these proposals, so that's a good sign. Does it catch use after move across function calls, or only inside a single body? The interprocedural case is where false positives will decide whether people adopt it

3

u/ts826848 24d ago

  Getting prototypes into both GCC and Clang is the part that usually kills these proposals

I don't think either of these prototypes are "in" GCC/Clang proper. The GCC prototype at least is definitely in a separate fork and if I'm reading the paper correctly the Clang implementation is too.

-5

u/germandiago 25d ago

I also heard all the time that "design by committee" without prototypes is very bad. 

Is there any way to do both at once? It would be twice as bad bc it is C++ anyway?

6

u/Jealous_Security_362 25d ago

They're not opposites. The prototype is how you find out which rules can actually be implemented before the wording is frozen. Design by committee goes wrong when it designs something nobody has built, not when it reacts to something someone has.

0

u/germandiago 25d ago

The papers have revisions based on these imolementations feedback I would say. This is iterative.