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] Elevenize KALDI_DISALLOW_COPY_AND_ASSIGN() #4547

Merged
merged 1 commit into from
May 28, 2021

Conversation

kkm000
Copy link
Contributor

@kkm000 kkm000 commented May 28, 2021

Before C++11 we declared the same members private, usually at the very end of a class declaration. With standardization of the delete keyword and adoption of the pattern, it is now idiomatic to make deleted members public. The rationale (which I'm totally with) is that deletion of copy members is part of the public behavior of a type, namely its uncopyability, and should be expressed in and readable from the public: section alone.

Google coding style, which we are generally following, does not mention the DISALLOW_COPY_AND_ASSIGN macro any more, and recommends using the = delete; construct directly:

Every class's public interface must make clear 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.

[Bold mine; the focus on public is very explicit.]

Examples from the guide use the delete straight without the macro¹, but I think we should make an exception and continue using the macro, which is more self-explanatory.

clang-tidy gets angry at non-public deleted members, too.

_ _
¹ Which originated at Google as DISALLOW_EVIL_CONSTRUCTORS and had been renamed DISALLOW_COPY_AND_ASSIGN during my tenure, around 2014, when Google first started releasing parts of its code as OSS.

Before C++11 we declared the same members private, usually at the
very end of a class declaration. With standardization of the delete
keyword and adoption of the pattern, it is now idiomatic to make
deleted members public. The rationale is that deletion of copy members
is part of the public behavior of a type, namely its uncopyability,
and should be expressed in and readable from the public: section alone.

Google coding style, which we are generally following, does not
mention the 'DISALLOW_COPY_AND_ASSIGN' macro any more, and recommends
using the '= delete;' construct directly. From
https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types:

> Every class's public interface must make clear 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.

Examples from the guide use the delete keyword straight without any
macro, but I think we should make an exception and continue using
the macro, which is more self-explanatory.

clang-tidy gets angry at non-public deleted members, too.
@kkm000 kkm000 requested review from danpovey and jtrmal May 28, 2021 12:27
@jtrmal
Copy link
Contributor

jtrmal commented May 28, 2021 via email

Copy link
Contributor

@danpovey danpovey left a comment

Choose a reason for hiding this comment

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

LGTM!

@kkm000
Copy link
Contributor Author

kkm000 commented May 28, 2021

CI is green, merging, thanks for looking!

@kkm000 kkm000 merged commit 949696e into kaldi-asr:master May 28, 2021
@kkm000 kkm000 deleted the 2105-elevenise-disallow-copy-etc branch May 28, 2021 13:42
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.

3 participants