Skip to content

Enable modernize-use-nodiscard clang-tidy check - #126158

Merged
alexey-milovidov merged 72 commits into
masterfrom
enable-modernize-use-nodiscard
Nov 16, 2026
Merged

alexey-milovidov merged 72 commits into
masterfrom
enable-modernize-use-nodiscard

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Enable the modernize-use-nodiscard clang-tidy check, which was disabled in .clang-tidy. It marks const member functions that return a value as [[nodiscard]], so -Wunused-result (an error with -Werror) catches a call whose result is dropped by mistake.

The attributes were added by running the check with --fix over all non-contrib translation units of the clang-tidy build (aarch64). About 14k declarations in 2200 files are changed.

Some const functions are mostly called for their side effect: they throw on failure, send a request, or signal an event, and the result is only a convenience. These get no attribute and are marked NOLINT(modernize-use-nodiscard) instead: assertTableExpression, checkRemoteHostFilter, EventFD::read/write, ExternalLoader::load/loadOrReload/reloadAllTriedToLoad, unloadDictionary, validateCodecAndGetPreprocessedAST, forEachPair, iterateGroups, finishWriting, checkTimeLimit, assertValid, SubmitBatch, and ACME doJWSRequest/finalizeOrder.

Calls of pure getters made only for validation or to trigger an exception (e.g. getNameForValue to check an enum value, CompressionCodecFactory::get to check a codec, and getters inside EXPECT_THROW in gtests) are cast to void.

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Enable the modernize-use-nodiscard clang-tidy check and add [[nodiscard]] to const member functions.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/126158]

Version info

  • Merged into: 26.11.1.2395-master (included in 26.11 and later)

…gests

Enable the `modernize-use-nodiscard` clang-tidy check, which marks `const`
member functions that return a value as `[[nodiscard]]`, so the compiler
reports a discarded result with `-Wunused-result`.

The attributes were added by running the check with `--fix` over all
translation units of the clang-tidy build.

Some `const` functions are mostly called for their side effect: they throw on
failure, send a request, or signal an event, and the result is only a
convenience. For them the attribute is not added, and the declaration has
`NOLINT(modernize-use-nodiscard)`. Examples are `assertTableExpression`,
`checkRemoteHostFilter`, `EventFD::read` and `EventFD::write`,
`ExternalLoader::load` and `loadOrReload`, and
`validateCodecAndGetPreprocessedAST`.

Calls of pure getters made only to validate an argument or to trigger an
exception (e.g. `getNameForValue` to check an enum value, or
`CompressionCodecFactory::get` to check a codec) are cast to `void`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reviewed, all good. This improves the code in general and eliminates potential bugs.

@alexey-milovidov alexey-milovidov self-assigned this Oct 16, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). label Oct 16, 2026
@PedroTadim

Copy link
Copy Markdown
Member

@alexey-milovidov are you sure you want to merge this? How can I review a 2200 file change PR?

@alexey-milovidov

Copy link
Copy Markdown
Member Author

@PedroTadim as usual, just read it.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

It is very easy - don't hesitate, open the diff, and review if you'd like. Or leave it to me.

@PedroTadim

Copy link
Copy Markdown
Member

Ok, let me try

@PedroTadim PedroTadim self-assigned this Oct 16, 2026
@PedroTadim

Copy link
Copy Markdown
Member

Why this is being labeled to const functions only?

alexey-milovidov and others added 2 commits October 17, 2026 10:14
…e-nodiscard

Conflicts (412 files, mostly from the function-signatures refactor) are
resolved by taking the `master` side of each hunk and re-applying
`[[nodiscard]]` to lines that are otherwise unchanged.
Re-ran `run-clang-tidy -checks='-*,modernize-use-nodiscard' -fix` over the
translation units touched by `master` since the previous merge base and by
the conflict resolution, and cast to `void` the calls made only for
validation or inside `EXPECT_THROW` (`reinterpretAs` signature check and
three gtests).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @PedroTadim it is how modernize-use-nodiscard is defined: it only suggests the attribute for const member functions with a non-void return and no non-const reference or pointer parameters, i.e. functions whose only observable effect is the return value, so ignoring the result is almost certainly a bug. Non-const functions often mutate state and return something optional (a status, an iterator, *this for chaining, the previous value), so dropping the result there is frequently intentional; annotating them would need case-by-case decisions rather than an automated pass.

