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

src: inline macro DISALLOW_COPY_AND_ASSIGN #26634

Merged
merged 2 commits into from Mar 18, 2019

Conversation

Projects
None yet
5 participants
@gengjiawen
Copy link
Member

commented Mar 13, 2019

This one is similar like #25764, following Effective Modern C++ Items 11: Prefer deleted functions to private undefined ones.

This time I tried this on godbolt.
When deleted functions are declared private,
GCC 6.2 error message is not very clear.
GCC 8.x and Clang 7.x error message is clear.
demo: https://godbolt.org/z/k6O9wc.

This commit also add commit use deleted function instead of private function in class AsyncWrap

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@gengjiawen gengjiawen force-pushed the gengjiawen:deleted_function_public_in_macro branch from b1c31b5 to 8198e3b Mar 13, 2019

@gengjiawen

This comment has been minimized.

Copy link
Member Author

commented Mar 13, 2019

Linting failed due to

src/node_buffer.cc:91:  DISALLOW_COPY_AND_ASSIGN must be in the private: section  [readability/constructors] [3]
src/node_buffer.cc:91:  DISALLOW_COPY_AND_ASSIGN should be the last thing in the class  [readability/constructors] [3]

cc @addaleax @refack @bnoordhuis

@refack

This comment has been minimized.

Copy link
Member

commented Mar 13, 2019

DISALLOW_COPY_AND_ASSIGN must be in the private: section [readability/constructors]

That's strange since it's contrary to https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types:

Decision:

Every class's public interface should make explicit which copy and move operations the class supports. This should usually take the form of explicitly declaring and/or deleting the appropriate operations in the public section of the declaration.

