Repository: terryyin/lizard

Issue:
Lizard not handling functions within unions correctly
For the following code:

```c++
namespace foo{
	
	void myFunction() { }
	
	union bar{
		void mySecondFunction() { }
	};
	
	class dog{
		void bark() { }
	};
};
```

Lizard generates the following output:
![doxunionbug](https://user-images.githubusercontent.com/29785071/27710254-b019601a-5ce4-11e7-9706-da253a28276e.png)

This shows that the long_name generated by lizard includes the namespace or the class that a function is contained in but does not contain the union the function is contained in. This inconsistency can cause issues for code analysis tools.

Discussion:

Patch:
diff --git a/lizard_languages/clike.py b/lizard_languages/clike.py
index 33e1c3d..2c1af01 100644
--- a/lizard_languages/clike.py
+++ b/lizard_languages/clike.py
@@ -155,7 +155,7 @@ class CLikeNestingStackStates(CodeStateMachine):
         if token == "template":
             self._state = self._template_declaration
 
-        elif token in ("struct", "class", "namespace"):
+        elif token in ("struct", "class", "namespace", "union"):
             self._state = self._read_namespace
 
         elif token == "{":


Test patch:
diff --git a/test/test_languages/testCAndCPP.py b/test/test_languages/testCAndCPP.py
index cd5569b..41a1b13 100644
--- a/test/test_languages/testCAndCPP.py
+++ b/test/test_languages/testCAndCPP.py
@@ -461,6 +461,11 @@ class Test_c_cpp_lizard(unittest.TestCase):
         self.assertEqual(1, len(result))
         self.assertEqual("A::foo", result[0].name)
 
+    def test_union_as_qualifier(self):
+        """Union as namespace for functions."""
+        result = get_cpp_function_list("union A { void foo() {} };")
+        self.assertEqual(1, len(result))
+        self.assertEqual("A::foo", result[0].name)
 
 class Test_cpp11_Attributes(unittest.TestCase):
     """C++11 extendable attributes can appear pretty much anywhere."""