r/cpp • • Oct 08 '26

CppCon Profiles for simplicity and guarantees - Bjarne Stroustrup - CppCon 2026

https://youtu.be/41USGJaGsAo?si=VyfCWkbUK5mhxe7G
53 Upvotes

141 comments sorted by

65

u/seanbaxter Oct 09 '26 edited Oct 10 '26 • Popcorn

The implementation that Bjarne teases is available on Compiler Explorer. You can try it. This is slideware, not software. It breaks all the time. There's no way this can ever be turned on with actual code.

Here's a sampling of the infinite variety of false positives. Basically nothing in <algorithm> compiles under the profile. https://godbolt.org/z/Ts7rbrc1c

std::unique_ptr<int> make_owned() {
    // error: returning a pointer or container that may hold a pointer
    // to a local, not permitted under the 'std::invalidation' profile
    // (wrap in 'std::no_dangling' if this is provably safe)
    return std::make_unique<int>(42); // false positive
}

make_unique takes a reference to a temporary and returns a pointer, so the profile assumes they're related and flags it. This is the quality of reasoning that local analysis without lifetime parameters gets you. It could never be any other way.

Most of false positives are fundamentally unavoidable, however I think a couple are quality of implementation issues:

int different_vector_types(std::vector<int>& a, std::vector<double>& b) { 
    auto it = a.begin(); 
    b.clear(); 
    // error: use of a value bound to 'a', potentially invalidated 
    // by an earlier mutation of 'b', not permitted under the 
    // 'std::invalidation' profile
    return *it; // false positive
}

Why does clearing b invalidate the iterator into a?

struct Handle {
    int& value;
 
    int& get() const {
        // returning a pointer or container that may hold a pointer to
        // a local, not permitted under the 'std::invalidation' profile
        // (wrap in 'std::no_dangling' if this is provably safe)
        return value; 
    }
};

I'm guessing the implementation doesn't actually model lifetimes even within a function.

Two years ago I documented why existing C++ can't be checked for safety. The biggest reason is that exclusivity of mutable references is not upheld. https://www.circle-lang.org/draft-profiles.html

If theory isn't your thing, and you want a practical demonstration of how safety profiles failed, try Bjarne's favored implementation. Throw an LLM at it. This is a totally predictable disaster. Now that there's an implementation we're past the "wait and see" stage. Why are we still pretending that this will make C++29?

27

u/seanbaxter Oct 09 '26 • Bravo

If you prefer an example application, here's a simple word-counting demonstration:
https://godbolt.org/z/Yz5cnqYn6

This alone raises 7 false positives. Good luck getting the number of annotations to 1 in 1000 lines.

6

u/VilleVoutilainen Oct 10 '26

Thanks for the bug reports, Sean. I made some changes according to them.

You're right on the part that if the goal were ironclad gapless security, we would need lifetime knowledge. And we need those anyway, for other reasons. Whether we'll get that within that particular profile remains to be seen, discussions about that are ongoing.

Some proponents of this facility are over-advertising it. There are others who will inject realism into it, it's a work-in-progress.

You can also report bugs as issues on the GCC clone on github, if you wish. Such bug reports are most welcome.

24

u/seanbaxter Oct 10 '26

Hi Ville. These aren't bugs that can be fixed. Before wasting precious tokens, could you address this minimized example:

int f(int& x, std::vector<int>& vec);

int main() {
  std::vector<int> vec { 1 };
  f(vec[0], vec);   // #1

  int x = 2;
  f(x, vec);        // #2
}

Does the safety profile permit calls #1 and #2 to f or not?

If f is safe to call, in either place, depends how f is defined:

// f1 requires x not alias vec
int f1(int& x, std::vector<int>& vec) {
  // If x aliases vec, then vec.push_back may invalidate x.
  vec.push_back(1);
 
  // Loading x is UB!
  return x;
}

// f2 requires x alias vec
int f2(int& x, std::vector<int>& vec) {
  // UB if &x is not a pointer into vec's allocation.
  return (int)(&x - vec.data());
}

If f is defined like f1, then call #1 is UB and call #2 is okay. If f is defined like f2, then call #2 is UB and call #1 is okay. This puts it outside of local analysis.

Rust has a tidy solution. On the caller side:

  • Call #1 would not compile, because that would violate exclusivity.
  • Call #2 would compile.

On the callee side:

  • f1's parameters cannot alias, because there is no mutable aliasing. The precondition is satisfied.
  • f2's precondition cannot be satisfied, but that's okay, because pointer arithmetic is unsafe, and would require entering an unsafe-block.

How does the invalidation profile handle calls #1 and #2? This isn't about "ironclad gapless security." I'm just trying to call one function.

2

u/SirClueless Oct 12 '26

I don't understand how you could possibly implement profiles as described without generalized runtime liveness tracking a la Fil-C or something.

1

u/CreativeAlbatross319 Oct 11 '26

A solution could be assuming alias by default, which is also the default behaviour of compilers. Thus, the definition of f1 (callee) reports the error and f2 is still safe and doesn't report an error (not considering the pointer arithmetic). At the call-site, error should also be reported for #2, but not for #1, as #2 is using an un-alias argument.

Now to make f1 definition safe, suppression must exist for the x argument, explicitly stating that x is assumed to be an un-alias of other arguments. Now the call site reports an error for #1 but not for #2, as the first argument for #1 is an alias to the second argument.

3

u/kronicum Oct 12 '26

"assuming alias by default" is the only sensibly practical solution for C++

3

u/ts826848 Oct 10 '26

You can also report bugs as issues on the GCC clone on github, if you wish.

Just to make sure I'm looking in the right place, is this the clone in question?

5

u/VilleVoutilainen Oct 10 '26

Yes.

3

u/tcbrindle Flux Oct 12 '26

FYI, Github issues don't seem to be enabled on that repo

4

u/VilleVoutilainen Oct 12 '26

That should be fixed now.

5

u/duneroadrunner Oct 11 '26

So the int f(int& x, std::vector<int>& vec); example function Sean gave demonstrates that it's not safe have a reference to an element in a vector while simultaneously having a non-const reference to the vector that can be used to invoke a resizing operation on the vector. Or at least it's not safe to pass those two references across a function boundary through which information about their aliasing would be lost.

I'd like to point out a further issue, which is that you cannot in the general case even reliably determine at compile-time whether two references alias. For example, consider this example:

std::vector<std::vector<int>> vvi = foo1();
size_t i = foo2();
size_t j = foo3();

std::vector<int>& vec = vvi.at(i);
int& x = vvi.at(j).front();
f(x, vec);

In this example do x and vec alias? (I.e. does x refer to an integer that is an element of vec?) It is not practical to determine whether they do or not at compile-time, and it's not practical to just prohibit all cases where you can't make the determination at compile-time because there are plenty of legitimate algorithms where this will be the case.

