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

Remove unnecessary explicit constructors #415

Merged
merged 4 commits into from
Jan 24, 2020

Conversation

miscco
Copy link
Contributor

@miscco miscco commented Jan 9, 2020

Description

This fixes #41 by unconditionally defining the default constructors

In contrast to the paper the constructors do not utilize the explicit constructors as that seems to be against the common praxis of the STL

Checklist

Be sure you've read README.md and understand the scope of this repo.

If you're unsure about a box, leave it unchecked. A maintainer will help you.

  • Identifiers in product code changes are properly _Ugly as per
    https://eel.is/c++draft/lex.name#3.1 or there are no product code changes.
  • The STL builds successfully and all tests have passed (must be manually
    verified by an STL maintainer before automated testing is enabled on GitHub,
    leave this unchecked for initial submission).
  • These changes introduce no known ABI breaks (adding members, renaming
    members, adding virtual functions, changing whether a type is an aggregate
    or trivially copyable, etc.).
  • These changes were written from scratch using only this repository,
    the C++ Working Draft (including any cited standards), other WG21 papers
    (excluding reference implementations outside of proposed standard wording),
    and LWG issues as reference material. If they were derived from a project
    that's already listed in NOTICE.txt, that's fine, but please mention it.
    If they were derived from any other project (including Boost and libc++,
    which are not yet listed in NOTICE.txt), you must mention it here,
    so we can determine whether the license is compatible and what else needs
    to be done.

@@ -34,7 +34,12 @@ public:
}; // set if character array ownership given away
using _Strstate = int;

explicit __CLR_OR_THIS_CALL strstreambuf(streamsize _Count = 0) {
// construct with empty character array
__CLR_OR_THIS_CALL strstreambuf() {
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it might be an ABI break (otherwise why would it be annotated __CLR_OR_THIS_CALL ?)

Alternately the __CLR_OR_THIS_CALL annotation might be incorrect.

Copy link
Member

Choose a reason for hiding this comment

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

It is definitely concerning - the presence of explicit calling conventions strongly indicates separately compiled machinery that we can't mess with. However, in the specific case of strstreambuf, I believe that this may be okay. The base class basic_streambuf has explicit calling conventions because it is indeed separately compiled. However, I can't find any mentions of strstream (including strstreambuf) in either the static or dynamic libraries. Therefore, I believe that splitting this constructor should be ABI-safe. Our test to verify the export surface will serve as a double-check.

Copy link
Member

@CaseyCarter CaseyCarter Jan 9, 2020

Choose a reason for hiding this comment

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

I agree with Stephan's analysis. If none of these are exported, should we file a separate issue to remove __CLR_OR_THIS_CALL from all of this class's function declarations?

Copy link
Member

Choose a reason for hiding this comment

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

I think that would be unnecessarily risky for no benefit. This is strstream, after all - the entire thing is deprecated and rarely changes. Also, the virtuals need explicitly specified calling conventions to match the base class, even if the non-virtuals don't.

(Also, vNext will eliminate separately compiled classes.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

NO chage done

@BillyONeal
Copy link
Member

In contrast to the paper the constructors do not utilize the explicit constructors as that seems to be against the common praxis of the STL

Yes, the codegen for that is very poor due to the interaction with EH :(

stl/inc/cvt/wbuffer Show resolved Hide resolved
@@ -34,7 +34,12 @@ public:
}; // set if character array ownership given away
using _Strstate = int;

explicit __CLR_OR_THIS_CALL strstreambuf(streamsize _Count = 0) {
// construct with empty character array
__CLR_OR_THIS_CALL strstreambuf() {
Copy link
Member

@CaseyCarter CaseyCarter Jan 9, 2020

Choose a reason for hiding this comment

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

I agree with Stephan's analysis. If none of these are exported, should we file a separate issue to remove __CLR_OR_THIS_CALL from all of this class's function declarations?

stl/inc/strstream Outdated Show resolved Hide resolved
@miscco miscco force-pushed the non_explicit branch 2 times, most recently from 402292e to 1c38b3f Compare January 10, 2020 04:32
Copy link
Member

@CaseyCarter CaseyCarter left a comment

Choose a reason for hiding this comment

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

Pushed a commit with some comment-wrapping cleanup.

Copy link
Contributor

@timsong-cpp timsong-cpp left a comment

Choose a reason for hiding this comment

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

The distributions' param_type are specified by reference to the distributions' constructors, so the changes to the distributions need to apply to their param_type as well. (This is intentional.)

@miscco
Copy link
Contributor Author

miscco commented Jan 15, 2020

@timsong-cpp Thanks a lot for the hint. I was unaware of that connection. Fixed it and pushed

Copy link
Member

@StephanTLavavej StephanTLavavej left a comment

Choose a reason for hiding this comment

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

Looks great. I found a couple of extremely minor comment/whitespace nitpicks, but I believe this is ready to merge as-is. (I double-checked the paper and verified that all edits were applied or already present.) We might want to add tests for this (although I am tempted to be lazy).

stl/inc/sstream Outdated Show resolved Hide resolved
stl/inc/xlocbuf Outdated Show resolved Hide resolved
@StephanTLavavej
Copy link
Member

Rebased to resolve merge conflict in yvals_core.h. This has passed my test run; beginning the final Microsoft-internal PR now.

@StephanTLavavej StephanTLavavej merged commit 0e336ac into microsoft:master Jan 24, 2020
@StephanTLavavej
Copy link
Member

Thanks for implementing another C++20 feature! This will appear in VS 2019 16.6 Preview 1.

@miscco miscco deleted the non_explicit branch January 28, 2020 14:08
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.

P0935R0 Eradicating Unnecessarily Explicit Default Constructors
6 participants