From b028976509bf1028b66ed91265f7dce76f7ad440 Mon Sep 17 00:00:00 2001 From: Andrii Semkiv Date: Fri, 29 Nov 2024 15:21:27 +0100 Subject: [PATCH] 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 --- src/plugins/clangformat/clangformatbaseindenter.cpp | 10 ++++++++-- src/plugins/clangformat/clangformatconfigwidget.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/clangformat/clangformatbaseindenter.cpp b/src/plugins/clangformat/clangformatbaseindenter.cpp index cf48f4d61b5..7b4549a9b41 100644 --- a/src/plugins/clangformat/clangformatbaseindenter.cpp +++ b/src/plugins/clangformat/clangformatbaseindenter.cpp @@ -930,8 +930,14 @@ clang::format::FormatStyle ClangFormatBaseIndenterPrivate::customSettingsStyle( return currentQtStyle(preferences); clang::format::FormatStyle currentSettingsStyle; - const Utils::expected_str success = parseConfigurationFile(filePath, currentSettingsStyle); - QTC_ASSERT(success, return currentQtStyle(preferences)); + const Utils::expected_str 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; } diff --git a/src/plugins/clangformat/clangformatconfigwidget.cpp b/src/plugins/clangformat/clangformatconfigwidget.cpp index 56a51ef83de..9d65daadcee 100644 --- a/src/plugins/clangformat/clangformatconfigwidget.cpp +++ b/src/plugins/clangformat/clangformatconfigwidget.cpp @@ -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 success = parseConfigurationContent(m_editor->document()->contents().toStdString(), currentSettingsStyle);