From b53aaae81bdff2d563dc2920e86d55caf1e817b8 Mon Sep 17 00:00:00 2001
From: Joao Matos <joao@tritao.eu>
Date: Fri, 8 Apr 2016 17:07:52 +0100
Subject: [PATCH] Fixes parsing of K&R-style C functions with no prototypes.

Fixes issue #641.
---
 src/CppParser/Parser.cpp | 30 ++++++++++++++++++++++++++++++
 tests/Common/Common.h    |  5 +++++
 2 files changed, 35 insertions(+)

diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp
index f6bf56cf..b9bdb8fe 100644
--- a/src/CppParser/Parser.cpp
+++ b/src/CppParser/Parser.cpp
@@ -1809,6 +1809,36 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
         Ty = A;
         break;
     }
+    case clang::Type::FunctionNoProto:
+    {
+        auto FP = Type->getAs<clang::FunctionNoProtoType>();
+
+        FunctionNoProtoTypeLoc FTL;
+        TypeLoc RL;
+        TypeLoc Next;
+        if (TL && !TL->isNull())
+        {
+            while (!TL->isNull() && TL->getTypeLocClass() != TypeLoc::FunctionNoProto)
+            {
+                Next = TL->getNextTypeLoc();
+                TL = &Next;
+            }
+
+            if (!TL->isNull() && TL->getTypeLocClass() == TypeLoc::FunctionNoProto)
+            {
+                FTL = TL->getAs<FunctionNoProtoTypeLoc>();
+                RL = FTL.getReturnLoc();
+            }
+        }
+
+        auto F = new FunctionType();
+        F->ReturnType = GetQualifiedType(FP->getReturnType(),
+            WalkType(FP->getReturnType(), &RL));
+        F->CallingConvention = ConvertCallConv(FP->getCallConv());
+
+        Ty = F;
+        break;
+    }
     case clang::Type::FunctionProto:
     {
         auto FP = Type->getAs<clang::FunctionProtoType>();
diff --git a/tests/Common/Common.h b/tests/Common/Common.h
index c64424c6..8dc43874 100644
--- a/tests/Common/Common.h
+++ b/tests/Common/Common.h
@@ -1088,3 +1088,8 @@ protected:
     };
     void function(ProtectedEnum param);
 };
+
+struct TestsTypes
+{
+    int(*FunctionNoProto)();
+};