Repository: rust-lang/rust-bindgen (rust)

Issue:
Cannot find type '__BindgenOpaqueArray' in this scope
Repro:

```console
cargo run --manifest-path bindgen-cli/Cargo.toml -- \
    --enable-cxx-namespaces \
    <(echo '
        namespace repro {
            template<unsigned int N> class Array { int inner[N]; };
            class C { Array<3> arr; };
        }
    ') \
    -- \
    -xc++ \
    | rustc --crate-type=lib --edition=2021 /dev/stdin
```

Bisects to https://github.com/rust-lang/rust-bindgen/pull/2880. @GKFX

This impacts Clang's implementation of `#include <chrono>`.

Pull request description:
Fix regression spotted at #3027
Fixes #3027.

Patch:
diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs
index 18277054..812b6b64 100644
--- a/bindgen/codegen/helpers.rs
+++ b/bindgen/codegen/helpers.rs
@@ -102,7 +102,11 @@ pub(crate) fn blob(
         ty
     } else if ffi_safe && ctx.options().rust_features().min_const_generics {
         ctx.generated_opaque_array();
-        syn::parse_quote! { __BindgenOpaqueArray<#ty, #data_len> }
+        if ctx.options().enable_cxx_namespaces {
+            syn::parse_quote! { root::__BindgenOpaqueArray<#ty, #data_len> }
+        } else {
+            syn::parse_quote! { __BindgenOpaqueArray<#ty, #data_len> }
+        }
     } else {
         // This is not FFI safe as an argument; the struct above is
         // preferable.


Test patch:
diff --git a/bindgen-tests/tests/expectations/tests/issue-3027.rs b/bindgen-tests/tests/expectations/tests/issue-3027.rs
new file mode 100644
index 00000000..757aa9d9
--- /dev/null
+++ b/bindgen-tests/tests/expectations/tests/issue-3027.rs
@@ -0,0 +1,31 @@
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
+pub mod root {
+    /// If Bindgen could only determine the size and alignment of a
+    /// type, it is represented like this.
+    #[derive(PartialEq, Copy, Clone, Debug, Hash)]
+    #[repr(C)]
+    pub struct __BindgenOpaqueArray<T: Copy, const N: usize>(pub [T; N]);
+    impl<T: Copy + Default, const N: usize> Default for __BindgenOpaqueArray<T, N> {
+        fn default() -> Self {
+            Self([<T as Default>::default(); N])
+        }
+    }
+    #[allow(unused_imports)]
+    use self::super::root;
+    pub mod regression {
+        #[allow(unused_imports)]
+        use self::super::super::root;
+        #[repr(C)]
+        #[derive(Debug, Default, Copy, Clone)]
+        pub struct C {
+            pub a: root::__BindgenOpaqueArray<u8, 3usize>,
+        }
+        #[allow(clippy::unnecessary_operation, clippy::identity_op)]
+        const _: () = {
+            ["Size of C"][::std::mem::size_of::<C>() - 3usize];
+            ["Alignment of C"][::std::mem::align_of::<C>() - 1usize];
+            ["Offset of field: C::a"][::std::mem::offset_of!(C, a) - 0usize];
+        };
+    }
+}
diff --git a/bindgen-tests/tests/headers/issue-3027.hpp b/bindgen-tests/tests/headers/issue-3027.hpp
new file mode 100644
index 00000000..d9b87ee6
--- /dev/null
+++ b/bindgen-tests/tests/headers/issue-3027.hpp
@@ -0,0 +1,6 @@
+// bindgen-flags: --enable-cxx-namespaces
+
+namespace regression {
+    template<unsigned N> class A { char c[N]; };
+    class C { A<3> a; };
+}