Skip to content

Drop template-id from ctor/dtor names in numeric/ (GCC 14/15 -Werror=template-id-cdtor) - #723

Merged
roccomoretti merged 3 commits into
RosettaCommons:mainfrom
lyskov-ai:fix/numeric-gcc15-template-id-cdtor
Jul 3, 2026
Merged

Drop template-id from ctor/dtor names in numeric/ (GCC 14/15 -Werror=template-id-cdtor)#723
roccomoretti merged 3 commits into
RosettaCommons:mainfrom
lyskov-ai:fix/numeric-gcc15-template-id-cdtor

Conversation

@lyskov-ai

@lyskov-ai lyskov-ai commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

GCC 14+ enforces -Werror=template-id-cdtor: a class template may not name its own constructors or destructors with explicit template arguments — the injected-class-name must be used without <...>. numeric/MathVector.hh, numeric/MathMatrix.hh, and numeric/histograms/OneDHistogram.hh declared constructors (and, for the first two, the destructor) in the disallowed form, e.g.:

MathVector< T>() : ...
explicit MathVector< T>( const Size SIZE, ... ) : ...
~MathVector< T>() { ... }
OneDHistogram<key1>()= default;

Under GCC 14/15 in C++20 mode this fails to compile (error: template-id not allowed for constructor/destructor in C++20). The numeric/ occurrences broke the plain library debug build before it could even reach basic/ or core/. The OneDHistogram.hh occurrence is more subtle: its default constructor is only instantiated by a unit test (numeric/histograms/OneDHistogram.cxxtest.hh), not by any library code, so it slipped past a library-only build and only surfaced when building/running the unit test suite — this is what broke CI on the previous version of this PR.

This drops the < T> / <key1> from the constructor and destructor declarator-ids, making them consistent with the copy constructors in the same classes, which already use the correct injected-class-name form. Return types, operators, and new expressions that legitimately use the templated name are untouched. Pure syntactic correction, no semantic change.

