<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJy9Vktv4zYQ_jXyhYghU3EsH3RI7DU2KFC03aTNzaDEscWEJg2SiuN_3yGph1-7lwI1BFEczvOb4YxLzY_FM2E74sxRqC1xmjQWiBRlJVnc10xxCYSRitTAOBiyERISuiBl44hpFBEK2VwtLBHWNpBkj0m6TNLHl0jCIzgT7c6Th7R9wtYd98BhQxoltCLJ7CmSCf7QAhFJdkF5v6J89JRktiQl4-ugrKdG1Vut24NrK7srnepU5_B97vtpqJXm4IHjsNOBcI7KTfmEZkJVskHJhNKA_V2V0NXi7YczmJhxjeRr1mwxsD4rDl_Il327xSe0dQbYrj9urM-3Yjuwe1YBsY4PwYV3gIMJldA8oXMPFfm_f69Yi9pXBAcM1AAngoNyYiOwlhI6W7yFqPGLdElrSZg6_06yJQkQrSuM3kHLnqe-fvE1P0n34u3FMGUlc1gZr0o4X4nuRMWeGQsXPB6cvlxItOp1Y7pcTBpuVCPl3pnW5vX-yvL6d63g3DuxQZ1555F3qtcyPy_jCozxKcfHu_GqWClDQQb_8ab3pkKAY_JnI5zzRYbcnSDgpT-7CvAVgr2bnLvl78RJzXgUF42x2pAqLgN8W3AXYUbONqxzvVHkU1jkqoXkBtQF1FUrvDglJtOnZLpEzsGNCHC7QwiwflqSFPi9ZA5bW_hcc_y-grNNbIC_DySq-w3T7alBJials7ReCZB8iWXr47rWFyLQjevwHjTHC39t7McepGxPvM5g83auWiy61PQUA64xyvvoIf3bg7v-CzyQcCHvZc-RHartok10ueLC7vWt-_Gz5LYC3ZVsr878rN3e7JXh_bhx2AMqvduLiMoCp5b68E0NBxbxg0n5zTNBBIltqhrDt410Pxs_Cb0neANWNa3a_heX97h8_IK4i4v6hbtiHEbmBmvQjwTsWMN0wu4Fn2COOB2xZnDgWlICqHbycuIOAhv0AXOGs0R18sMUu1SAc0greezltYriCAEewdceKofk8kh2MD518p-aYaZmlhyMRujQ1u4YxlmSrQKq3_XBNxL2qQUPfkTXsKWgectkH1_Fwr-Ij6tIUdOpxRf08cP2pfbEtEXKiBcZn2dzNmKNq7UpWvofWDajxsiidm5vfSLpCp-tcHVTjrEWcCPlZ7fc7Y1-x1hxG0Yw2llNs8n9w6guaJbOKSvnQKf5PN_kWU4nM5pNpveM5nySjiQrQdrCNxRKFRzaKY4Nfboc_XcPREFTStPJZIJGaZaPp_ebtKL5Q76ZpZN09pDcp4DTV469nrE225Epgsqy2Vo8lMI6Oxwya8VWARSxA46ccBKK_n-c0o4ctInXY6iBUfCqCC79C5yH8ko>53146</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            libclang not working as expected
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          BaoshanPang
      </td>
    </tr>
</table>

<pre>
    I am trying to use libclang to handle a c header file, but run into this issue:
This is the header file:
```
typedef union {
    int i;
    int j;
    int k;
} bad_union;
union good_union {
    int m;
    int n;
};
```
This is the code to demo the issue:

```
#include "clang-c/CXString.h"
#include <clang-c/Index.h>
#include <iostream>
using namespace std;

int main() {                                                                                                                 Use of undeclared identifier 'CXIndex' 
  CXIndex index = clang_createIndex(0, 0);
  CXTranslationUnit unit = clang_parseTranslationUnit(
      index, "t.h", nullptr, 0, nullptr, 0, CXTranslationUnit_None);
  if (unit == nullptr) {
    cerr << "Unable to parse translation unit. Quitting." << endl;
    exit(-1);
  }

  CXCursor cursor = clang_getTranslationUnitCursor(unit);
  clang_visitChildren(
      cursor,
      [](CXCursor c, CXCursor parent, CXClientData client_data) {
          if (clang_getCursorKind(c) == CXCursor_FieldDecl){
              cout << clang_getCString(clang_getCursorSpelling(c)) << endl;
          }
         return CXChildVisit_Recurse;
      },
      nullptr);

  clang_disposeTranslationUnit(unit);
  clang_disposeIndex(index);
}
```

After compiling, linking and  running I get such result:
```
$ ./h2c
i
j
k
i
j
k
m
n
```

i.e, for the 'bad_union' every field has been handled twice while in the 'good_union' every field is only handled once which is expected by me.

What's wrong in my code? and How to avoid the twice traversal for the case like 'bad_union'?

Thanks,
Baoshan
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VkuP4jgQ_jXhYjUKCa8ccuiGQdNaabW70z3bN2TiCnG3sZHtNM2_37KdBxBmjouiOC7X86tyFTvFzvkzoQdi9ZnLPbGK1AaI4LtC0LCvqGQCCCUFqYAy0KTkAqJkRXa1JbqWhEtksxU3hBtTQ5Q-RvE6ih9fAgmP4Eq0PY_mcfP4rT0fgUFJasmVJNHiKZAJ_tAC4VF6Q3kfUD46SrRYkx1lW6-sowbVe6Wag6GVw0CnvNTZf1_7fhlqoRg44BgclCdco3JXPkpSLgtRo2SUJB77hyJKNqu3H1ZjYsYVkoes6apnfZYMvpAv_XaPjytjNdBDd1wbl29JD2COtABiLOuD828PB-UySpZRkjmoyP_9e8VaVK4iGGCgGhjhDKTlJcdaipLF6s1HjV-kTVpDwtS5d5SuiYdoW2D0Fhr2ZezqF1_ZRbpXby-aSiOoxcp4ldy6SrQXKo5UG7jhceB05UKCVacb02VD0nAjayGOVjc2h_uB5e2fSsK1d7xEncvWI-dUpyW7LuMCtHYpx8e58SrpTviC9P7jTe9M-QDH5O-aW-uKDLlbQcBLf3UV4MsH-zC5dsvdiYuacSiuam2UJkVYevj2YG_CDJxNWNd6g8gnN8hVccE0yBuoi0Z4dUmMZk_RbI2cvRsB4GaHEGD9NCTB8XtNLbY2_7ll-D2As0msh78LJKj7A9PtqF4mJKW1tN1wEGyNZeviGurzEajatnj3msOFHxr7cQQhmhOn09u8n6sGizY1HUWDrbV0PjpIfzpwt_-AAxJu5J3sNbJ9td20iTZXjJujunc_fpXcRqC9ks3Vya7a7d1e6d-PpcUeUKjDkQdUVji15IdrajiwiBtM0m2eCSJITF1UGL6phf3V-ImSKcEbsKmSoul_YXkPy8dviIewyN-4y8d-ZJZY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