Skip to content

Fix construct tag#497

Merged
StephanTLavavej merged 24 commits intomicrosoft:masterfrom
JeanPhilippeKernel:fix-construct-tag
Feb 29, 2020
Merged

Fix construct tag#497
StephanTLavavej merged 24 commits intomicrosoft:masterfrom
JeanPhilippeKernel:fix-construct-tag

Conversation

@JeanPhilippeKernel
Copy link
Contributor

@JeanPhilippeKernel JeanPhilippeKernel commented Feb 12, 2020

Description

Fixes #468.

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.

@JeanPhilippeKernel JeanPhilippeKernel requested a review from a team as a code owner February 12, 2020 18:21
@StephanTLavavej StephanTLavavej added the enhancement Something can be improved label Feb 12, 2020
stl/inc/codecvt Outdated
Comment on lines +24 to +26
constexpr int _Little_first = 1;
constexpr int _Big_first = 2;
constexpr int _Bytes_per_word = 4;
Copy link
Member

Choose a reason for hiding this comment

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

In stl/inc headers, we conventionally say _INLINE_VAR constexpr, for example:

_INLINE_VAR constexpr int _ISORT_MAX = 32; // maximum size for insertion sort

This expands to inline constexpr in C++17 mode, which makes a difference if the constant is ever address-taken (hopefully not for these constants, but we follow the convention anyways).

stl/inc/codecvt Outdated
#define _BYTES_PER_WORD 4
constexpr int _Little_first = 1;
constexpr int _Big_first = 2;
constexpr int _Bytes_per_word = 4;
Copy link
Member

Choose a reason for hiding this comment

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

_BYTES_PER_WORD appears to have been completely unused and should be eliminated.

stl/inc/xmemory Outdated
Comment on lines +1246 to +1247
}; // tag to indicate that a proxy is being allocated before it is safe to bind to a
// _Container_base12
Copy link
Member

Choose a reason for hiding this comment

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

This comment can now be unwrapped to a single line. (clang-format wraps excessively long comments, but won't unwrap in situations like this.)

stl/inc/xutility Outdated
struct contiguous_iterator_tag : random_access_iterator_tag {};
struct contiguous_iterator_tag : random_access_iterator_tag {
explicit contiguous_iterator_tag() = default;
};
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, the "explicit default constructor" improvement can't be extended to these Standard types, so please revert this group of changes.

The issue is that WG21-N4849 [std.iterator.tags]/1 (see https://eel.is/c++draft/std.iterator.tags#1 for HTML instead of PDF) specifies the Standard tag types, with implicit default constructors, so we have to match that observable behavior. In contrast, we can do basically whatever we want with internal non-Standard types like _Priority_tag below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh okay let's revert so !
thanks a lot !! I didn't aware about that

Comment on lines +13 to +14
extern "C" _CRT_SATELLITE_1 _Aligned_new_delete_resource_impl* __cdecl _Aligned_new_delete_resource() noexcept {
_EXTERN_C
_CRT_SATELLITE_1 _Aligned_new_delete_resource_impl* __cdecl _Aligned_new_delete_resource() noexcept {
Copy link
Member

Choose a reason for hiding this comment

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

The extern "C" changes in this file are unrelated to the tag changes in the rest of the PR. While this transformation doesn't change the meaning of the code, it introduces inconsistency with the declarations in <memory_resource>. If you believe that we should consistently rely on _EXTERN_C blocks for declarations and definitions, please file an enhancement issue so we can make a decision - and then if we decide on a convention, it can be cleaned up in a separate PR.

The general principle is that large code transformations/cleanups should be performed in separate PRs for ease of code reviewing and history reading. Mixing in very small changes can be OK (e.g. comment changes, or the _Default_resource{nullptr} initialization change above - that one is at least thematically related to "brace-initialize more things").

I noticed similar changes in #487 but didn't object then because they were small and increased consistency between the declarations and definitions. I probably should have mentioned my concerns though, apologies for not doing so earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah totally right !, let's revert and consider another PR for these changes

The extern "C" changes in this file are unrelated to the tag changes in the rest of the PR. While this transformation doesn't change the meaning of the code, it introduces inconsistency with the declarations in <memory_resource>. If you believe that we should consistently rely on _EXTERN_C blocks for declarations and definitions, please file an enhancement issue so we can make a decision - and then if we decide on a convention, it can be cleaned up in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you don't need to apologies 😉, what do you think about a file an enhancement issue and assign it to me ?

I noticed similar changes in #487 but didn't object then because they were small and increased consistency between the declarations and definitions. I probably should have mentioned my concerns though, apologies for not doing so earlier.

}

extern "C" {
EXTERN_C_START
Copy link
Member

Choose a reason for hiding this comment

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

These are <Windows.h> macros, but we conventionally use the STL's macros for this (in fact, I had to look up where this was coming from). I think it would be fine to use the STL macros here in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this means that we should include <yvals_core.h>
as we said above, let's file a new enhancement issue for a diff PR

}

} // extern "C"
EXTERN_C_END // extern "C"
Copy link
Member

Choose a reason for hiding this comment

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

When changing this to the STL's macro, the comment should also be dropped (as it no longer serves a purpose).


extern "C" {

EXTERN_C_START
Copy link
Member

Choose a reason for hiding this comment

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

Same comments about using STL macros instead of <Windows.h> macros.

revert "explicit default constructor" on Standard tag type,
revert "extern "C"" for another PR
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.

Perfect; I will port this to our Microsoft-internal repo and merge it soon. Thank you!

`_Lex_compare_optimize` now has an explicit default constructor,
so we can't return `{}`. Usage through an alias template also needs
to be fixed.
@BillyONeal
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@StephanTLavavej StephanTLavavej merged commit 577827a into microsoft:master Feb 29, 2020
@StephanTLavavej
Copy link
Member

Thank you for improving the codebase's consistency and readability!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something can be improved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

STL: Consistently use empty braces to construct tags like _Meow{}

3 participants