Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflicting enum and #define identifiers make a translated header cause invalid redefinition of constant #467

Open
topolarity opened this issue Jan 31, 2024 · 2 comments
Labels

Comments

@topolarity
Copy link

NgSpice has a habit of establishing most enum-like constants with #define: https://github.com/imr/ngspice/blob/902a62d2f442a1d8322ae4fcad35c143c7a14561/src/include/ngspice/noisedef.h#L72-L74

but then occasionally introducing an enum { ... } with the same names wrapped in an ifdef guard: https://github.com/imr/ngspice/blob/902a62d2f442a1d8322ae4fcad35c143c7a14561/src/include/ngspice/acdefs.h#L29-L35

Example:

// test1.h
#ifndef TEST_H_
#define TEST_H_
enum {
    DECADE = 1,
    OCTAVE,
    LINEAR,
};
#endif // TEST_H_
// test2.h
#ifndef TEST_H_
#define DECADE 1
#endif

result:

module TestModule

const __JL_Ctag_1 = UInt32
const DECADE = 1 % UInt32
const OCTAVE = 2 % UInt32
const LINEAR = 3 % UInt32

const DECADE = 1
# ...
end # module

It would be nice if Clang.jl either:

  • Applied the #define across header files so that the duplicate enum definition is not parsed, OR
  • Merged the enum and #define constants, since their definitions are compatible up to a difference of integer type
@topolarity
Copy link
Author

As a workaround, it does work if I use a wrapper header:

// wrapper.h
#include "test1.h"
#include "test2.h"

and translate only that

@Gnimuc Gnimuc added the macro label Feb 1, 2024
@Gnimuc
Copy link
Member

Gnimuc commented Feb 1, 2024

does it work if you pass a macro-define compiler flag to args?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants