STYLE: Replace non-POD string constants with constexpr QLatin1String#1410
Open
hjmjohnson wants to merge 1 commit intocommontk:masterfrom
Open
STYLE: Replace non-POD string constants with constexpr QLatin1String#1410hjmjohnson wants to merge 1 commit intocommontk:masterfrom
hjmjohnson wants to merge 1 commit intocommontk:masterfrom
Conversation
This was referenced Apr 2, 2026
640dab9 to
1e01702
Compare
8 tasks
Contributor
Author
CTK Validation Report for PR #1410Date: 2026-04-03T13:37:14Z
Validation Actions Performed
CTK-in-Slicer Build Detail (classified warnings)
Slicer Test Detail (classified failures)
CTK Test Failures (proposed
|
Static QString variables have non-trivial constructors and destructors,
triggering clazy:non-pod-global-static and introducing Static
Initialization Order Fiasco (SIOF) risk. All affected constants are
pure compile-time string literals, so they can be expressed as
constexpr QLatin1String with zero runtime overhead.
Qt5 / Apple-clang compatibility: QLatin1String(const char*) calls
strlen(), which is not constexpr under Apple clang. Use the
two-argument constructor with sizeof("literal") - 1 instead:
static constexpr QLatin1String NAME{
"literal", static_cast<int>(sizeof("literal") - 1)};
For class static members (ctkPluginFrameworkDebug), the constexpr
definition moves entirely into the header; the out-of-line QString
definitions and the CTK_OSGI intermediate variable are removed.
No call-site changes are required -- QLatin1String implicitly converts
to QString for all existing uses.
Files changed:
- Libs/CommandLineModules/Frontend/QtGui/ctkCmdLineModuleObjectTreeWalker.cpp
- Libs/PluginFramework/ctkBasicLocation.cpp
- Libs/PluginFramework/ctkLocationManager.cpp
- Libs/PluginFramework/ctkPluginFrameworkDebug_p.h
- Libs/PluginFramework/ctkPluginFrameworkDebug.cpp
- Libs/PluginFramework/ctkPluginFrameworkLauncher.cpp
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1e01702 to
3e92050
Compare
Contributor
Author
|
@jamesobutler I've been developing a method to more completely test each proposed change to CTK. See the commit message: #1410 (comment). I built the CTK source code
The report indicates no regressions to tests or builds. If there are other bits of information you think would be helpful, let me know and I'll try to add them. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
clazy:non-pod-global-staticwarnings on file-scope and class-static string constants by converting them tostatic constexpr QLatin1String.This is one of two PRs split from a combined approach (the companion PR #1409 handles
ctkLoggerglobals viaQ_GLOBAL_STATIC_WITH_ARGS).Problem
static QStringat file scope or as class static members have non-trivial constructors and destructors, triggering thenon-pod-global-staticclazy warning. These are subject to the Static Initialization Order Fiasco (SIOF) and add unnecessary startup/teardown overhead.Approach
QLatin1Stringis a lightweight wrapper around aconst char*+ length — no heap allocation, trivially constructible/destructible. All affected constants are pure compile-time string literals, making them idealconstexprcandidates.Qt5 / Apple-clang compatibility:
QLatin1String(const char*)callsstrlen(), which Apple clang does not treat asconstexpr. The 2-argument constructor withsizeof("literal") - 1is used instead:For class static members (
ctkPluginFrameworkDebug), theconstexprdefinition moves entirely into the header (C++17static constexpris implicitlyinline), the out-of-lineQStringdefinitions in the.cppare removed, and theCTK_OSGIintermediate variable becomes unnecessary:No call-site changes required —
QLatin1Stringimplicitly converts toQStringfor all existing uses.Files Changed
Libs/CommandLineModules/Frontend/QtGui/ctkCmdLineModuleObjectTreeWalker.cppLibs/PluginFramework/ctkBasicLocation.cppLibs/PluginFramework/ctkLocationManager.cppLibs/PluginFramework/ctkPluginFrameworkDebug_p.hconstexprinlineLibs/PluginFramework/ctkPluginFrameworkDebug.cppCTK_OSGIvariableLibs/PluginFramework/ctkPluginFrameworkLauncher.cppComparison with PR #1398
const T& name()constexpr QLatin1String name()suffixTesting
Built successfully against Qt5 (
cmake-build-clazy-qt5, Apple clang) and Qt6 (cmake-build-clazy-qt6) on macOS ARM64.Part of the fix for #1407. See also companion PR #1409 for
Q_GLOBAL_STATIC_WITH_ARGSlogger fixes, and draft PR #1411 for thectkDICOMModalitiesAPI deprecation strategy.🤖 Generated with Claude Code