So the way Rust deals with this is that it prohibits mutable aliasing for all references (so the prohibition survives through function boundaries) and it provides various run-time mechanisms for ensuring the prevention of mutable aliasing (such as std::RefCell<>, std::Cell<>, slice splitting, etc.) when static analysis is not up to the job.

Now a safe version of C++ may not have to adopt the exact same policies as Rust, but fundamentally you're not going to be able to avoid those two features: i) aliasing restrictions/information that survives through function boundaries, and ii) run-time mechanisms to prevent aliasing in the many cases where a static analyzer cannot practically determine the aliasing status.

The scpptool approach to memory-safe C++ that I work on is based on the recognition of these two realities. However, it is also based on the premise that, for memory safety, a Rust-style universal prohibition of mutable aliasing is somewhat overkill. (Though there are arguments for benefits apart from just memory safety.) Which is fortunate, as the universal prohibition of mutable aliasing is not really compatible with existing C++ code and library interfaces.

In particular, I claim that the memory-safety danger related to mutable aliasing (in modern C++) is limited to interaction with dynamic owning pointers (like std::unique_ptr<>) and containers (like std::vector<>). And specifically limited to the subset of operations that can arbitrarily end the life of an owned object at its current location in memory. (Operations like vector::push_back(), vector::clear(), etc.) It turns out that such operations are generally avoided in performance-sensitive inner loops anyway, so I argue that it is reasonable even to accept the addition of some modest run-time overhead to these (often already potentially expensive) operations in order to achieve memory safety.

Adding the run-time safety mechanisms to the dynamic owning pointers and containers does mean switching to alternative (safe) implementations provided by the scpptool solution. While there are some differences, the vast majority of their interface is compatible with (code using) their standard library counterparts.

Now, I understand the aversion to the introduction of slightly incompatible standard library container alternatives with built-in (theoretical) additional run-time overhead in some operations. It probably wouldn't be wise to embrace such an alternative before being convinced it's necessary. But I am suggesting that the scpptool approach is a concrete solution (as far as I know, along with Fil-C, one of the only ones) for C++ memory safety that might be useful to understand and measure against. For example, here is an scpptool version of the word counting example. Note the modesty of the changes required.

3

u/seanbaxter Oct 11 '26

memory-safety danger related to mutable aliasing (in modern C++) is limited to interaction with dynamic owning pointers (like std::unique_ptr<>) and containers (like std::vector<>). And specifically limited to the subset of operations that can arbitrarily end the life of an owned object at its current location in memory.

This is definitely not true. Mutable aliasing is a danger for reasons beyond lifetimes.

int values[] = {1, 2, 3, 4, 5};

// UB because the source and dest overlap
std::copy(values, values + 4, values + 1);

If you want it Rustier, imagine copying one overlapping slice into another. There's no wrappers, dynamic allocations, etc. We rely on exclusivity to prevent all varieties of UB.

3

u/duneroadrunner Oct 11 '26

Right. But isn't that an implementation/policy choice of std::copy(), not necessarily an intrinsic property of its interface? I mean, if we consider the simplest implementation

template< class InputIt, class OutputIt >
OutputIt copy( InputIt first, InputIt last, OutputIt d_first ) {
    auto current = first;
    auto d_current = d_first;
    while (current != last) {
        *d_current = *current;
        ++current;
        ++d_current;
    }
}

As long as the iterators are bounds checked (including the != operator), then overlapping ranges would be a code correctness issue, but not an intrinsic memory safety one I think. So, for example, the hardened standard library could adopt a policy of ensuing that std::copy() doesn't introduce any new UB.

And while the cppref page states that overlapping ranges are UB, does any unexpected behavior happen in practice? I'm not immediately seeing how that might come about. (Your simple example seems to behave as one might expect.) I mean, if I'm correct about the std::copy() interface not being intrinsically memory unsafe, I'm not even (immediately) seeing what performance optimizations might need to be sacrificed in the name of memory safety. (Though I might just need an ELI5.)

I mean the question we're ultimately interested in here I think is whether or not the modern C++ interface is inherently memory unsafe, and can the code built on that interface be used to build memory-safe executables. And if not, why not exactly? And what is the minimum deviation from that interface required to achieve memory safety (while maintaining acceptable performance).

4

u/seanbaxter Oct 11 '26

> However, it is also based on the premise that, for memory safety, a Rust-style universal prohibition of mutable aliasing is somewhat overkill. 

What I'm doubtful of is that a form of weaker restrictions canl provide equivalent safety coverage at preferable cost. By making slice references exclusive, for example, Rust avoids requiring bounds checks (with a runtime cost) in many situations, as in that copy. It's high safety coverage with low cost. The less-than-universal coverage you talk about, as with group borrows, is hard to write down, prove soundness, and to use at scale.

2

u/duneroadrunner Oct 12 '26

It's high safety coverage with low cost.

Well, my impression is that in practice modern compiler optimizers will dispose of most of any theoretical performance difference. That said, the I don't see the (theoretical unoptimized) performance argument favoring universal prohibition of mutable aliasing. The way I see it, in this era of brutally expensive cache misses, performance-sensitive data will tend to be stored and accessed in contiguous ranges. (Structure-of-arrays vs array-of-structures, right?) And in the case of contiguous accesses, the check for overlap only needs to be done once at the beginning of the data access loop. That is, the theoretical additional run-time check occurs outside of the hot inner loop and so presumably would have no significant performance impact. (And to the extent that the overlap check may occur in an outer loop, it would presumably be perfectly branch-predicted.)

On the other hand, in Rust, copying the value of an element of a container to another element, or swapping two elements (determined at run-time) in the same container can theoretically incur additional run-time overhead (like a range split which incurs a bounds check, or a clone() which incurs an additional intermediate copy/move) to establish that the elements don't alias, right? Now, most inner loops won't have such operations, but it strikes me as quite plausible that some could.

