Skip to content

Apply Rule of Zero to old-style uncopyable classes in core/ and protocols/#697

Open
lyskov-ai wants to merge 2 commits into
RosettaCommons:mainfrom
lyskov-ai:refactor/rule-of-zero-batched-fixes
Open

Apply Rule of Zero to old-style uncopyable classes in core/ and protocols/#697
lyskov-ai wants to merge 2 commits into
RosettaCommons:mainfrom
lyskov-ai:refactor/rule-of-zero-batched-fixes

Conversation

@lyskov-ai
Copy link
Copy Markdown
Contributor

Summary

Modernize 31 headers across core/ and protocols/ that used the pre-C++11 idiom of declaring (but not defining) private copy constructor and assignment operator to forbid copies. The link-error-as-enforcement trick is fragile (silent breakage if anyone defines them in the same translation unit, confusing diagnostics on misuse, and falsely implies the class has a copy constructor).

Two flavours of fix applied:

  1. Stand-alone non-copyable classes — InteractionGraphBase node/edge/graph family (9 files, 23 classes total), FlexbbInteractionGraph (2 classes), JobDigraph (2 classes), AtomTreeCollection's ResidueAtomTreeCollection, Matcher, and MonteCarlo's operator=: replace the private unimplemented declarations with public = delete. Where the old assignment took a non-const reference or returned T const & (a C++03 idiom holdover), the modernized signatures take T const & and return T &.

  2. Singleton-derived factories (utility::SingletonBase children) — RotamerLibrarySpecificationFactory, SingleResidueRotamerLibraryFactory, RotamerLibrary, CenrotLibrary, plus DockingHighResFactory, EvaluatorFactory, JobInputterFactory, JobOutputterFactory, LoopMoverFactory, LoopRefineInnerCycleFactory, LoopsDefinerFactory, GridFactory, PoseSelectorFactory, RotamerRecoveryFactory, AssemblyRequirementFactory, AssemblyScorerFactory: simply drop the redundant unimplemented copy/assignment declarations. SingletonBase already = deletes its own copy/assignment, which transitively deletes the derived class's implicit versions, so the extra lines were noise.

No behaviour change: copy/assignment attempts that were link errors before are now compile errors, which is the intended diagnostic-quality improvement. Debug build passes clean.

…cols/

Modernize 31 files that used the pre-C++11 idiom of declaring (but not
defining) private copy constructor and assignment operator to forbid
copies. The link-error-as-enforcement trick predates `= delete` and is
fragile (silent same-translation-unit ICE breakage, confusing diagnostics).

Two flavours of fix:

1. Stand-alone non-copyable classes (InteractionGraphBase node/edge/graph
   family, FlexbbInteractionGraph, JobDigraph, AtomTreeCollection's
   ResidueAtomTreeCollection, Matcher, MonteCarlo's operator=): replace
   the unimplemented private declarations with public `= delete` copies.
   Where the old assignment took a non-const reference or returned `T const &`
   that was a holdover from the C++03 idiom; the modernized signatures take
   `T const &` and return `T &`.

2. Singleton-derived factories (utility::SingletonBase children): drop the
   redundant unimplemented copy/assignment declarations entirely. The base
   class already `= delete`s its own copy/assignment, which transitively
   makes the derived class's implicit copies deleted, so the extra lines
   were noise.

No behaviour change: copies/assignments that were link errors before are
now compile errors, which is the intended improvement in diagnostic
quality. Debug build passes clean.
Clang's -Wunused-private-field is suppressed while a class has any
declared (even unimplemented) private copy constructor / assignment,
because the compiler can't prove those bodies don't touch the field.
Replacing those declarations with = delete in PR RosettaCommons#697 let clang fully
analyze member usage, surfacing five orphaned scalar fields whose only
references live inside large /* ... */ blocks of disabled I/O code:

- DoubleLazyNode::procrastinated_
- LazyNode::procrastinated_
- LazyInteractionGraph::num_aa_types_
- PDInteractionGraph::num_nodes_in_file_
- PDInteractionGraph::num_file_aa_types_

Drop the fields and the matching constructor initializers. The commented
I/O functions that reference them are left alone (already dead).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants