Clang Format: Fix partially initialized style

"Always initialize an object".
`clang::format::FormatStyle` does not have a default constructor,
so the options that are not explicitly specified in the config
had garbage values.
Improved error reporting.

Task-number: QTCREATORBUG-32051
Change-Id: Id5d5d1b8247b61725644e0aa5f774e35635fcb41
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Andrii Semkiv
2024-11-29 15:21:27 +01:00
parent 91fcdcce2d
commit b028976509
2 changed files with 9 additions and 3 deletions

View File

@@ -930,8 +930,14 @@ clang::format::FormatStyle ClangFormatBaseIndenterPrivate::customSettingsStyle(
return currentQtStyle(preferences);
clang::format::FormatStyle currentSettingsStyle;
const Utils::expected_str<void> success = parseConfigurationFile(filePath, currentSettingsStyle);
QTC_ASSERT(success, return currentQtStyle(preferences));
const Utils::expected_str<void> result = parseConfigurationFile(filePath, currentSettingsStyle);
if (!result) {
qCWarning(clangIndenterLog)
<< QString{"Failed to parse config %1. Falling back to the Qt style."}.arg(
filePath.toUserOutput())
<< result.error();
return currentQtStyle(preferences);
};
return currentSettingsStyle;
}

View File

@@ -201,7 +201,7 @@ void ClangFormatConfigWidget::initEditor()
this);
connect(m_editor->document(), &TextEditor::TextDocument::contentsChanged, this, [this] {
clang::format::FormatStyle currentSettingsStyle;
clang::format::FormatStyle currentSettingsStyle{};
const Utils::expected_str<void> success
= parseConfigurationContent(m_editor->document()->contents().toStdString(),
currentSettingsStyle);