I have also merged master (resolving 412 conflicts with the function-signatures refactor) and re-ran the check over the code that came from master.

@clickhouse-gh

clickhouse-gh Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f415f9e]

Summary: ✅


AI Review

Summary

Enables modernize-use-nodiscard, adds [[nodiscard]], and preserves calls made for validation or side effects through explicit (void) casts and lint exemptions. Reviewed all 2,368 changed files at head f415f9e3, including the prior discussion. No actionable findings. Existing CI reports show zero failed tests and passing arm_tidy shards; no local builds or tests were run.

Final Verdict

✅ Approve. No changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-build Pull request with build/testing/packaging improvement label Oct 17, 2026
alexey-milovidov and others added 5 commits October 18, 2026 18:34
…e-nodiscard

# Conflicts:
#	src/Interpreters/DiskSet.h
#	src/Interpreters/DiskSetImpl.h
#	src/Processors/Transforms/DistinctSetFilter.h
#	src/Storages/MergeTree/MergeTreeReaderIndex.h
# Conflicts:
#	src/DataTypes/Serializations/ISerialization.h
#	src/DataTypes/Serializations/SerializationDynamic.cpp
#	src/DataTypes/Serializations/SerializationDynamic.h
#	src/DataTypes/Serializations/SerializationDynamicElement.cpp
#	src/DataTypes/Serializations/SerializationLowCardinality.cpp
#	src/DataTypes/Serializations/SerializationMap.cpp
#	src/DataTypes/Serializations/SerializationMap.h
#	src/DataTypes/Serializations/SerializationMapKeyValue.cpp
#	src/DataTypes/Serializations/SerializationMapKeysOrValues.cpp
#	src/DataTypes/Serializations/SerializationMapSize.cpp
#	src/DataTypes/Serializations/SerializationObject.cpp
#	src/DataTypes/Serializations/SerializationObject.h
#	src/DataTypes/Serializations/SerializationObjectCombinedPath.cpp
#	src/DataTypes/Serializations/SerializationObjectDistinctPaths.cpp
#	src/DataTypes/Serializations/SerializationObjectDynamicPath.cpp
#	src/DataTypes/Serializations/SerializationObjectSharedData.cpp
#	src/DataTypes/Serializations/SerializationObjectSharedData.h
#	src/DataTypes/Serializations/SerializationObjectSharedDataPath.cpp
#	src/DataTypes/Serializations/SerializationSparse.cpp
#	src/DataTypes/Serializations/SerializationString.h
#	src/DataTypes/Serializations/SerializationSubObject.cpp
#	src/DataTypes/Serializations/SerializationSubObjectSharedData.cpp
#	src/DataTypes/Serializations/SerializationTuple.cpp
#	src/DataTypes/Serializations/SerializationVariant.cpp
#	src/DataTypes/Serializations/SerializationVariant.h
#	src/DataTypes/Serializations/SerializationVariantElement.cpp
#	src/DataTypes/Serializations/SerializationVariantElementNullMap.cpp
#	src/Disks/DiskObjectStorage/MetadataStorages/Web/MetadataStorageFromIndexPages.h
#	src/Disks/DiskObjectStorage/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.h
#	src/Functions/FunctionsNullSafeCmp.h
#	src/Functions/geoToH3.cpp
#	src/Functions/icebergTruncate.cpp
#	src/Functions/identity.h
#	src/Functions/toNullable.cpp
#	src/Functions/toTypeName.cpp
#	src/Interpreters/IJoin.h
#	src/Processors/Formats/Impl/ArrowIPC/RecordBatchDecoder.h
#	src/Processors/QueryPlan/JoinStepLogical.h
#	src/Processors/QueryPlan/Optimizations/applyStreamDisjointness.cpp
#	src/Storages/MergeTree/MergeTreeIndices.h
#	src/Storages/Statistics/StatisticsBasic.h
#	src/Storages/StorageMerge.h
Fix the new `modernize-use-nodiscard` findings from the latest merge of
`master`, found by running the check over the translation units touched
by `master` since the previous merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The `arm_tidy` build also checks the `unit_tests_dbms` translation units,
which the previous pass missed. Fix the `modernize-use-nodiscard`
findings there, found by running the check over all unit test sources.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126158&sha=3e3b2b40b8056460a15828c5499877cc72b48a4c&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29
#126158

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-build-system Build system (CMake, compilation, platform builds). and removed comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). labels Oct 21, 2026
@PedroTadim

