Skip to content

Commit

Permalink
Workaround for identifying header files in the CFamily analyzer
Browse files Browse the repository at this point in the history
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
  • Loading branch information
michael-jabbour-sonarsource committed Nov 29, 2024
1 parent c3dd043 commit 02beb4c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Integration.Vsix/CFamily/VcxProject/FileConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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,
};
}
Expand Down

0 comments on commit 02beb4c

Please sign in to comment.