Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[diff.cpp03.containers] Add overdue compatibility note on allocators #5835

Closed

Conversation

AlisdairM
Copy link
Contributor

Revisiting my abandoned paper P0177, there was approval to add this historical compatibility with C++03 text back in 2016, but I never turned it into an editorial request after abandoning the paper.

Revisiting my abandoned paper P0177, there was approval to add
this historical compatibility with C++03 text back in 2016, but
I never turned it into an editorial request after abandoning
the paper.
\effect
\tcode{allocator_traits} supplies default definitions for many allocator type
names and operations. Valid \CppIII{} code that follows the original
allocator-aware container requirements may not support allocators written to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were no "allocator-aware container requirements" before C++11, so it's unclear what "the original" ones are. We did have Allocator requirements in C++03, and those are what changed dramatically.

Maybe it would help to have an example showing a function template with an Allocator parameter, assuming the presence of pointer and construct members, which need to be accessed via allocator_traits since C++11.

@AlisdairM
Copy link
Contributor Author

Additional note: turns out this is Pending NAD Editorial issue http://cplusplus.github.io/LWG/lwg-closed.html#2178. I will try to clean this up so we can finally remove the Pending!

\tcode{allocator_traits} supplies default definitions for many allocator type
names and operations. Valid \CppIII{} code that follows the original
allocator-aware container requirements may not support allocators written to
the simpler set of requirements in this standard, and may propagate allocators
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO allocator propagation deserves a separated paragraph since corresponding change in C++11 doen't seemly simplify user codes.
Library supports for stateful allocators were essentially conditionally-supported extensions in C++03, while being precisely required and specified since C++11. Incompatibility may come from the conflict between standard and (pre-standard) extented mechanisms (only when using stateful allocators with standard containers).

@jensmaurer
Copy link
Member

Annex C is for previously-valid code that becomes invalid or changes meaning with a new standard.

Are there any actual allocators in later C++ that had their pointer and construct members removed? Otherwise, all allocators that were written for C++-old will have those members, and nothing breaks.

There should be no Annex C entry for stuff that merely was underspecified or a popular extension.

Please provide an example of previously-valid code that becomes invalid or changes meaning with a new standard.

@AlisdairM
Copy link
Contributor Author

The code that breaks is user authored container templates, instantiated with an allocator specified according to C++11. I will add an example when I revise the PR later today.

@jensmaurer
Copy link
Member

But that's not a breakage we can meaningfully record in Annex C: The code you sketch wouldn't compile with C++03, so it's not the case of valid code becoming invalid or changing meaning.

@AlisdairM
Copy link
Contributor Author

As noted, I extracted this edit from the abandoned P0177 (which may resurface shortly). This passed LEWG review as maybe worthwhile in 2016, but I could not honestly claim it was a strong endorsement :). I wrote this wording up as I recall concerns during the C++11 standardization of this feature that we were breaking backwards compatibility for concepts (not implying the language term) though, rather than existing code. Templates that satisfied their requirements would no longer serve their purpose without change when updating to C++11.

So while I think this is a change worth documenting, as something to be aware of when upgrading, I have done my due diligence and am not strongly attached to this change. If the editors believe it is a mistake to add it, please close the issue.
If they would like to see the edit revised with an example before making up their minds, please reply here and I will provide a another update - understanding that the PR could still be closed without change.

@frederick-vs-ja
Copy link
Contributor

I think I've figured the "real" incompatibilities out. (Although I guess they didn't happen for real codes.)

Requirements on new members may matter.

A C++03 allocator may have its void_pointer and const_void_pointer member types defined as arbitrary types (e.g. int, void()). Such a non-conventional member type may make the program ill-formed when an allocator type is required since C++11, but had no impact in C++03.

Likewise, a non-conventional select_on_container_copy_construction member function, or propagate_on_container_copy_assignment, propagate_on_container_move_assignment, propagate_on_container_swap member type may result in UB since C++11.

Perhaps the is_always_equal member type should be considered to have effects since C++17 (N4258), but it is handled in all modes that support stateful allocators by mainstream implementations (as the resolution of LWG2108 that may be considered applied to C++11).

A non-conventional allocate_at_least member function may result in UB since C++23 (P0401R6).

@tkoeppe tkoeppe closed this Nov 9, 2023
@AlisdairM AlisdairM deleted the cpp03_alloc_traits_compat branch November 14, 2023 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants