Biohazrd
Biohazrd copied to clipboard
Assert failure with out-of-scope inline definition for in-scope declaration
Found with OpenCV by indexing all root include files without marking nested files as in-scope.
[Fact]
public void InScopeDeclarationWithDefaultParameterValueWithOutOfScopeInlineDefinitionWithoutDefaultParameterValue()
{
TranslatedLibraryBuilder builder = new();
builder.AddFile(new SourceFile("A.h")
{
Contents = @"
int MyFunction(int a = 0);
#include ""B.h""
"
});
builder.AddFile(new SourceFile("B.h")
{
Contents = @"
inline int MyFunction(int a)
{
return a + a;
}
",
IsInScope = false,
IndexDirectly = false
});
TranslatedLibrary library = builder.Create();
Assert.Empty(library.ParsingDiagnostics.Where(d => d.IsError));
}
Clang implicitly adds a child cursor for the default parameter value 0
to the a
parameter in B.h
, and that cursor is attributed to A.h
since that's where the literal is.
The easy solution here might be to skip Clang statements here:
https://github.com/InfectedLibraries/Biohazrd/blob/8f179a30531cb063128887d1aa607178b62c09cd/Biohazrd/TranslationUnitParser.cs#L393
We already skip attributes for a similar reason.
This would likely also solve this contrived example (which also probably has a similar issue):
A.h (In scope, indexed)
int x =
#include "B.h"
;
B.h (Out of scope, not indexed)
100
Since Biohazrd basically ignores statements, I don't anticipate this having unintended consequences.