From e2d0dce8baad24e76f965b095425e54db516e758 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sat, 18 Sep 2021 21:27:46 +0300 Subject: [PATCH] Generate valid C# for forwarded specializations Signed-off-by: Dimitar Dobrev --- src/Generator/AST/Utils.cs | 5 +++-- tests/NamespacesBase/NamespacesBase.h | 14 ++++++++++++++ tests/NamespacesDerived/Independent.h | 3 +++ tests/NamespacesDerived/NamespacesDerived.cpp | 4 ++++ tests/NamespacesDerived/NamespacesDerived.h | 3 +++ 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/NamespacesDerived/Independent.h diff --git a/src/Generator/AST/Utils.cs b/src/Generator/AST/Utils.cs index fc5f3e7605..7ead35cd6b 100644 --- a/src/Generator/AST/Utils.cs +++ b/src/Generator/AST/Utils.cs @@ -151,7 +151,8 @@ private static bool UnsupportedTemplateArgument( ClassTemplateSpecialization specialization, TemplateArgument a, ITypeMapDatabase typeMaps) { if (a.Type.Type == null || - IsTypeExternal(specialization.TranslationUnit.Module, a.Type.Type)) + IsTypeExternal( + specialization.TemplatedDecl.TemplatedDecl.TranslationUnit.Module, a.Type.Type)) return true; var typeIgnoreChecker = new TypeIgnoreChecker(typeMaps); @@ -178,7 +179,7 @@ private static ClassTemplateSpecialization GetParentSpecialization(Type type) { if (type.TryGetDeclaration(out Declaration declaration)) { - ClassTemplateSpecialization specialization = null; + ClassTemplateSpecialization specialization; do { specialization = declaration as ClassTemplateSpecialization; diff --git a/tests/NamespacesBase/NamespacesBase.h b/tests/NamespacesBase/NamespacesBase.h index d6e0544b33..f421cf1d9b 100644 --- a/tests/NamespacesBase/NamespacesBase.h +++ b/tests/NamespacesBase/NamespacesBase.h @@ -80,8 +80,22 @@ class DLL_API TemplateWithIndependentFields { public: void useDependentPointer(const T* t); + const T& constField() const; +private: + T* t = new T; }; +template +const T& TemplateWithIndependentFields::constField() const +{ + return *t; +} + +template +void TemplateWithIndependentFields::useDependentPointer(const T* t) +{ +} + class DLL_API HasVirtualInCore { public: diff --git a/tests/NamespacesDerived/Independent.h b/tests/NamespacesDerived/Independent.h new file mode 100644 index 0000000000..2afe45bfbe --- /dev/null +++ b/tests/NamespacesDerived/Independent.h @@ -0,0 +1,3 @@ +class Derived; +template class TemplateWithIndependentFields; +typedef TemplateWithIndependentFields ForwardedInIndependentHeader; \ No newline at end of file diff --git a/tests/NamespacesDerived/NamespacesDerived.cpp b/tests/NamespacesDerived/NamespacesDerived.cpp index e463a7c39d..8bd6c77501 100644 --- a/tests/NamespacesDerived/NamespacesDerived.cpp +++ b/tests/NamespacesDerived/NamespacesDerived.cpp @@ -110,3 +110,7 @@ bool operator<<(const Base& b, const char* str) { return false; } + +void forceUseSpecializations(ForwardedInIndependentHeader value) +{ +} diff --git a/tests/NamespacesDerived/NamespacesDerived.h b/tests/NamespacesDerived/NamespacesDerived.h index 0ddf676a55..a30af2f662 100644 --- a/tests/NamespacesDerived/NamespacesDerived.h +++ b/tests/NamespacesDerived/NamespacesDerived.h @@ -1,5 +1,6 @@ #include "../Tests.h" #include "../NamespacesBase/NamespacesBase.h" +#include "Independent.h" // Namespace clashes with NamespacesBase.OverlappingNamespace // Test whether qualified names turn out right. @@ -168,3 +169,5 @@ class TestComments */ class LinphoneAddress {}; }; + +DLL_API void forceUseSpecializations(ForwardedInIndependentHeader value);