Copy link
Copy Markdown
Member

@alexey-milovidov are you sure you want to continue with this?

alexey-milovidov and others added 2 commits October 22, 2026 17:09
…e-nodiscard

Conflicts were resolved by taking the code from `master` and keeping the
`[[nodiscard]]` attributes the PR added to the unchanged declarations.
Fix the new `modernize-use-nodiscard` findings from the latest merge of
`master`, found by running the check over the translation units touched
by `master` since the previous merge. `checkOrDropServerManagedCredentials`
is marked with `NOLINT` instead, because some callers use it only for the
exception it throws.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126158&sha=819057700fb473a4fd61aa567b1fd21f73e2e8ff&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29
#126158

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged the latest master (resolved 23 conflicts that came from the added [[nodiscard]]) and fixed the new modernize-use-nodiscard findings that master brought in, which were the cause of the red arm_tidy builds. clickhouse and unit_tests_dbms build locally. @PedroTadim, whether to continue with this PR is for @alexey-milovidov to decide; this update only keeps it mergeable and green.

alexey-milovidov and others added 3 commits October 22, 2026 18:38
# Conflicts:
#	src/AggregateFunctions/Combinators/AggregateFunctionNull.h
#	src/Client/BuzzHouse/Generator/SQLCatalog.h
#	src/Disks/DiskObjectStorage/MetadataStorages/PlainRewritable/PlainRewritableLayout.h
#	src/Disks/DiskObjectStorage/ObjectStorages/Cached/CachedObjectStorage.h
#	src/Functions/FunctionBaseAI.h
#	src/Functions/FunctionTopKFilter.cpp
#	src/Functions/IFunction.h
#	src/Functions/aiEmbed.cpp
#	src/Functions/aiSimilarity.cpp
#	src/IO/S3/ReadBufferFromGetObjectResult.h
#	src/Interpreters/Set.h
#	src/Processors/Formats/Impl/ArrowIPC/RecordBatchDecoder.h
#	src/Processors/Formats/Impl/ParquetMetadataCache.h
#	src/Processors/QueryPlan/IQueryPlanStep.h
#	src/Processors/QueryPlan/JoinStepLogical.h
#	src/Processors/QueryPlan/SourceStepWithFilter.h
#	src/Storages/ObjectStorage/DataLakes/IDataLakeMetadata.h
#	src/Storages/ObjectStorage/StorageObjectStorageConfiguration.h
Fixes the `modernize-use-nodiscard` findings in the `arm_tidy` builds
(e.g. `jsonRemove.cpp`, `ALPEncoding.cpp`), found by running `clang-tidy`
with this check over the files changed on `master` since the start of the PR.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126158&sha=6f42c86f18d378ba7d21f25a3b439eb322319586&name_0=PR&name_1=Build%20%28arm_tidy%2C%202%2F4%29
#126158