Verified with a clean mode=debug library build and mode=debug cat=test unit-test build under GCC 15 (this machine's default), plus a full library build under GCC 14 — both fully green. A targeted scan of source/src, source/test, and source/src/devel for the same declaration pattern turned up no other occurrences.

Relationship to existing GCC 15 PRs (#555, #556)

This is not the first attempt at the GCC 15 build. Two earlier community PRs are still open and overlap with this one:

  • Fix C++20 template-id errors in constructors/destructors #555 — "Fix C++20 template-id errors in constructors/destructors" (@saberger). This contains the identical MathVector/MathMatrix/OneDHistogram template-id fix as this PR, and additionally covers core/scoring/lkball/LK_DomeEnergy.cc, protocols/forge/remodel/RemodelGlobalFrame.cc, utility/options/VectorOption_T_.hh, two unit tests, and tools/build/basic.settings — none of which have this same template-id-cdtor pattern currently (checked directly), so those are addressing separate GCC 15 issues.
  • Fixes for compiling with gcc15 #556 — "Fixes for compiling with gcc15" (@roccomoretti). The broader assorted GCC 15 fixes. Does not touch these three files.

Because #555 already lands the same fix, #723 is largely redundant with the numeric/ slice of that effort. It's offered as a minimal, narrowly-scoped version of just the template-id-cdtor correction in case it's useful to merge the build-blocking part independently; otherwise #555 (combined with #556, per its author's note) supersedes it. Closing this in favor of #555 + #556 is fine if the maintainers prefer to consolidate the GCC 15 work.

Note on diff size

This is a small change (three files, ~18 lines) — below the usual bundling threshold — but it is the complete fix for this pattern across the codebase: a scan of source/src, source/test, and source/src/devel found no other occurrences of a class template naming its own constructor/destructor with a template-id. Kept narrowly scoped to this one toolchain-compatibility pattern.

GCC 15 enforces -Werror=template-id-cdtor: a class template may not name
its own constructors or destructors with explicit template arguments
(the injected-class-name must be used without <...>). MathVector and
MathMatrix declared several ctors and their dtor as e.g.
'MathVector< T>()' and '~MathVector< T>()', which fails to compile under
GCC 15 in C++20 mode and broke the debug build before it reached any
core/ code.

Drop the '< T>' so these match the injected-class-name form already used
by the copy constructors in the same classes. No semantic change.
Same -Werror=template-id-cdtor issue as MathVector/MathMatrix: the
default constructor named itself 'OneDHistogram<key1>()' instead of
using the injected-class-name. This one only surfaces when something
instantiates the ctor (a unit test does), so it slipped past a
library-only build and is what broke CI on the previous version of
this fix.
@lyskov-ai
lyskov-ai force-pushed the fix/numeric-gcc15-template-id-cdtor branch from 5f88382 to 631830c Compare July 1, 2026 00:21
@lyskov-ai lyskov-ai changed the title Drop template-id from MathVector/MathMatrix ctor/dtor names (GCC 15 -Werror=template-id-cdtor) Drop template-id from ctor/dtor names in numeric/ (GCC 14/15 -Werror=template-id-cdtor) Jul 1, 2026
@roccomoretti

Copy link
Copy Markdown
Member

Looks like this needs beautification: https://b3.graylab.jhu.edu/test/915440

Running tools/python_cc_reader/beautify_changed_files_in_branch.py over the
files touched by this branch restores project-standard formatting that the
template-id edits had left off: member-initializer lists in MathVector/
MathMatrix are re-indented one level under their constructors (matching the
copy constructors in the same classes). Incidentally normalizes pre-existing
style in OneDHistogram.hh (namespace brace spacing, data-member indentation)
so the beautify check passes on all files in this branch's diff.

Whitespace-only; no semantic change.
lyskov-ai added a commit to lyskov-ai/rosetta that referenced this pull request Jul 2, 2026
This branch carries the same numeric/ template-id ctor/dtor fix as RosettaCommons#723;
run tools/python_cc_reader/beautify_changed_files_in_branch.py over the
changed files to restore project-standard formatting the template-id edits
had left off: member-initializer lists in MathVector/MathMatrix re-indented
one level under their constructors, plus incidental namespace/data-member
normalization in OneDHistogram.hh so the beautify check passes.

Whitespace-only; no semantic change.
@roccomoretti
roccomoretti merged commit 0b048cf into RosettaCommons:main Jul 3, 2026
1 check passed
lyskov pushed a commit that referenced this pull request Jul 9, 2026
…le cleanup (#728)

## Summary

This machine has GCC 12 through GCC 16 (16 is an experimental trunk
build) installed side by side. A survey of the debug library build under
each version found:

- **GCC 12, GCC 13**: build cleanly out of the box.
- **GCC 14, GCC 15**: need the `template-id-cdtor` fix in #723.
- **GCC 16**: needs #723's fix *plus* the changes in this PR.

Building under GCC 16 (with #723's fix applied) surfaced 16 unique
`-Werror` sites — mostly `-Wunused-but-set-variable`, plus two
`-Wmaybe-uninitialized` cases (one of which is a real bug):

1. **Real bug** — `core/chemical/CacheableResidueTypeSets.cc`: the copy
constructor initialized its base class with `CacheableData(*this)`
instead of `CacheableData(other)`, reading from the not-yet-constructed
destination object rather than the fully-constructed source. Harmless
today only because `CacheableData` has no data members of its own; still
wrong and exactly what GCC 16 is right to flag.
2. **False-positive trigger** —
`protocols/simple_moves/MissingDensityToJumpMover.cc`: the default
constructor called `MissingDensityToJumpMover::get_name()` (a qualified
call through `*this`, mid-construction) to build an argument for the
`Mover` base class. `get_name()` just returns a string literal, so it's
passed directly instead — avoids the pattern rather than working around
a compiler quirk.
3. **Dead loop counters** (13 sites across 9 files) — variables
incremented alongside a real loop iterator but never read anywhere:
`EnergyGraph.hh` (`iilag`, 2 of 4 occurrences — the other two are real
array indices and are untouched), `PDBInfo.cc` (`idx`, x2),
`mmtf_writer.cc` (`chainIndex`, `modelIndex`), `md.cc` (`imap`),
`StructureDataFactory.cc` (`cur_chain`), `FoldArchitectMover.cc`
(`count`), `pose_mod.hh` (`current_pos`), `DistanceScoreMover.cc`
(`ct_peaks`), `StructureDependentPeakCalibrator.cc` (`pose_ct`). No
behavior change — removed the tracking, left the actual iteration logic
untouched.
4. **Deliberately-unused, kept** — `SapConstraintHelper.cc`'s `offset`
is tracked "for symmetry" per an existing comment even though never
read. Rather than removing it against that stated intent, added an
explicit `(void)offset;` cast to satisfy the warning.
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