Skip to content

Further expansions of check_syntax#3313

Open
Lestropie wants to merge 8 commits into
devfrom
check_syntax
Open

Further expansions of check_syntax#3313
Lestropie wants to merge 8 commits into
devfrom
check_syntax

Conversation

@Lestropie
Copy link
Copy Markdown
Member

@Lestropie Lestropie commented Apr 18, 2026

  • Having discovered std::optional, I now really dislike checks for the number of rows in a matrix being zero as a flag for the absence of data. I find std::optional far more communicative in this respect. And it also has the prospect of distinguishing between something that was never present in the first place, versus something that was present but has been whittled away to zero size.

    • It can replace a std::unique_ptr<> for eg. a ProgressBar that is optionally constructed.
    • For metadata fetching functions, whether a function return a matrix or a std::optional of a matrix very clearly communicates whether that function must provide relevant data, or whether it may return nothing if no such data are available.
  • Expanding the regex searches to include new and delete is trivial, and it would make sense to me to maximise use of std::make_unique<> and std::make_shared<> and minimise use of naked pointers. There's a couple of places in cpp/core/ where there's still naked pointers in use---recalling particularly Thread::Queue and global tractography---but mostly we can get rid of them.
    The GUI code is however harder. There's a lot of passing responsibility for deleting dynamically-allocated objects to Qt, and lists of pointers etc.. So for now I've just excluded cpp/gui from these checks. Will have to see how difficult it is to resolve this against Run check_syntax as pre-commit hook #3310...
    Edit: This turned out to require no intervention: run_checks() had already been set up to pass the filename regardless of whether looping over all content of each file or parsing a git diff, which occurs one file at a time.

check_syntax has been used to find code where the size of a container has been compared to zero; for containers that do not themselves offer a .empty() function, use of a std::optional better communicates the prospect that data may be present or absent.
@Lestropie Lestropie self-assigned this Apr 18, 2026
@Lestropie Lestropie marked this pull request as draft April 18, 2026 06:52
Conflicts:
	cpp/cmd/mrregister.cpp
	cpp/cmd/sh2amp.cpp
	cpp/cmd/tcksample.cpp
	cpp/cmd/transformcompose.cpp
	cpp/core/dwi/tractography/ACT/shared.h
	cpp/core/dwi/tractography/algorithms/sd_stream.h
	cpp/core/dwi/tractography/seeding/list.h
	cpp/core/dwi/tractography/seeding/seeding.cpp
Prompt: "Modify parsing of command-line usage within script "check_syntax". If one or more filesystem paths are provided, then syntax checks should be performed only for the content within those specific files. Abort if file does not exist. Abort if file does not have .h or .cpp extension. Abort if both --diff and at least one path are specified.".

Generated-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@Lestropie Lestropie marked this pull request as ready for review April 25, 2026 12:16
@Lestropie Lestropie requested a review from jdtournier April 25, 2026 12:18
@Lestropie
Copy link
Copy Markdown
Member Author

@jdtournier Feel like it needs your approval to change the return type of some very long-standing API functions. See eg. cpp/core/dwi/gradient.h. Functions that throw an Exception on the absence of a valid table return an Eigen::Matrix<>, whereas those that just yield the table if present now return std::optional<Eigen::Matrix<>>.

@Lestropie
Copy link
Copy Markdown
Member Author

Worth noting that this PR expects use of std::make_shared<>, whereas previous versions of check_syntax precluded std::make_shared<>. See #960. Unfortunately my recollection of that saga is a little on the hazy side...

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.

1 participant