Skip to content

Types can end up in the wrong namespace #2556

@glandium

Description

@glandium

This is a regression from 83f729f

Input C/C++ Header

I'm sorry this is not reduced as much as possible, but it's already significantly reduced. The problem does not happen using the output of --dump-preprocessed-input (it does require multiple separate headers, and even worse, it requires that some of them are included multiple times)

The complete set of files involved in this somehow reduced testcase is: https://drive.google.com/file/d/1vldgLGgcslyeUTlcHzMd4r0WVZNY2Wht/view?usp=sharing

Bindgen Invocation

Assuming the testcase.tar.gz archive is extracted to /tmp/testcase, run the cli with

cargo run --release -p bindgen-cli -- /tmp/testcase/mozilla/GeckoBindings.h --allowlist-type nsSimpleContentList --allowlist-type nsSize --enable-cxx-namespaces --no-derive-default --generate types --ignore-methods --rust-target 1.68 -- -x c++ -std=c++17 -fno-sized-deallocation -fno-aligned-new -DTRACING=1 -DIMPL_LIBXUL -DMOZILLA_INTERNAL_API -DRUST_BINDGEN -I/tmp/testcase -I/tmp/testcase/nspr -include /tmp/testcase/mozilla-config.h -include /tmp/testcase/nsStyleStruct.h -include /tmp/testcase/LayoutConstants.h

(using clang 16, I don't know for sure whether the command works with older versions, I know for sure it doesn't work with clang 11, because I have that in a corner)

Actual Results

The output contains the nsSize type in the root::mozilla namespace, although the type is defined in the root namespace.

There are many ways to make this disappear:

  • removing --allowlist-type nsSimpleContentList
  • in LayoutConstants.h, adding constexpr nsSize dummy(0, 0); above namespace mozilla (because yes, that's where the bogus namespace comes from)
  • not including nsStyleStruct.h from the command line
  • not including nsStyleStruct.h from mozilla/GeckoBindings.h
  • using the preprocessed input
  • creating a file that includes mozilla-config.h, nsStyleStruct.h, LayoutConstants.h and mozilla/GeckoBindings.h, and using that instead of passing those files on the command line.
  • etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions