diff --git a/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CXXInferenceTest.kt b/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CXXInferenceTest.kt index 4a98fe702d..ff2e92a5de 100644 --- a/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CXXInferenceTest.kt +++ b/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CXXInferenceTest.kt @@ -150,17 +150,25 @@ class CXXInferenceTest { assertNotNull(a) assertTrue(a.isInferred) - val b = result.records["N::B"] + val n = result.namespaces["N"] + assertNotNull(n) + assertTrue(n.isInferred) + + val b = n.records["N::B"] assertNotNull(b) assertTrue(b.isInferred) - val c = result.records["C"] + val m = result.namespaces["M"] + assertNotNull(m) + assertTrue(m.isInferred) + + val c = m.records["N::C"] assertNotNull(c) assertTrue(c.isInferred) - val n = result.namespaces["N"] - assertNotNull(n) - assertTrue(n.isInferred) + val d = result.records["D"] + assertNotNull(d) + assertTrue(d.isInferred) } @Test diff --git a/cpg-language-cxx/src/test/resources/cxx/inference/superclass.cpp b/cpg-language-cxx/src/test/resources/cxx/inference/superclass.cpp index 376ab5092b..ae6f47550b 100644 --- a/cpg-language-cxx/src/test/resources/cxx/inference/superclass.cpp +++ b/cpg-language-cxx/src/test/resources/cxx/inference/superclass.cpp @@ -2,14 +2,22 @@ // You can use `clang++ -std=c++20 tricky_inference.cpp` to check, if it will compile. #include "superclass.h" -class D : A { +class E : A { }; -class E : N::B { +class F : N::B { - class F : C { +}; +namespace O { + class G : D { + // This is a very tricky case, we are in a sub-class within a namespace and + // we depend on a type with a qualified name. It could be that M::C is part of + // O and this is a partial qualified name, but the probability is higher that + // M is actually a namespace on its own. + class H : M::C { + }; }; -}; +} diff --git a/cpg-language-cxx/src/test/resources/cxx/inference/superclass.h b/cpg-language-cxx/src/test/resources/cxx/inference/superclass.h index ad75eeb7fb..97102d57e1 100644 --- a/cpg-language-cxx/src/test/resources/cxx/inference/superclass.h +++ b/cpg-language-cxx/src/test/resources/cxx/inference/superclass.h @@ -4,4 +4,8 @@ namespace N { class B {}; }; -class C {}; \ No newline at end of file +namespace M { + class C {}; +} + +class D {}; \ No newline at end of file