I'd be +1 for unpacking the macro everywhere. Personally I'm ambivalent of it's use... On the one hand it has an nice explicit name. On the other hand it's non-language meta-programming (ES.30: Don’t use macros for program text manipulation & https://google.github.io/styleguide/cppguide.html#Preprocessor_Macros)

I'll post a PR to patch cpplint.py.

@gengjiawen

This comment has been minimized.

Copy link
Member Author

commented Mar 13, 2019

Personally I like to unpack them too.

@refack

This comment has been minimized.

Copy link
Member

commented Mar 13, 2019

following Effective Modern C++ [Items 11: Prefer deleted functions to private undefined ones](http://clchiou.github.io/notes-effective-modern-c++/2017-01-14/item-11-prefer-deleted-functions-to-private-undefined-ones).

FTR: the reason behind this is Deleted functions should be declared public because compiler checks accessibility before deleted status. So deleting default operation in public will give a better compilation error ("x was deleted" rather then "x is private")

@gengjiawen

This comment has been minimized.

Copy link
Member Author

commented Mar 13, 2019

Yeap, the pr I refered has the similar information.

By convention, deleted functions are declared public, not private. There’s a reason for that. When client code tries to use a member function, C++ checks accessibility before deleted status. When client code tries to use a deleted private function, some compilers complain only about the function being private, even though the function’s accessibility doesn’t really affect whether it can be used. It’s worth bearing this in mind when revising legacy code to replace private-and-not-defined member functions with deleted ones, because making the new functions public will generally result in better error messages.

@gengjiawen gengjiawen changed the title src: make deleted function public using macro DISALLOW_COPY_AND_ASSIGN src: make deleted function public when using macro DISALLOW_COPY_AND_ASSIGN Mar 13, 2019

@gengjiawen

This comment has been minimized.

Copy link
Member Author

commented Mar 15, 2019

I am thinking inline DISALLOW_COPY_AND_ASSIGN more be more appropriate, thoughts ?

cc @addaleax @bnoordhuis @jasnell @joyeecheung

@addaleax

This comment has been minimized.

Copy link
Member

commented Mar 15, 2019

I don’t have a strong opinion on this, personally.

@gengjiawen

This comment has been minimized.

Copy link
Member Author

commented Mar 15, 2019

I don’t have a strong opinion on this, personally.

If there is no strong objection on this, I can work on this on Sunday.

@gengjiawen gengjiawen force-pushed the gengjiawen:deleted_function_public_in_macro branch from 8198e3b to 46f5862 Mar 16, 2019

@gengjiawen gengjiawen changed the title src: make deleted function public when using macro DISALLOW_COPY_AND_ASSIGN src: inline macro DISALLOW_COPY_AND_ASSIGN Mar 16, 2019

@gengjiawen

This comment has been minimized.

Copy link
Member Author

commented Mar 16, 2019

@addaleax @refack I have inlined the macro and make it in public. Can you review this, thanks.

@gengjiawen gengjiawen force-pushed the gengjiawen:deleted_function_public_in_macro branch 2 times, most recently from d21c189 to c6dd193 Mar 16, 2019

Show resolved Hide resolved src/node_file.h Outdated

@gengjiawen gengjiawen force-pushed the gengjiawen:deleted_function_public_in_macro branch 3 times, most recently from 54bfa35 to 6e9c44c Mar 16, 2019

@gengjiawen gengjiawen force-pushed the gengjiawen:deleted_function_public_in_macro branch from 6e9c44c to 156e239 Mar 16, 2019

@refack

refack approved these changes Mar 16, 2019

@refack

This comment has been minimized.

Copy link
Member

commented Mar 16, 2019

Non blocking, but it would be nice to update the example in

// private:
// ~MyData() override {}
// DISALLOW_COPY_AND_ASSIGN(MyData);

@refack

This comment has been minimized.

@refack

This comment has been minimized.

Copy link
Member

commented Mar 16, 2019

@gengjiawen

This comment has been minimized.

Copy link
Member Author

commented Mar 17, 2019

Non blocking, but it would be nice to update the example in

node/src/tracing/trace_event_common.h

Lines 153 to 155 in 6608cf2

// private:
// ~MyData() override {}
// DISALLOW_COPY_AND_ASSIGN(MyData);

Done.

@gengjiawen gengjiawen force-pushed the gengjiawen:deleted_function_public_in_macro branch from 156e239 to 138d76c Mar 17, 2019

@BridgeAR

This comment has been minimized.

@gengjiawen gengjiawen force-pushed the gengjiawen:deleted_function_public_in_macro branch from 138d76c to 45d9454 Mar 17, 2019

@refack

This comment has been minimized.

Copy link
Member

commented Mar 17, 2019

@refack

This comment has been minimized.

Copy link
Member

commented Mar 17, 2019

gengjiawen added some commits Mar 13, 2019

src: inline macro DISALLOW_COPY_AND_ASSIGN
PR-URL: #26634
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
src: use deleted function instead of private function in class AsyncWrap
PR-URL: #26634
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>

@refack refack force-pushed the gengjiawen:deleted_function_public_in_macro branch from 45d9454 to dace489 Mar 18, 2019

@refack

This comment has been minimized.

Copy link
Member

commented Mar 18, 2019

@refack refack merged commit dace489 into nodejs:master Mar 18, 2019

4 checks passed

Travis CI - Branch Build Passed
Details
Travis CI - Pull Request Build Passed
Details
linter tests passed
Details
node-test-commit-linuxone tests passed
Details

Drieger added a commit to Drieger/node that referenced this pull request Mar 22, 2019

src: inline macro DISALLOW_COPY_AND_ASSIGN
PR-URL: nodejs#26634
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>

Drieger added a commit to Drieger/node that referenced this pull request Mar 22, 2019

src: use deleted function instead of private function in class AsyncWrap
PR-URL: nodejs#26634
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>

targos added a commit to targos/node that referenced this pull request Mar 27, 2019

src: inline macro DISALLOW_COPY_AND_ASSIGN
PR-URL: nodejs#26634
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>

targos added a commit to targos/node that referenced this pull request Mar 27, 2019

src: use deleted function instead of private function in class AsyncWrap
PR-URL: nodejs#26634
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>

targos added a commit to targos/node that referenced this pull request Mar 27, 2019

src: inline macro DISALLOW_COPY_AND_ASSIGN
PR-URL: nodejs#26634
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>

targos added a commit to targos/node that referenced this pull request Mar 27, 2019

src: use deleted function instead of private function in class AsyncWrap
PR-URL: nodejs#26634
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>

targos added a commit to targos/node that referenced this pull request Mar 27, 2019

src: inline macro DISALLOW_COPY_AND_ASSIGN
PR-URL: nodejs#26634
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>

targos added a commit to targos/node that referenced this pull request Mar 27, 2019

src: use deleted function instead of private function in class AsyncWrap
PR-URL: nodejs#26634
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>

targos added a commit that referenced this pull request Mar 27, 2019

src: inline macro DISALLOW_COPY_AND_ASSIGN
PR-URL: #26634
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>

targos added a commit that referenced this pull request Mar 27, 2019

src: use deleted function instead of private function in class AsyncWrap
PR-URL: #26634
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>

@targos targos referenced this pull request Mar 27, 2019

Merged

v11.13.0 release proposal #26949

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.