-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Use designated initializers #24531
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
Use designated initializers #24531
The head ref may contain hidden characters: "2203-designated_init-\u{1F6CD}"
Conversation
Looks like there is a msvc bug that causes |
|
ee4a55e
to
7106a59
Compare
fa2cea2
to
10b4fc9
Compare
@sipsorcery Any idea on how to approach the msvc bug? |
I can't replicate this bug locally. The changes in this PR build fine for me with |
On Cirrus we have Visual Studio 2019:
|
Maybe we should bump it? Not sure how, though. |
Looks like it was a memory issue on the Cirrus VM then? I did build this PR locally using Visual Studio 2019, with a version close to what Cirrus is using, and did not get any compiler errors. I got some linker errors but they are related to vcpkg dependencies being built with a newer Visual Studio version. I didn't see any errors that looked like they were caused by this PR. |
fa14cfb
to
fadc9cf
Compare
CI is green now 😄 |
Taken out of draft for review. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
fadc9cf
to
fa42f0b
Compare
fa42f0b
to
fad0b52
Compare
Looks like another msvc bug??
|
8857267
to
faa49c0
Compare
Disabled for msvc due to bug for now |
Ha, what a gross hack. I love it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK faa49c0
Desig(prefer_evict) node->m_prefer_evict, | ||
Desig(m_is_local) node->addr.IsLocal(), | ||
Desig(m_network) node->ConnectedThroughNetwork(), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought (don't want to bikeshed), but it might be more readable & obvious what is going on with a macro syntax like:
NodeEvictionCandidate candidate{
INIT_FIELD(id, node->GetId()),
INIT_FIELD(m_connected, node->m_connected),
...
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be easier to write a scripted-diff to convert Desig(x)
to .x:
than having to find the closing bracket in INIT_FIELD(id, node->GetId()),
? Might be worth a little bikeshedding to see if there's a particularly readable format though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I was optimizing for the scripted-diff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer @ryanofsky 's suggestion as well (if we need this clumsiness at all).
faa49c0
to
fa72e0b
Compare
Concept ACK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK fa72e0b
@@ -90,7 +90,7 @@ | |||
<AdditionalOptions>/utf-8 /Zc:__cplusplus /std:c++17 %(AdditionalOptions)</AdditionalOptions> | |||
<DisableSpecificWarnings>4018;4244;4267;4334;4715;4805;4834</DisableSpecificWarnings> | |||
<TreatWarningAsError>true</TreatWarningAsError> | |||
<PreprocessorDefinitions>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING;ZMQ_STATIC;NOMINMAX;WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_CONSOLE;_WIN32_WINNT=0x0601;_WIN32_IE=0x0501;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<PreprocessorDefinitions>DISABLE_DESIGNATED_INITIALIZER_ERRORS;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING;ZMQ_STATIC;NOMINMAX;WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_CONSOLE;_WIN32_WINNT=0x0601;_WIN32_IE=0x0501;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This affects not only CI builds with MSVC 2019, but local builds as well which could use MSVC 2022.
Are we going to remove it when switching to C++20?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes to both questions/statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK fa72e0b
* option "/std:c++20" | ||
*/ | ||
#ifndef DISABLE_DESIGNATED_INITIALIZER_ERRORS | ||
#define Desig(field_name) .field_name = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I don't particularly like defining our own macro for this. Would have preferred to either use the language feature as-is, or not.
(inserting loose tokens like this is also a bit ugly imo, if you really want to define a macro for this why not
#define Desig(field_name, value) .field_name = (value)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, no objection to revert it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to support MSVC 2019?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cirrus doesn't supprt VS2022 yet https://cirrus-ci.org/guide/windows/.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to support MSVC 2019?
No, that's the point. We should stop supporting it, as it is know to be broken (it can't compile c++20, even though the flag exists). However, no one was successful in bumping the CI task to msvc22.
See my previous attempt: #24531 (comment), as well as: cirruslabs/cirrus-ci-docs#985
Maybe a bounty task? 😅 @jamesob
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#define Desig(field_name, value) .field_name = (value)
see previous discussion: #24531 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#25472 🐅
…ualstudio2022` 05b2d9f build: Bump default `PlatformToolset` for Visual Studio 2022 (Hennadii Stepanov) 460c6c7 doc: Make Windows build docs match the CI task (Hennadii Stepanov) 849cf96 ci: Increase CPU number for "Win64 native" task (Hennadii Stepanov) a18c4c1 ci: Bump vcpkg to the latest version (Hennadii Stepanov) b9a5a9b ci: Limit ccache cache size properly on "Win64 native" task (Hennadii Stepanov) 156bc89 ci: Update Windows task image up to visualstudio2022 (Hennadii Stepanov) Pull request description: Besides upgrading Visual Studio, which seems [inevitable](bitcoin/bitcoin#24531 (comment)), this PR also: - bumps vcpkg to the latest version (previous one was in bitcoin/bitcoin#24847) - fixes cache size limit for `ccache` ACKs for top commit: sipsorcery: reACK 05b2d9f. hebasto: > ACK [05b2d9f](bitcoin/bitcoin@05b2d9f) jarolrod: ACK 05b2d9f Tree-SHA512: 6338e74a3f1907f09ca29540e9e2cf7ac3be3b9e28271e8a20e71b67a9c3d5ebb8d34528b9677bcd1d9bc0ad723d68fd2ba7db368443ed1854cca3a3961f294b
630c171 refactor: Drop no longer needed `util/designator.h` (Hennadii Stepanov) 88ec5d4 build: Increase MS Visual Studio minimum version (Hennadii Stepanov) 555f9dd rpc, refactor: Add `decodepsbt_outputs` (Hennadii Stepanov) 0c432cb rpc, refactor: Add `decodepsbt_inputs` (Hennadii Stepanov) 01d95a3 rpc, refactor: Add `getblock_prevout` (Hennadii Stepanov) Pull request description: Visual Studio 2022 with `/std:c++20` supports [designated initializers](#24531). ACKs for top commit: sipsorcery: reACK 630c171. Tree-SHA512: 5b8933940dd69061c6b077512168bebb6fea05d429b63ffbab191950798b4c825e8484b1a651db0ae13f97eae481097d3c16395659c0f3b9f847af2aaf44b65d
#ifndef DISABLE_DESIGNATED_INITIALIZER_ERRORS | ||
#define Desig(field_name) .field_name = | ||
#else | ||
#define Desig(field_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for clarity and documentation. This code is wrong as-is and has long been removed. Omitting the field name here can lead to bugs, see https://godbolt.org/z/9TnoMKMT3 for a playground.
Designated initializers are supported since gcc 4.7 (Our minimum required is 8) and clang 3 (Our minimum required is 7). They work out of the box with C++17, and only msvc requires the C++20 flag to be set. I don't expect any of our msvc users will run into issues due to this. See also https://bitcoin.jonasschnelli.ch/ircmeetings/logs/bitcoin-core-dev/2022/bitcoin-core-dev.2022-03-10-19.00.log.html#l-114