You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Avoid collision between tag and typedef identifier (#166)
C allows name collision between the following 2 declarations:
```c
struct X {};
typedef enum {} X;
```
The 2 declarations live in different name spaces:
6.2.3 Name spaces of identifiers
[...] there are separate namespaces for various categories of
identifiers, as follows:
1. the tags of structures, unions, and enumerations (disambiguated by
following any) of the keywords struct, union, or enum);
2. all other identifiers, called ordinary identifiers (declared in
ordinary declarators or as enumeration constants).
`struct X {}` lives in namespace 1 and `typedef enum {} X` lives in
namespace 2.
We cannot translate both to `X` in the Rust code. We need to
disambiguate between the 2 names. I chose to translate them as:
```
struct X {} -> X
typedef enum {} X -> X_enum
```
C++ does not have the name space rule for identifiers. I added the
`tag->getASTContext().getLangOpts().CPlusPlus` check in
DisambiguateAnonymousTag to avoid polluting the C++ generated files.
---------
Co-authored-by: Nuno Lopes <nuno.lopes@tecnico.ulisboa.pt>
0 commit comments