syncqt.cpp: don't init static variables with non-static data
Static variables are only initialized once, when control passes over their definition for the first time¹. If they are initialized with non-static data, like the contents of a non-static data member, or the address of one, then all following uses of the object will continue to use the first control pass' data, even if the data members were from an object that has since been deleted. This whole construct appears to have worked merely because these functions are only executed once, or at least not on different objects. But better remove the dangerous construct while it hasn't broken something, yet, and before we e.g. make syncqt a library² or add a mode that makes it scan multiple modules at once. Requires to capture more variables in the parseArgument() lambda; more than fits into an explicit capture list, so use a [&] catch-all instead. As a drive-by, use CTAD to not have to mention the number of elements in a std::array, but have the compiler deduce them, and add const, where it's missing. Amends b89d63515bb352cecfd87e709320a2db5b6a1906 (and maybe a few in-between, we'll see when cherry-picking). ¹ Except corner-case like when initialization fails by throwing an exception. ² see similar ideas for moc, e.g.: QTBUG-132820 Pick-to: 6.8 6.5 Change-Id: I65a73059151e3d39341939f613080e6d833a4c30 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> (cherry picked from commit 01ced9d45ab87f5d3fd41525621c680965517ee7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
3e7f2f2048
commit
8e9ef8df5b
@ -337,7 +337,7 @@ private:
|
||||
std::string ssgHeadersFilter;
|
||||
std::string privateHeadersFilter;
|
||||
std::string publicNamespaceFilter;
|
||||
static std::unordered_map<std::string, CommandLineOption<std::string>> stringArgumentMap = {
|
||||
const std::unordered_map<std::string, CommandLineOption<std::string>> stringArgumentMap = {
|
||||
{ "-module", { &m_moduleName } },
|
||||
{ "-sourceDir", { &m_sourceDir } },
|
||||
{ "-binaryDir", { &m_binaryDir } },
|
||||
@ -356,14 +356,14 @@ private:
|
||||
{ "-publicNamespaceFilter", { &publicNamespaceFilter, true } },
|
||||
};
|
||||
|
||||
static const std::unordered_map<std::string, CommandLineOption<std::set<std::string>>>
|
||||
const std::unordered_map<std::string, CommandLineOption<std::set<std::string>>>
|
||||
listArgumentMap = {
|
||||
{ "-headers", { &m_headers, true } },
|
||||
{ "-generatedHeaders", { &m_generatedHeaders, true } },
|
||||
{ "-knownModules", { &m_knownModules, true } },
|
||||
};
|
||||
|
||||
static const std::unordered_map<std::string, CommandLineOption<bool>> boolArgumentMap = {
|
||||
const std::unordered_map<std::string, CommandLineOption<bool>> boolArgumentMap = {
|
||||
{ "-nonQt", { &m_isNonQtModule, true } }, { "-debug", { &m_debug, true } },
|
||||
{ "-help", { &m_printHelpOnly, true } },
|
||||
{ "-internal", { &m_isInternal, true } }, { "-all", { &m_scanAllMode, true } },
|
||||
@ -375,7 +375,7 @@ private:
|
||||
std::string *currentValue = nullptr;
|
||||
std::set<std::string> *currentListValue = nullptr;
|
||||
|
||||
auto parseArgument = [¤tValue, ¤tListValue](const std::string &arg) -> bool {
|
||||
auto parseArgument = [&](const std::string &arg) -> bool {
|
||||
if (arg[0] == '-') {
|
||||
currentValue = nullptr;
|
||||
currentListValue = nullptr;
|
||||
@ -502,7 +502,7 @@ private:
|
||||
// Convert all paths from command line to a generic one.
|
||||
void normilizePaths()
|
||||
{
|
||||
const std::array<std::string *, 9> paths = {
|
||||
const std::array paths = {
|
||||
&m_sourceDir, &m_binaryDir, &m_includeDir,
|
||||
&m_installIncludeDir, &m_privateIncludeDir, &m_qpaIncludeDir,
|
||||
&m_rhiIncludeDir, &m_stagingDir, &m_versionScriptFile,
|
||||
@ -1565,7 +1565,7 @@ public:
|
||||
[[nodiscard]] bool generateDeprecatedHeaders()
|
||||
{
|
||||
static std::regex cIdentifierSymbolsRegex("[^a-zA-Z0-9_]");
|
||||
static std::string guard_base = "DEPRECATED_HEADER_" + m_commandLineArgs->moduleName();
|
||||
const std::string guard_base = "DEPRECATED_HEADER_" + m_commandLineArgs->moduleName();
|
||||
bool result = true;
|
||||
for (auto it = m_deprecatedHeaders.begin(); it != m_deprecatedHeaders.end(); ++it) {
|
||||
const std::string &descriptor = it->first;
|
||||
|
Loading…
x
Reference in New Issue
Block a user