I think a significant factor in the relative performance issue might be the fact that at the hardware level (and I'm not the expert in this area) there isn't really any performance penalty for mutable aliasing, right? Like, as far as I know, x[i] = x[j] won't be any slower or less reliable if i and j are equal, or might be equal. So at the lowest levels, in some sense the hardware is not taking full advantage of the aliasing information that Rust can provide. And yet maintaining that aliasing information has a cost. Sometimes a run-time cost.

The less-than-universal coverage you talk about, as with group borrows, is hard to write down, prove soundness, and to use at scale.

Yeah, but in terms of mutable aliasing, I think a lot of the advantage is undermined by presence of std::RefCell<>s and std::Cell<>s. Like, if I hold a reference to an i32, then I as a programmer can call a function and know that when that function returns, the value of the i32 will not have been modified. But that nice property doesn't extent to generic programming, right? I mean if I hold a reference to an object of some generic type and I call a function, the value of the object might end up having been changed depending on whether it contains std::RefCell<>s and/or std::Cell<>s.

And with respect to scalability, the problem is that the ergonomic costs of restrictions can scale up along with the code base. (This may be less of an issue for all the future AI Rust programmers :) Like, I seem to recall a post from a while ago where a game programmer was talking about having a widely accessed state object that had grown to have many components. But if you're making deeply nested function calls, and a deeply nested function needs to reference a component of the state object, then a reference to that component needs to be borrowed and passed through all the functions in the call stack. It ended up that the shallower functions were borrowing an unwieldy number of references to different components to make available to all the various deeper functions. So much so that they ended up just passing a reference to an std::RefCell<> containing the state object. And then eventually finding out at run-time the places where they inadvertently held on to an std::RefCell<>::RefMut too long. The programmer seemed to feel that all this ceremony wasn't actually preventing any real bugs. Just an anecdote, but I don't know if there's real data available on the ergonomic costs.

Personally, at this point I'm not sure if the advantages of a universal-prohibition-of-mutable-aliasing policy outweigh the costs. I don't have a strong opinion either way. But I don't think the argument is strong enough yet to justify wholesale abandonment of the old interfaces and codebases. (Although it does feel like the bots might make language migration costs low enough to make this all moot before long. ¯\(ツ)/¯ )

2

u/pdimov2 Oct 11 '26

Unlike memcpy, std::copy isn't UB for any overlap, just for some of them, and that's fixable by just removing the UB and defining the behavior as the straightforward copy loop.

std::vector::insert is a bit less trivial, but we can define the behavior there as well.

1

u/tialaramex Oct 12 '26

If you want it Rustier, imagine copying one overlapping slice into another

In Rust if we know it's two [potentially overlapping] sub-ranges of the same slice we can explicitly tell the standard library we want to do this : values.copy_within(0..4, 1);

5

u/tcbrindle Flux Oct 11 '26

Two years ago I documented why existing C++ can't be checked for safety. The biggest reason is that exclusivity of mutable references is not upheld

For what it's worth, I'm less convinced these days that exclusivity is an absolute requirement for compile-time memory safety.

The Carbon team is using an approach they call "place sets" which would allow safe mutable aliasing; they gave a video presentation about it recently (slides here).

There's also this project which wants to allow mutable aliasing in a way that is compatible with Rust code, using similar ideas (this time called "group borrowing").

9

u/seanbaxter Oct 11 '26 edited Oct 11 '26

There's no implementation. I personally don't believe the presentation they have is sound.

Edit: I left a comment here, with an example that I think would require exclusivity. I really don't understand how group borrows is supposed to get around that.

4

u/tcbrindle Flux Oct 12 '26

I left a comment here, with an example that I think would require exclusivity. I really don't understand how group borrows is supposed to get around that.

For std::copy, I believe you'd write the "no overlap" condition with Carbon as something like:

fn Copy[IIter: Iterator, OIter: Iterator]
    (in_begin: IIter(^C), in_end: IIter(^C), out_begin: OIter(^));

That is, you'd specify that in_begin and in_end share the same place set (here named C) and so must originate from the same container, and that out_begin has a distinct (unnamed) place set which does not overlap with C.

Or am I misunderstanding the requirement here?

2

u/foonathan Oct 10 '26

Why does clearing b invalidate the iterator into a?

That part I actually like. Without a dont_alias annotation, the only sensible thing is too assume that clearing b invalidates a.

13

u/pdimov2 Oct 10 '26

It doesn't because one is vector<int> and the other is vector<double>. There's no way for a and b to refer to the same vector, and there's no way for double[] to own anything, including a. (Actually there is a way but we can probably assume, for the purposes of the profile, that nobody uses double[] as raw storage. What sane person would return double from their type_with_alignment primitive? Suprisingly many.)

Make b a vector<X>, where X contains a pointer member, or is incomplete, and (most) bets are off. Then heuristics come into play. Does the char const* in X provide storage for a? Who knows.

3

u/tcbrindle Flux Oct 11 '26

It doesn't because one is vector<int> and the other is vector<double>

This happens to be true only because of the prohibition on adding specialisations to namespace std though, right? Otherwise, we could have something like

template <>
struct my::vector<double> { 
    my::vector<int> ints;

    void clear() { ints.resize(0); }
};

my::vector<double> vec = get_vector();
different_vector_types(vec.ints, vec);

So unless it gives special treatment to std templates, I think the analyser must assume potential aliasing here?

4

u/pdimov2 Oct 11 '26

I don't think specializations are a problem here because while compiling different_vector_types the compiler knows what the types actually are (in particular, whether vector<double> has been specialized or not.)

3

u/ts826848 Oct 11 '26 edited Oct 11 '26

Oh, that is evil! And a little concerning in that I don't think you even need specialization?

[[profiles::enforce(std::invalidation)]];

#include <vector>

struct wrapper {
    std::vector<int> ints;
    void maybe_reallocate() { this->ints.resize(20); }
};

int f(std::vector<int>& a, wrapper& b) { 
    auto it = a.begin(); 
    b.maybe_reallocate(); 
    return *it;
}

int main() {
    wrapper w{std::vector{0, 1, 2, 3, 4}};
    auto i = f(w.ints, w);
    return (i == 0);
}

Looks like the profiles implementation on Godbolt has been updated so that different_vector_types is now accepted, but it seems the new implementation is now too permissive as it fails to reject the above program which ASan flags as executing a heap-use-after-free.

I don't know if there's a general solution here. I think looking through type definitions to try to find potential aliasing would work for this specific example, but if opaque/incomplete types are involved at any point (e.g., PIMPL) then I think all bets are off.

4

u/foonathan Oct 11 '26

I don't know if there's a general solution here

Rust wouldn't allow the call-site: you can't bind a mutable reference to a part of a struct and to the whole struct at the same time.

2

u/ts826848 Oct 11 '26

Right, sorry, I meant that I don't know if there is a "profiles/SD-10-compatible" general solution.

4

u/pdimov2 Oct 11 '26

Right, it's too permissive now. Instead of wrapping, one can just derive, which makes the problem even more obvious.

https://godbolt.org/z/s7vahxhWs

[[profiles::enforce(std::invalidation)]];

#include <vector>

struct wrapper: public std::vector<int> {};

int f(std::vector<int>& a, wrapper& b) { 
    auto it = a.begin(); 
    b.push_back( 7 );
    return *(++it);
}

int main()
{
    wrapper w{std::vector{0, 1, 2, 3, 4}};
    auto i = f(w, w);
    return (i == 0);
}

The analysis needs to take into account the fact that T& and U& can alias if T has a subobject of type U. (They can also "alias" if T has a subobject of type U* but that's another story.)

4

u/ts826848 Oct 11 '26

The analysis needs to take into account the fact that T& and U& can alias if T has a subobject of type U.

Right, and I feel you'd probably need a pretty expansive definition of "subobject" as well in that you'd need to (recursively?) follow pointers to other types that themselves may have U subobjects if you want to be confident in catching potential aliasing.

I want to say that opaque pointers a la PIMPL might throw a wrench into that though?

3

u/pdimov2 Oct 11 '26

I want to say that opaque pointers a la PIMPL might throw a wrench into that though?

They most certainly do, but we aren't even there yet.

3

u/pdimov2 Oct 13 '26

Right, and I feel you'd probably need a pretty expansive definition of "subobject" as well in that you'd need to (recursively?) follow pointers to other types that themselves may have U subobjects if you want to be confident in catching potential aliasing.

Here's an example why the "recursively" is needed:

https://godbolt.org/z/c4z9bGh4W

int f( std::vector<std::vector<int>>& v, int& x )
{
    v.clear();
    return x;
}

std::vector<std::vector<int>> contains a pointer to std::vector<int>, which contains a pointer to int.

I suspect that we'll need to annotate the owning pointers in some way, because otherwise, under the conservative assumption that all pointers are potentially owning, the false positive rate will be much too high.

8

u/Dragdu Oct 10 '26

I see only the declaration on mobile Reddit, but the two vectors cannot legally alias in standard C++, so they can be assumed not to.

1

u/foonathan Oct 10 '26

Ahh, missed the different types

25

u/t_hunger Oct 08 '26 edited Oct 08 '26

I see how profiles do not make a new language, as a profile is not supposed to change the meaning of code as written (as long as it does not have undefined behavior). But I would definitely call something where parts of the language are rejected by the compiler a dialect of that language.

Having an (user-) extensible set of profiles that each can limit the language and inject code to runtime-check something is going to make it damn hard to enforce the part where it says valid programs do not change their meaning.

I am not looking forward to remember which constructs are forbidden by which profile, where in the code base which restrictions apply and which guarantees I get from which code and how expensive the code injected by which profile is and whether it conflicts with code injected by another profile -- and how all this differs between compiler implementations.

34

u/James20k P2005R0 Oct 09 '26

The combinatorial explosion of profiles and the ways that they don't interact well together is going to be a nightmare to maintain

2

u/oscardssmith Oct 13 '26

I'm betting they won't because no compiler will actually support any of them.

3

u/smdowney WG21, Text/Unicode SG, optional<T&> Oct 11 '26

Modules and exported inline . All answers seem to be wrong for someone.

6

u/James20k P2005R0 Oct 11 '26

What I mean more is that when we have 10+ profiles, which may be turned on or off arbitrarily at various points in the code, its going to be pretty suboptimal from a maintainability perspective

The current plan for safety seems to be to add an increasing number of rules to attempt to cover every case, presumably all of which can be turned off as they'll create false positives, and the interaction between all of these profiles is going to be very non trivial

4

u/tialaramex Oct 12 '26

For anybody who thinks this avenue is worth pursuing it will be important to check that Bjarne's wording is not actually his intent. P3984 talks of "code that needs to violate that guarantee". This could just be inadvertently sloppy wording in a place where it matters, but it could equally be sloppy thinking and that's a problem.

Software composition is practical in Rust because all your Rust code obeys the same guarantees. The unsafe keyword does not somehow ignore those guarantees, instead this is a "with great power comes great responsibility" situation in which you are trusted to ensure you deliver on the guarantees even though unsafe has granted powers which the compiler can't check were used correctly.

A question which helps cut through the mist on this stuff is the nexus of responsibility question. In Rust when things go wrong I can (modulo compiler bugs etc.) point at an unsafe block which is faulty because it did not uphold Rust's guarantees. In some cases a real world solution will be somewhere else but the nexus of responsibility will always be in such a block. Can code using profiles always point at such a nexus when things go wrong or is it sometimes "your fault" for holding it wrong in which case you have not delivered safety ?

4

u/pdimov2 Oct 12 '26

Responsibility is not the main problem with the profiles framework when it comes to code reuse. The main problem is that when the set of possible profiles is open and potentially ever expanding, you can't write code in a way that is guaranteed to compile when profiles are enforced (there's no known way of holding it right.) (You can't put the appropriate suppressions there either because you don't know in advance what they need to be.)

An additional problem is that if a profile is not rigidly defined, in purely "frontend" terms (if it relies on information from the back end), you can't write the code "correctly" either because whether it will trip up the profile would depend on the compiler and the version and possibly on the build options and on the code complexity.

We've already seen this exact movie, and it's called -Werror. We know how it ends.

There are scenarios where the profiles framework is a good fit; e.g. in automotive code where the company controls the entire code base and does not admit third party dependencies, they can just put profiles::enforce(misra::v3::strict) in all their translation units and call it a day. But that's not the majority of C++ development.

7

u/VilleVoutilainen Oct 12 '26

The additional problem suggested in the middle paragraph is too unlikely to be a concern. Every one of the people working on profiles knows not to do that, not in the design, not in the spec, not in the implementation.

1

u/GabrielDosReis Oct 12 '26

... code reuse.

Are you thinking of copy-and-paste, or code that takes dependencies on libraries/packages along with their settings that provide context?

2

u/pdimov2 Oct 12 '26

I'm thinking of the library code being taken as a dependency.

1

u/GabrielDosReis Oct 12 '26

I'm thinking of the library code being taken as a dependency.

Without its declared flags and context?

3

u/pdimov2 Oct 12 '26

I don't know what "declared flags" means in this context. What are the declared flags of a Boost library?

Are you driving at the fact that an import directive can have a local [[profiles:]] annotation? If so, there are two problems with that. One, it doesn't even seem to support suppress.

The primary problem with integrating third party code in your code base that needs to compile cleanly under profile my::pumpkin is that the third party has never heard of the my::pumpkin profile and therefore could not possibly have ensured compilation under it. Consequently, when import-ing that third party code, you often need to suppress my::pumpkin.

But even if we accept that import is extended to allow suppression, the second problem is a more fundamental one. It's that whether a profile is enabled or not is essentially a build option and build options do not belong in source files.

Whether a particular dependency should have a particular profile suppressed or enforced is knowledge that is properly supplied by whoever supplies the dependency (he might be the only one who's heard of the profile, he's the only one that knows what particular version of the dependency is used, and whether or how it's been patched.)

When executable A imports library B imports library C, in general the author of B has no idea what he needs to enforce or suppress in his import directives. The person assembling A from its constituent parts knows.

→ More replies

-8

u/germandiago Oct 09 '26 edited Oct 09 '26

I think this can be handled at the toolchain config level + a package manager. Will need the care to not put on you neck a profile that makes something incompatible on a per library basis losing a guarantee but that is true also for things like the ABI change in MSVC debug/release toolchains.

I wonder which profiles you foresee to be incompatible among them for mainstream uses bc I would say that lifetime, type and bounds seem to not have big conflicts (that I can think of).

13

u/t_hunger Oct 09 '26 edited Oct 09 '26

How would a package manager handle that?

Assume you have a profile A that checks that function a() is not used and a profile B that injects a call to a() as part of a runtime check. A package manager will happily install both next to each other unless someone manually added a "A and B conflict with one another". You can not expect that with user-supplied plugins where the authors may or may not know of the existence of the other plugin.

If the two packages conflict, then you can not install both profiles at the same time into the same compiler, even though you may never use them together in one project. That is inconvenient.

If the two packages do not conflict and end up being used together, what happens then? I guess it depends on the implementation of the compiler running the profiles? Either profile A will pass and lie as profile B injected a call to a() after all or the build fails for totally non-obvious reasons, or something else happens? The profile framework paper is entirely silent on what should happen if profiles conflict with each other AFAICT. I guess we will find out when (not if) the first profiles of the open set we are going for actually conflict. This is actually dangerois:: you can not trust random plugins to not break other plugins. Who will dare to run user-provided profiles then?

But yes, we can hope the standardized profiles will actually work together (minus bugs of course).

-5

u/germandiago Oct 09 '26 edited Oct 09 '26

A and B conflict with each other is the same conflict you have mixing release and debug MSVC runtimes today and you also solve it yourself.

So you need some kind of metadata, yes.

I do not trust random packages or random sources to install from internet. Do you? Your employer would not be happy you do. Even in apython or Rust or any other language. It is just dangerous for many reasons.

So I do not see what the drama is about you just cannot choose and consume packages willy-nilly in all circumstances, that is a very big hole for chain supply attacks.

Yes I just think it is doable but not only that: 50, 60, 90% of work delievered as progress is made means 50, 60, 90% better in some way for some measurement of that (of course this depends entirely of how expensive a mistake is affordable, but you get my point). Not worse than before starting to add them for sure anyway.

15

u/t_hunger Oct 09 '26

Profile A silently dropping the thing it is supposed to guarantee is a lot worse than the debug/release problem.

Contracts get a lot of push back due to now being ablento guarantee their assertions get triggered. You can reliably fix that by setting the right policy and rebuilding the entire dependency chain.

That seems harmless compared to the pain conflicting profiles can cause.

-5

u/germandiago Oct 09 '26 edited Oct 09 '26

The debug/release problem is a crash in your face and UB. How it can be worse than disabling a safety?

Your code does not become incorrect, it just suppresses a guarantee. That is strictly more benign butIdk if what you say can possibly happen.

Anyway, my point is that some metadata is needed. I think Gabriel Dos Reis had a talk about exactly mix and match profiles (and the framework in general).

Did you take a look at it? Bc I recall he was thinking of these problems.

13

u/t_hunger Oct 09 '26 edited Oct 09 '26

I read the papers, they are pretty blank on the topics up to the last mailing posted here.

-3

u/germandiago Oct 10 '26

I am talking about a talk Gabrield Dos Reis gave in a conference.

That is not a wg21 paper. I am not sure when a new paper will come but it definitely explainednresesrch done after the last profiles framework papers published.

19

u/Minimonium Oct 09 '26

Honestly the source based "Profiles" framework must be the funniest thing since that paper that proposed writing credentials in source files for package management.

The level of granularity combined with an open set is quite a mix that will force you to touch a massive amount of source files for everything.

Then I look at [[mcvs::no_unique_address]], some of the claims in this video, the story with the lifetime framework that went nowhere as far as industry experience goes - and I can only say "good luck" and hope Bjarne actually sees something no one else is seeing that he just failed to communicate so far.

5

u/ts826848 Oct 09 '26

  since that paper that proposed writing credentials in source files for package management.

Wait, what paper was this? I want to read more!

7

u/Minimonium Oct 09 '26

1

u/13steinj Oct 09 '26

This system differs from modules in that it is all about source code distribution

I don't want to be disparaging to the authors, but they wrote the paper in 2016.

The solution is git. Or tarballs! That's it. Package managers do a lot more than just distribution, hopefully of more than just of source code.

1

u/FrogNoPants Oct 14 '26

Profiles seems like such an obvious dead end that I'm kinda stumped why anyone is pushing it

16

u/praesentibus Oct 08 '26

Truth in advertising: "Profiles for placating people who want safety with some bullshit".

9

u/KFUP Oct 08 '26

How is using something like [[profiles::enforce(initialization)]] to prohibit uninitialized variables "bullshit" exactly?

36

u/CocktailPerson Oct 09 '26

Because -Werror=uninitialized solved that problem ages ago.

Because C++26 solved it again quite recently.

Because uninitialized variables are a de minimis share of memory safety bugs.

Let me know when profiles can prevent iterator invalidation, use-after-free, and double-free. That's when they won't be bullshit.

-4

u/johannes1971 Oct 09 '26

Iterator invalidation and use after free are serious issues, but double-free was solved in 2011 with move semantics.

13

u/13steinj Oct 09 '26

Double-free is definitely not "solved." Greatly reduced, yes, but not solved. I'm not even talking about people writing C-style pointer-y code in C++, there are still just cases where even with move semantics you can end up screwing up (especially in multithreaded code).

-4

u/serviscope_minor Oct 09 '26

>Double-free is definitely not "solved." Greatly reduced, yes, but not solved. I'm not even talking about people writing C-style pointer-y code in C++

Nothing is going to help those people. If you're mucking with such things in 2026 it's by choice. Hand those people Rust and they'll wrap everything in unsafe and go back to their happy place of pointer-bashing.

>There are still just cases where even with move semantics you can end up screwing up (especially in multithreaded code

Move semantics don't save you from race conditions. I'd argue that's not a double free problem: you get a drievby double free as a consequence of UB from having two threads bash on the same part of without protections. In other words it's a somewhat randomized symptom of a completely different problem. You might equally well have got a segfault or read random garbage from having the wrong pointer in one of your classes. As such I think that's not much to do with the normal "double free" problem which is what you get from mucking with new and delete by hand.

Beyond that I don't think I've ever seen a double free in good RAII code even before move semantics.

6

u/13steinj Oct 09 '26

Nothing is going to help those people. If you're mucking with such things in 2026 it's by choice. Hand those people Rust and they'll wrap everything in unsafe and go back to their happy place of pointer-bashing.

I will repeat

I'm not even talking about people writing C-style pointer-y code in C++

Beyond that I don't think I've ever seen a double free in good RAII code even before move semantics.

There's something between "good RAII" and "C-style" that still exists for better or worse, and move semantics do not save you from accidentally double freeing across two threads. Doesn't even have to be an actual race condition.

2

u/johannes1971 Oct 10 '26

It sounds very much like you are acquiring the resource once, and then sharing it across two owning threads. Does C++ provide a tool for that situation? As a matter of fact, it does: shared_ptr, introduced in C++11.

So the tools are there. It is still up to you to choose to use them, just like you'll have to opt in to whatever safety profiles the future might bring.

1

u/13steinj Oct 10 '26

A simple shared pointer is not good for every possible usecase of sharing resources across threads. Sometimes you don't control the API giving you resources. Sometimes the performance profile of using a shared pointer here and calling it a day is not an acceptable outcome.

1

u/CocktailPerson Oct 10 '26
  1. It definitely wasn't.
  2. RAII helped, but move semantics didn't add anything to help with double-free that basic C++98 RAII didn't already provide.

-3

u/johannes1971 Oct 10 '26

Ok, interesting take. So why was autoptr deprecated, then, in your opinion?

4

u/CocktailPerson Oct 10 '26

auto_ptr was problematic because it was confusing that the copy constructor transferred ownership.

But the operative concept is that it did transfer ownership. You're probably imagining that copying an auto_ptr resulted in two objects that would both delete their "owned" pointer on destruction, causing a double-free. But that's not the case; auto_ptr's copy constructor worked just like unique_ptr's move constructor, but didn't force you to write std::move to make it obvious that a move was happening.

So, auto_ptr resulted in nullptr derefs when people didn't realize that ownership had been transferred away by a copy. It did not result in any more double-frees than unique_ptr.

-7

u/cr1mzen Oct 08 '26

Perhaps anything less than full memory safety is seen as “wimping out”. A pretence of safety. Especially since RUST already proved that memory safety is technically achievable. And the sudden supposed “consensus” that we are not allowed to make major changes to the language, yet somehow templates, reflection and constepr dont count.

11

u/AnyPhotograph7804 Oct 09 '26

They have nothing against major changes as long as the backwards compatibility or zero-overhead-principle are not violated.

11

u/pjmlp Oct 09 '26

ISO C++23 has a few examples where C++98 features are no longer available, backwards compatibility violated.

The ISO C++23 standard library has a few examples where third party implementations do it better, zero overhead principle violated.

It seems that these principles are only uphold when it is convenient.

6

u/johannes1971 Oct 09 '26

I think you need to look at the scale of changes here. That a very small change is ok, does not imply that a massive change is therefore also ok.

8

u/13steinj Oct 09 '26

I think both you and /u/pjmlp are being unrealistic here.

Let's be honest: SD-10 is very clearly an exclusionary circus disguised as a backwards compatibility policy. From 11 to 26 there have been breaking changes here and there, some larger than others. But some definitely of meaningful size.

Continuing with honesty: we all know this language tries very hard not to change. Many are in the camp that it should break more not less. To be honest I do not understand the argument for trying to never change. If you want your old software to work that's fine-- stick to your old compiler and settings. If you want to upgrade your compiler, well, every time I do I have had to go through and fix a lot of things anyway to the point where it's up to a month of churn. Breaking ABI would not increase this churn for me. Breaking API... would, but how much depends significantly on the API break. Changing a name of something would be de minimis. Making every case of an old thing not work and there's a clear transformation to "new thing" is fine. I actually struggle to come up with an example that would annoy me / add a significant amount of work to my plate. Maybe changing a default parameter?

1

u/johannes1971 Oct 09 '26

You are talking on the level of changing a name or a default parameter. Meanwile, u/cr1mzen is asking for a complete overhaul of the entire syntax.

My "old compiler" is msvc6.0. Is that still going to work today, you think? How many new libraries could I use using that compiler? How many old libraries would have been ported? Do you really think that each C++ version should be completely independent from the others: new syntax, new compilers, new libraries, just change everything every three years? How would we be able to write software that lasts for decades, what language should we use for that?

1

u/cr1mzen Oct 09 '26

MSVC is not a great example, they broke the ABI on me more than once. Plus i assume that C++ would remain backward compatible and memory safety would remain opt-in. i.e. if you didn’t want it, you would not have to use it

0

u/johannes1971 Oct 09 '26

So why were you complaining about Stroustrups opt-in proposal to be too wimpy, then?

And this is about language syntax, not about what it compiles into. ABI doesn't come into it.

→ More replies

1

u/13steinj Oct 09 '26

is asking for a complete overhaul of the entire syntax.

I don't think that's true, or at least it's optional / additive syntax?

My "old compiler" is msvc6.0.

Yes that's too old.

Do you really think that each C++ version should be completely independent from the others: new syntax, new compilers, new libraries, just change everything every three years?

No and that's a complete charicature of the point and you know it. Because msvc6.0 isn't 3 years old, it's 28.

How would we be able to write software that lasts for decades, what language should we use for that?

You can use msvc6.0! Just don't expect to use new libraries written post 2003. I'd expect you to take the updates as they come if you wanted to use new libraries.

0

u/johannes1971 Oct 09 '26

I don't think that's true, or at least it's optional / additive syntax

To me the comment seemed to indicate that he considered the backward compatible solution proposed by Stroustrup too 'wimpy' and was asking for a more comprehensive language change.

No and that's a complete charicature of the point and you know it. Because msvc6.0 isn't 3 years old, it's 28.

It seems that way because, apparently, you cannot look beyond the moment. But three years from now we will be having the same discussion, now with some other super important subject. And again, three years after that, and again after that.

You can use msvc6.0! Just don't expect to use new libraries written post 2003. I'd expect you to take the updates as they come if you wanted to use new libraries.

And how's that going to work out, you reckon? Especially given that it doesn't even install on any modern Windows version. Are we going to be maintaining some stockpile of computers from back in the day, get new customers to buy some Pentiums just to run the old Windows version to run our software? Or are we going back to rewriting the whole thing every three years?

Oh, and we do this in the name of safety - discarding three decades of software improvements in the process...

-1

u/AnyPhotograph7804 Oct 09 '26

Scala does, what you suggest here: they break the binary and sourcecode compatibility very often. And what happens? Nobody uses it. Because nobody has the time and patience to rewrite a whole application because a new version of the programming language came out.

And no, "stick to your old compiler and settings" is not a solution. Because if you break the binary compatibility, older applications will stop working on newer operating systems. So "stick to your old compiler and settings" will turn into "stick to your old compiler and settings and OS".

4

u/13steinj Oct 09 '26

There are a bunch of people that use Scala, including my two recent previous orgs. Nobody uses Scala (and I argued against the use of Scala there) not because it broke compatibility, but because it is the prototypical thing people don't use because functional programming purists want to overcomplicate everything.

And no, "stick to your old compiler and settings" is not a solution. Because if you break the binary compatibility, older applications will stop working on newer operating systems. So "stick to your old compiler and settings" will turn into "stick to your old compiler and settings and OS".

This is just straight up false. The app I built with GCC 4 still works on ubuntu 26. You ship your /lib and set your LD_LIBRARY_PATH / rpath in the worst case. Windows does this often, it's the point of the whole MSVC++ "redistributable"s that install with basically every video game and professional (e.g. CAD / Adobe / Office-Suite) piece of software on the planet.

Also, I'm fine with this being the case, even if it wasn't false.

5

u/germandiago Oct 09 '26

Yes, bc in Rust unsafe does not exist and everything can be done in the safe subset.

5

u/CocktailPerson Oct 09 '26

What's an example, in your mind, of a memory-safe language?

5

u/germandiago Oct 09 '26 edited Oct 09 '26

Any language that can tell you: "this subset used this way" is memory-safe in an enough obvious way.

That includes C++ hardened, eliminating UB and with profiles. It is just being worked on.

Noone discusses the greys here. They just simplify: look Rust = memory safe. C++ != memory safe.

Well, Rust has now an obvious memory safe subset, indeed. That was an explicit design goal.

Nothing prevents C++ with profiles from being an obvious memory safe subset.

Even I could describe one such subset that is expressive enough for lots of uses for C++, as long as you attach yourself to some limitarions, in the current language. You will tell me that Rust is memory-safe. Yes, except for unsafe... so it is exactly the same thing from a mathematical point of view: it exists a memory safe subset in both. And an impossible-to-make-memory-safe-one.

Just that Rust is ahead bc it is conveniently marked. And that is a valuable thing, do not misinterpret me. But it is very silly here to see bold claims about memory safety without understanding that in real life the distance can be much narrower than it looks on the paper.

On top of that, every report I see about memory safety makes a C/C++ melee which is, well, not representativ, or, at least, not representative of my codebases and practices. Real problem? It is not enforced or obvious inC++. Add profiles on top and it should be possible. That is the target and I think it is doable.

Mr. Stroustrup talks the difficult and nuanced cases, everything, paying attention to the compatibility and usefulness of the feature to deliver the biggest value.

That is how professionals analyze problems. Not with some kind of manicheist all-or-nothing, with-me-or-against-me (talking about memory safety) mindset.

7

u/t_hunger Oct 09 '26 edited Oct 09 '26

That's the fun thing: There are no greys.The theory is binary there: Either a language allows to express memory unsafe programs or not. In practical languages there is an implicit "unless an escape hatch is used".

Nothing prevents C++ with profiles from being an obvious memory safe subset.

... once somebody bothered to write a soundness proof.

3

u/germandiago Oct 09 '26 edited Oct 09 '26

Where do you set the cutoff?

Is Python using the struct module memory-safe? Is Python a memory-safe language?

Is Java memory-safe? When calling native methods? In whcih circumstances it is or not guaranteed?

Is Rust safe? Even if you bury unsafe and pretend it is a safe interface?

It is C++ unsafe when I use a subset with only values and smart pointers for return, Ido not invalidate in dangerous ways and I use hardened preconditions (pretend all conditions are hardened even if not true) and I avoid undefined behavior?

No, it is not a totally binary characteristic if you go to the corner cases like these where it could be either depending on the memory safety provenance, though I can see the value of segregating one part from the other.

Something that can be done wirh C++ also. At what cost? Good question.

It can be done? Yes. It will be practical and adoptable? My guess is yes. But let us see what keeps going on.

3

u/ts826848 Oct 09 '26

Is Java memory-safe? When calling native methods? In whcih circumstances it is or not guaranteed?

Fun fact in case you and/or any readers didn't know: one interesting thing the Java devs are doing is moving towards a security model where you have to explicitly opt in to allowing unsafe calls even if the calls are in your dependencies.

Even if you bury unsafe and pretend it is a safe interface?

sighs

It is C++ unsafe when I use a subset with only values and smart pointers for return, Ido not invalidate in dangerous ways and I use hardened preconditions (pretend all conditions are hardened even if not true) and I avoid undefined behavior?

I don't think you needed to list everything else if you're going to end with that.

That being said, I think most people would still answer yes.

4

u/germandiago Oct 09 '26

so it is an unsafe language like "C/C++"?

This is exactly what I mean. Noone would consider Java unsafe or C++ as unsafe as C for normal practices. Yet we see this all-or-nothing division.

In fact, I consider Java, C# or Python safer than Rust under most conditions.

→ More replies

-1

u/cr1mzen Oct 09 '26

Great example of a logical fallacy.
PS i am a diehard C++ coder. I’m not here to stan for RUST

2

u/QuaternionsRoll Oct 09 '26

Why is RUST in all caps lol

-2

u/cr1mzen Oct 09 '26

I’m a C++ coder, sorry if I’m not an expert on how to spell rust.

3

u/QuaternionsRoll Oct 09 '26

You’re a C++ coder yet you think the “consensus” that we are not allowed to make major changes to the language is “sudden”?

1

u/13steinj Oct 09 '26

I'd argue that constexpr with C++11 and 14 was a pretty major change.

2

u/QuaternionsRoll Oct 09 '26

But the only breaking change was the addition of the `constexpr` keyword. It should also be clear to any seasoned C++ developer that WG21 is comfortable adding… whatever to the language, even half-baked nonsense, so long as the additions require minimal breaking changes.

2

u/ContraryConman Oct 10 '26

I personally would like a button I could push that just makes all pointer arithmetic, uninitialized variables, and the like compiler errors. That kind of profile might be nice. But it's also clear that for special and temporal memory safety, you need additional annotations in the language to allow a compiler to actually understand the lifetimes of your variables. I don't understand why we don't just adopt lifetime annotations as a standalone thing. If I turn on a flag, then the compiler uses the annotations to enforce lifetime rules via borrow checking, and if the flag is off, the annotations are ignored. This will catch more bugs in practice than fully ignoring lifetime annotations as a strategy of fully trying to make C++ into Rust.

But anyway none of this matters because LLMs will destroy programming language evolution. Humans aren't going to be writing code in the future anyway, and it'll no longer matter which underlying language is used for any given piece of software. It's kind of fun to think about hypothetically, I guess

7

u/Dragdu Oct 11 '26

If you mean for your own code, that button is called clang-tidy and a bit of effort.

1

u/ContraryConman Oct 11 '26

I already use that. I want it standard with deeper language-level guarantees

3

u/chaos_pill Oct 12 '26

adopt lifetime annotations as a standalone thing.

The profiles authors do not want to be seen "borrowing" ideas from rust. One of the slides at 09:15 says profiles are not a borrow checker. They also cornered themselves with roughly one annotation per thousand lines (i.e. no virality) rule.

The real problem is that there's no deadline. So, hard problems like lifetime/concurrency profiles don't make much progress. I wish people used their tokens on these problems instead of oneshotting another tetris clone.

1

u/ContraryConman Oct 12 '26

The clang lifetime annotation project is the single best way to get C++ to be more safe than it is, as well as give it enough information to properly interop with Swift and Rust. It doesn't fully add a second shadow type system like Circle does, but it doesn't straight up do nothing like profiles do. It's literally our best chance and it gets zero attention :(

3

u/chaos_pill Oct 12 '26

AFAIK, clang annotations are still not enough, and are limited in scope precisely because you need language support for anything more sophisticated.

Unless OpenAI throws their frontier at this problem, I don't see how any human can wrangle c++'s complexity.

3

u/ContraryConman Oct 12 '26

I phrased it as "more safe than it is" instead of "memory safe" because it doesn't seem worth it to me to make C++ a totally memory safe language. All iterators, containers, and views would have to be reworked as common patterns in the language.

If you just deliver lifetime annotations and a borrow checker as a standalone feature, you can allow the programmer to tell the compiler what they intend to do with object lifetime and have that enforced in an opt-in basis. This will catch many current and future bugs. I care less about reaching the formal definition of memory safety

0

u/Minimonium Oct 12 '26

The only argument for annotations is that you can wrap them in a macro to support old code. But you want them to deliver anything resembling borrowing guarantees - you will need to re-write the underlying code. They won't work with existing iterators/containers without a massive amount of problems.

3

u/ContraryConman Oct 12 '26

I am not afraid of rewriting code because code that is wrong will have to be rewritten by definition

0

u/Minimonium Oct 12 '26

Unfortunately that was the argument against proper borrow checker - people do not want to rewrite all the iterators/containers.

The underlying code is not strictly wrong, it just cannot be supported by annotations in a reasonable manner. And people do not want it.

2

u/ContraryConman Oct 12 '26

Then we won't annotate iterators and we'll annotate the other parts?

0

u/Minimonium Oct 12 '26

That's besides the point, although worth to note that most examples shown are about iterators/containers.

0

u/germandiago Oct 09 '26

I saw a slide of the lifetime profile in Stroustrup slide used in Godbolt.

I find the model a good fit for C++ since you can rely in higher level not annotated code when possible but if you must you can use some annotation when this is not possible. 

I know many people will jump to my neck and say Safe C++ and so on, but that would have been a throw away all existing code directly in terms of safety, that is why I find this solution a better fit.

It is not perfect, but the model is realistically compatible.

Does anyone know if the profile implementation is publicly available, since it seems to be work in progress and would like to give it a try.

14

u/pjmlp Oct 09 '26

No it wouldn't, because it is a superset, all existing code would still be compatible.

If profiles ever ship, the code will be full of [[profile::something()]] just as much, and the standard library will be equally annotated.

But hey I guess it is cooler to type that, given how many sigils are already used all over the place, especially when static reflection becomes mainstream.

So lets see if this does ship in C++29, full implementation, and which compilers support it by 2040 or something.

4

u/drbazza Oct 09 '26

Given the increasing ease with which you can tell an agent to 'convert this program to Rust', C++ is in even greater danger of safety-irrelevance in more and more sectors. Data point, mold3.0 just came out as a rewrite in Rust.

1

u/inouthack Oct 09 '26

u/drbazza the vice versa is true as well!

5

u/drbazza Oct 09 '26

Indeed, but I don't think I've seen a 'we've converted this Rust program to C++'.

1

u/germandiago Oct 11 '26

And you cannot convert some C++ libraries to Rust easily either. Think of expression templates or fully overloaded operator libraries, consteval constexpr, variadic templates.

There are quite a few libs that cannot be faithfully reproduced in Rust from C++.

1

u/drbazza Oct 11 '26

Agreed. I have a type list style container that is impossible to convert to Rust.

2

u/germandiago Oct 09 '26

I can see transitioning compiler switches or something similar to use profiles. What would be the impediment?

10

u/pjmlp Oct 09 '26

First one is for all three major compilers to implement them, and they hardly still have full C++20 and C++23 compliance today, let alone something that might, or not, land in C++29. Thus the 2040 there as wild guess.

Second there is the dream of the lifetime profile, and the hard reality of what they can achieve without violating paper P3466 (Re)affirm design principles for future C++ evolution, Do not add a feature that requires viral annotation section, as proven by what clang and VC++ have managed to achieve in a decade, since Core Guidelines were introduced in 2015.

Then lets see how they interact when different translation units, object files, static and dynamic libraries were compiled with conflicting on/off configurations.

Naturally all of this without refactoring the standard library into a V2, because this is something only competing proposals would do.

2

u/SkiFire13 Oct 13 '26

After all we have seen I doubt they will stick to that rule. They will most likely end up with something that requires more annotations than Rust but they will claim the annotations won't be needed in practice and thus are not "viral", all while likely having some issues that will require a lot of opt-outs for code that won't be checkable.

0

u/germandiago Oct 09 '26

Annotations will be needed in some cases. And that rule will be violated. And we will have the feature. Do not take that literally.

8

u/pdimov2 Oct 10 '26

Annotations will be needed in some cases.

Understatement of the decade.

-1

u/germandiago Oct 09 '26

The goal is incremental adoption and I think this is a bit of a distorted opinion. Check what Gabriel Dos Reis has to say about the framework.

1

u/drbazza Oct 12 '26

Having just watched this, I have questions...

Humans manually annotating [[owner]], whereas Rust mechanically and provably knows the owner.

Mixing and matching profiles as you want.

It feels like profiles occupies some weird third dimension perpendicular to unsafe (current) C and C++, and safe Rust and gc languages.

It just seems like a lot of moving existing static analysis into the compiler and selectively switching it on.

I'm not saying some of it won't be useful, and push defect counts down, but I feel like I'm missing something here. ELI5.

-1

u/AutonomousOrganism Oct 11 '26

When your programming language becomes so complex that you start introducing profiles, you probably should move on, create a new programming language. Oh wait, there is one. It's called Rust.

6

u/pdimov2 Oct 11 '26

Rust has "profiles". They are just done right. There is a single "profile", "safe", rigidly defined, always on, and a single escape hatch, the unsafe keyword.

2

u/drbazza Oct 12 '26

constinit, constexpr, consteval, whereas zig just has 'comptime'.

I suppose someone has to do it first for other languages to learn and simplify.

Alas, I feel like profiles is going to be this as well - a salutary lesson for other languages of either 'what not to do' (again), or 'can be simplified' (cf. your 'unsafe' comment)

1

u/PossibilityUsual6262 Oct 15 '26

Yea actually, what's up with that, why cant be one keyword, parsing issue?