-
Notifications
You must be signed in to change notification settings - Fork 4
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
Record initialization with no designators #165
Conversation
include/type.hpp
Outdated
std::size_t offset( // NOLINT(readability-identifier-naming) | ||
const std::size_t index) const override; |
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 suggest dropping the const
specifier for pass-by-value parameters from the function declaration, but keep it in the function definition. This does not apply to const
-reference parameters, which should be kept in both places.
std::size_t offset( // NOLINT(readability-identifier-naming) | |
const std::size_t index) const override; | |
std::size_t offset( // NOLINT(readability-identifier-naming) | |
std::size_t index) const override; |
Note that two function declarations differing only in the constness of their pass-by-value parameters are not considered overloads, as they are indistinguishable when called. Removing const
from the function declaration is recommended for the following reasons:
- The caller does not need to know whether the parameter is
const
or not, as it does not affect the caller. Includingconst
only clutters the function declaration. - You might want to change the function's implementation, which could involve removing the
const
. Ifconst
is included in the function declaration, you will have to update it there as well.
After applying the current fix, compiler will not initialize exceeding elements.
|
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.
Additionally, the NOLINT
s can be removed after the renaming.
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.
LGTM! Masterpiece 🤓
This PR implement record initialization with no designator code generation. Even though we support initializing multiple elements for
union
,union
member access expression will only return the first element (Similar with gcc and clang, they only throw warning)[1].[1] https://godbolt.org/z/57fYnn95G