Skip to content

[gui] Prevent detaching from Q containers in range-based for loop#8311

Merged
firewave merged 1 commit intodanmar:mainfrom
gruenich:feature/qAsConst-prevent-detach
Mar 9, 2026
Merged

[gui] Prevent detaching from Q containers in range-based for loop#8311
firewave merged 1 commit intodanmar:mainfrom
gruenich:feature/qAsConst-prevent-detach

Conversation

@gruenich
Copy link
Contributor

@gruenich gruenich commented Mar 8, 2026

Use utils::as_const
Found by Clazy (range-loop-detach).

@gruenich
Copy link
Contributor Author

gruenich commented Mar 8, 2026

There are some more possible detachments, but they need temporary variables.

@gruenich gruenich force-pushed the feature/qAsConst-prevent-detach branch 2 times, most recently from 8dc86f4 to 1dfc753 Compare March 8, 2026 17:26
@firewave
Copy link
Collaborator

firewave commented Mar 9, 2026

Thanks for your contribution. Please use utils::as_const() instead. Currently mainly for consistency but I also have local changes which catch potential issues in its usage which are not covered by the std version.

@gruenich gruenich force-pushed the feature/qAsConst-prevent-detach branch from 1dfc753 to c2ede85 Compare March 9, 2026 21:52
Use internal utils::as_const
Found by Clazy (range-loop-detach).
@gruenich gruenich force-pushed the feature/qAsConst-prevent-detach branch from c2ede85 to e5a2cd8 Compare March 9, 2026 22:01
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 9, 2026

@firewave
Copy link
Collaborator

firewave commented Mar 9, 2026

For reference: https://github.com/KDE/clazy/blob/master/docs/checks/README-range-loop-detach.md. Unfortunately it is not very explanatory. But I came across the following which goes into much detail: https://www.kdab.com/blog-qasconst-and-stdas_const (spoiler - it prevents unwanted copies).

@firewave firewave merged commit 26f1287 into danmar:main Mar 9, 2026
70 checks passed
@gruenich gruenich deleted the feature/qAsConst-prevent-detach branch March 10, 2026 13:19
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.

2 participants