From 02beb4c8acaf4bf4c72a340c456bee72f93d8341 Mon Sep 17 00:00:00 2001 From: Michael Jabbour Date: Fri, 29 Nov 2024 16:49:56 +0100 Subject: [PATCH] Workaround for identifying header files in the CFamily analyzer Normally, the CFamily analyzer deduces that the file being analyzed is a header when there is no exact match for the file name in the given compilation database. This is a temporary workaround to communicate with the analyzer that the current file is a header file. This helps the analyzer avoid reporting some FPs. See https://sonarsource.atlassian.net/browse/CPP-2743 --- src/Integration.Vsix/CFamily/VcxProject/FileConfig.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Integration.Vsix/CFamily/VcxProject/FileConfig.cs b/src/Integration.Vsix/CFamily/VcxProject/FileConfig.cs index 93e11de61..1285eb00a 100644 --- a/src/Integration.Vsix/CFamily/VcxProject/FileConfig.cs +++ b/src/Integration.Vsix/CFamily/VcxProject/FileConfig.cs @@ -46,7 +46,8 @@ public static FileConfig TryGet(ILogger logger, ProjectItem dteProjectItem, stri return null; } - CmdBuilder cmdBuilder = new CmdBuilder(vcFile.ItemType == "ClInclude"); + var isHeader = vcFile.ItemType == "ClInclude"; + CmdBuilder cmdBuilder = new CmdBuilder(isHeader); var compilerPath = vcConfig.GetEvaluatedPropertyValue("ClCompilerPath"); if (string.IsNullOrEmpty(compilerPath)) @@ -75,7 +76,9 @@ public static FileConfig TryGet(ILogger logger, ProjectItem dteProjectItem, stri { CDDirectory = Path.GetDirectoryName(vcProject.ProjectFile), CDCommand = cmdBuilder.GetFullCmd(), - CDFile = absoluteFilePath, + // A hack to communicate with the CFamily analyzer that this is a header file. + // A long-term solution should be investigated in CPP-5898. + CDFile = isHeader ? "non_existent_file" : absoluteFilePath, EnvInclude = envINCLUDE, }; }