Co-Authored-By: Claude Opus 5.5 <[email protected]>
murphy-4o added a commit to groeneai/ClickHouse that referenced this pull request Nov 16, 2026
ClickHouse#131664 added the declaration while ClickHouse#126158 enabled modernize-use-nodiscard; each passed CI on its own, together they break the clang-tidy build on master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 16, 2026
…-order-dry-run-not-ready-set

Resolve the conflict in `src/Functions/array/arrayFold.cpp`: master added
`[[nodiscard]]` to `executeImpl` (`modernize-use-nodiscard`, ClickHouse#126158), which this
branch split into `executeImpl`, `executeImplDryRun` and `executeImplCommon`.
All three now carry `[[nodiscard]]`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 16, 2026
Master enables clang-tidy `modernize-use-nodiscard` (ClickHouse#126158) and marks every
`executeImpl` `[[nodiscard]]`; the `executeImplDryRun` and `executeImplCommon`
overrides added by this branch get the same attribute.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 16, 2026
Conflict in src/Analyzer/TrivialGroupByLimit.cpp: master added
`[[nodiscard]]` to `CheckArrayJoinExistsVisitor` (ClickHouse#126158), which this
branch moved to src/Analyzer/Utils.cpp. Keep the move and add the two
`[[nodiscard]]` attributes there, as `modernize-use-nodiscard` now requires.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 16, 2026
…uffer-insert-auth-ebd9

Resolve the conflicts with #125946 and
#126158.

- `StorageBuffer::writeBlockToDestination` keeps the identity and the flush stage of this
  branch and takes master's `query_context`: the direct write passes the inserting query's
  context to share its `max_threads` snapshot, a flush passes `nullptr` as on master. The
  snapshot is shared on the context this branch builds before restoring the identity.
- `getSQLSecurityOverriddenContext` keeps both master's snapshot sharing and the
  background-operation marker of this branch.
- `AsynchronousInsertQueue::InsertQuery::toTupleCmp` keeps master's `[[nodiscard]]` and
  the `auth_initial_address` key of this branch.

Co-authored-by: yakov <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 16, 2026
…h-dynamic-json

Resolve the conflicts with the `[[nodiscard]]` attributes of ClickHouse#126158 in
`MergedData.h` and `MergingSortedAlgorithm.h`, and mark the new const getters
`extraBytesPerRow` and `maxBlockSizeBytes` `[[nodiscard]]` as well, since
master now enables `modernize-use-nodiscard`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 16, 2026
modernize-use-nodiscard is enabled on master since ClickHouse#126158.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 16, 2026
Master now enforces clang-tidy `modernize-use-nodiscard` (ClickHouse#126158), so the
`canRejectValues` overrides get `[[nodiscard]]` like the neighbouring
`isTrivial` overrides, and bans plain `std::vector` in `src/Processors/Formats`
(ClickHouse#126530), so the decode ranges use `VectorWithMemoryTracking`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
buggins added a commit to buggins/ClickHouse that referenced this pull request Nov 17, 2026
`modernize-use-nodiscard` of clang-tidy is enabled on master since 2026-11-15, and the new `enumerateSettings` and
`enumerateSettingsWithConstraints` const methods of the engine settings failed the tidy build without the attribute.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123041&sha=cd63e43cc1f37c1d7ee95901c404cc54aace9c1b&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29
Related: ClickHouse#123041
Related: ClickHouse#126158

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 18, 2026
master enabled the `modernize-use-nodiscard` clang-tidy check in ClickHouse#126158,
after this PR's last CI run. The merge queue's `Clang-tidy (changed files)`
job then flagged the new declaration (RuntimeFilterLookup.h:251 in the
merge commit) and removed the PR from the queue. This matches master's
`ExactSetRuntimeFilter::getValuesColumn`, which the same check annotated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 18, 2026
`modernize-use-nodiscard`, enabled on master by ClickHouse#126158, flags it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 18, 2026
…w-defer-plan-optimization

Since ClickHouse#130552 a DEFINER view read by its definer is not sealed, so the views of
the clone cases in 05257 now have another definer: the default user still reads
them sealed with the plan visible. ReadFromSealedViewStep takes the comment on
getBuiltChildPlans that ClickHouse#132608 added to the class in StorageView.cpp, and
[[nodiscard]] for modernize-use-nodiscard (ClickHouse#126158).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 18, 2026
`modernize-use-nodiscard` is enabled on master (ClickHouse#126158); the other
virtual predicates of `SourceStepWithFilterBase` carry the attribute too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 18, 2026
clang-tidy's modernize-use-nodiscard (on since ClickHouse#126158) failed every
Build (arm_tidy) shard on LegacyHeaderNames::empty, and on getLegacyName,
hasNoCandidates and the const getLegacyActionNodeNames in PlannerContext.h.

Test comments: say "case" instead of "arm", and stop claiming the quoting
helper treats exactly six words as keywords (master quotes more).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 19, 2026
Resolve the conflicts of the cherry-pick of #132416 to 26.9. The fix applies in full; the differences
from the original diff come only from master-only neighbours that 26.9 does not have:

- `ArrowIPCBlockInputFormat.cpp`: 26.9 still checks that dictionary values are unique after registering
  them (master dropped the check in #125677). Keep the check and look the values up by the dictionary use,
  as the registry is now keyed by it.
- `RecordBatchDecoder.cpp`: 26.9 has no `TypeKind::RunEndEncoded` case in `collectDictionaryUses`
  (run-end encoding, #126207, is master-only), so there is no call to pass `below_union` to there.
  The struct case keeps the 26.9 helpers `tupleElementHint` / `childPath` (master renamed them in
  #125674) and passes `below_union` as the original change does.
- `RecordBatchDecoder.cpp`: include `base/scope_guard.h` for the two new `SCOPE_EXIT` uses. On master
  the include came with the big-endian reader (#126562); 26.9 does not include it, directly or
  transitively.
- `RecordBatchDecoder.h`: no `[[nodiscard]]` on the changed declarations, as on the rest of the 26.9
  file (master added them in #126158).

Co-authored-by: yakov <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 19, 2026
Resolve the conflicts of the cherry-pick of #132416 to 26.10. The fix applies in full; the differences
from the original diff come only from master-only neighbours that 26.10 does not have:

- `RecordBatchDecoder.cpp`: 26.10 has no `TypeKind::RunEndEncoded` case in `collectDictionaryUses`
  (run-end encoding, #126207, is master-only), so there is no call to pass `below_union` to there.
  The struct case keeps the 26.10 helpers `tupleElementHint` / `childPath` (master renamed them in
  #125674) and passes `below_union` as the original change does.
- `RecordBatchDecoder.cpp`: include `base/scope_guard.h` for the two new `SCOPE_EXIT` uses. On master
  the include came with the big-endian reader (#126562); 26.10 does not include it, directly or
  transitively.
- `RecordBatchDecoder.h`: no `[[nodiscard]]` on the changed declarations, as on the rest of the 26.10
  file (master added them in #126158).

Co-authored-by: yakov <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 20, 2026
…g-merge-no-per-row-rowref

Conflicts resolved against master:
- ClickHouse#126158 added [[nodiscard]] to lines this PR edits: kept, except on
  RowRefWithOwnedChunk::firstNonEqualSortColumnsWith, which this PR removes.
- ClickHouse#131513 gated the part-level shortcut of rowsHaveDifferentSortColumns with
  nonzero_level_parts_have_unique_keys: the cursor overload keeps that gate,
  so CollapsingMergeTree still compares rows of merged parts.
- ClickHouse#131560 counts selected rows in vertical FINAL: kept, the selection is
  appended with push_back instead of insert(Field).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 23, 2026
…scard]]

Master enabled `modernize-use-nodiscard` (ClickHouse#126158), which flags them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-build-system Build system (CMake, compilation, platform builds). pr-build Pull request with build/testing/packaging improvement pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants