diff --git a/src/AST/TypeExtensions.cs b/src/AST/TypeExtensions.cs index 6636d880..ebbfe5de 100644 --- a/src/AST/TypeExtensions.cs +++ b/src/AST/TypeExtensions.cs @@ -90,26 +90,19 @@ if (ptr == null) return false; return ptr.Pointee.IsPrimitiveType(primitive); - } - - public static bool IsPointerTo(this Type t, out T type) where T : Type - { - var ptr = t as PointerType; - - if (ptr == null) - { - var functionPointer = t as MemberPointerType; - if (functionPointer != null) - { - type = functionPointer.Pointee as T; - return type != null; - } - type = null; - return false; - } - - type = ptr.Pointee as T; - return type != null; + } + + public static bool IsPointerTo(this Type t, out T type) where T : Type + { + var pointee = t.GetPointee(); + type = pointee as T; + if (type == null) + { + var attributedType = pointee as AttributedType; + if (attributedType != null) + type = attributedType.Modified.Type as T; + } + return type != null; } public static bool IsTagDecl(this Type t, out T decl) where T : Declaration diff --git a/tests/Basic/Basic.Tests.cs b/tests/Basic/Basic.Tests.cs index fc289418..c79f4079 100644 --- a/tests/Basic/Basic.Tests.cs +++ b/tests/Basic/Basic.Tests.cs @@ -176,6 +176,14 @@ public class BasicTests : GeneratorTestFixture var delegates = new TestDelegates(); var doubleSum = delegates.A(2) + delegates.B(2); Assert.AreEqual(8, doubleSum); + } + + [Test] + public void TestAttributedDelegate() + { + var attributedDelegate = basic.GetAttributedDelegate(); + var result = attributedDelegate(2); + Assert.AreEqual(4, result); } [Test] diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index 29012b47..d8550963 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -259,6 +259,14 @@ struct DLL_API TestDelegates MemberDelegate C; }; +// Tests delegate generation for attributed function types +typedef int(__cdecl *AttributedDelegate)(int n); +DLL_API int __cdecl Double(int n) { return n * 2; } +DLL_API AttributedDelegate GetAttributedDelegate() +{ + return Double; +} + // Tests memory leaks in constructors // C#: Marshal.FreeHGlobal(arg0); struct DLL_API TestMemoryLeaks