title: Finding anonymous enums with libclang
body: <p>Is there a way to detect anonymous enumerations using libclang without relying on the text in the spelling name? </p>
  
  <p>The python bindings to <a href="https://raw.githubusercontent.com/llvm-mirror/clang/release_36/bindings/python/clang/cindex.py">libclang</a> include functionality to detect whether C/C++ structs or unions are anonymous using <a href="https://github.com/llvm-mirror/clang/blob/release_37/bindings/python/clang/cindex.py#L1483">clang.cindex.Cursor.is_anonymous</a>, which ends up calling <a href="http://clang.llvm.org/doxygen/group__CINDEX__TYPES.html#ga6e0d2674d126fd43816ce3a80b592373">clang_Cursor_isAnonymous</a>. </p>
  
  <p>The following sample demonstrates the issue.</p>
  
  <pre><code>import sys
  from clang.cindex import *
  
  def nodeinfo(n):
      return (n.kind, n.is_anonymous(), n.spelling, n.type.spelling)
  
  idx = Index.create()
  
  # translation unit parsed correctly
  tu = idx.parse(sys.argv[1], ['-std=c++11'])
  assert(len(tu.diagnostics) == 0)
  
  for n in tu.cursor.walk_preorder():
      if n.kind == CursorKind.STRUCT_DECL and n.is_anonymous():
          print nodeinfo(n)
      if n.kind == CursorKind.UNION_DECL and n.is_anonymous():
          print nodeinfo(n)
      if n.kind == CursorKind.ENUM_DECL:
          if n.is_anonymous():
              print nodeinfo(n)
          else:
              print 'INCORRECT', nodeinfo(n)
  </code></pre>
  
  <p>Which when run on sample.cpp</p>
  
  <pre><code>enum
  {
      VAL = 1
  };
  
  struct s
  {
      struct {};
      union
      {
          int x;
          float y;
      };
  };
  </code></pre>
  
  <p>Gives:</p>
  
  <pre><code>INCORRECT (CursorKind.ENUM_DECL, False, '', '(anonymous enum at sample1.cpp:1:1)')
  (CursorKind.STRUCT_DECL, True, '', 's::(anonymous struct at sample1.cpp:8:5)')
  (CursorKind.UNION_DECL, True, '', 's::(anonymous union at sample1.cpp:9:5)')
  </code></pre>