cbindgen icon indicating copy to clipboard operation
cbindgen copied to clipboard

Dependencies between constants aren't tracked correctly.

Open emilio opened this issue 5 years ago • 0 comments

See https://github.com/eqrion/cbindgen/pull/587#issuecomment-703466832

This is not an issue for C mode because we use macros which are terrible but don't have this problem.

But for C++, where we try to generate "proper" constants, this can cause compilation errors.

This test-case:

pub const B: usize = 4;
pub const A: usize = B + 1;

Generates:

#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

static const uintptr_t A = (B + 1);

static const uintptr_t B = 4;

Which fails to compile like:

t.cc:7:29: error: ‘B’ was not declared in this scope
    7 | static const uintptr_t A = (B + 1);
      |

It seems at least we should preserve the const definition order.

emilio avatar Oct 05 '20 08:10 emilio