clang: Push the fix for #3277 into Type::declaration.

Fixes #3264.
diff --git a/bindgen-tests/tests/expectations/tests/nested-class-field.rs b/bindgen-tests/tests/expectations/tests/nested-class-field.rs
new file mode 100644
index 0000000..91500f4
--- /dev/null
+++ b/bindgen-tests/tests/expectations/tests/nested-class-field.rs
@@ -0,0 +1,22 @@
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct A {
+    pub _address: u8,
+}
+#[allow(clippy::unnecessary_operation, clippy::identity_op)]
+const _: () = {
+    ["Size of A"][::std::mem::size_of::<A>() - 1usize];
+    ["Alignment of A"][::std::mem::align_of::<A>() - 1usize];
+};
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct A_I {
+    pub i: ::std::os::raw::c_int,
+}
+#[allow(clippy::unnecessary_operation, clippy::identity_op)]
+const _: () = {
+    ["Size of A_I"][::std::mem::size_of::<A_I>() - 4usize];
+    ["Alignment of A_I"][::std::mem::align_of::<A_I>() - 4usize];
+    ["Offset of field: A_I::i"][::std::mem::offset_of!(A_I, i) - 0usize];
+};
diff --git a/bindgen-tests/tests/headers/nested-class-field.hpp b/bindgen-tests/tests/headers/nested-class-field.hpp
new file mode 100644
index 0000000..295ebe8
--- /dev/null
+++ b/bindgen-tests/tests/headers/nested-class-field.hpp
@@ -0,0 +1,7 @@
+class A {
+  class I;
+};
+
+class A::I {
+  int i;
+};
diff --git a/bindgen/clang.rs b/bindgen/clang.rs
index e52fed0..1e8326e 100644
--- a/bindgen/clang.rs
+++ b/bindgen/clang.rs
@@ -1211,11 +1211,11 @@
 
     /// Get a cursor pointing to this type's declaration.
     pub(crate) fn declaration(&self) -> Cursor {
-        unsafe {
-            Cursor {
-                x: clang_getTypeDeclaration(self.x),
-            }
-        }
+        let decl = Cursor {
+            x: unsafe { clang_getTypeDeclaration(self.x) },
+        };
+        // Prior to clang 22, the declaration pointed to the definition.
+        decl.definition().unwrap_or(decl)
     }
 
     /// Get the canonical declaration of this type, if it is available.
diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs
index f0c4e6f..0b50bf3 100644
--- a/bindgen/ir/comp.rs
+++ b/bindgen/ir/comp.rs
@@ -1234,12 +1234,6 @@
         );
 
         let mut cursor = ty.declaration();
-
-        // If there is a definition, that's what we want.
-        if let Some(def) = cursor.definition() {
-            cursor = def;
-        }
-
         let mut kind = Self::kind_from_cursor(&cursor);
         if kind.is_err() {
             if let Some(location) = location {