Return UnsupportedItem when `volatile` qualifier is used.
This CL is only loosely related to b/217419782 - I've just noticed that
`volatile` is ignored when working on Importer::ConvertType changes to
support function pointer types.
PiperOrigin-RevId: 428770476
diff --git a/rs_bindings_from_cc/importer.cc b/rs_bindings_from_cc/importer.cc
index d395d98..7ba5a84 100644
--- a/rs_bindings_from_cc/importer.cc
+++ b/rs_bindings_from_cc/importer.cc
@@ -898,10 +898,12 @@
return error;
}
- // Add cv-qualification.
+ // Handle cv-qualification.
type->cc_type.is_const = qual_type.isConstQualified();
- // Not doing volatile for now -- note that volatile pointers do not exist in
- // Rust, though volatile reads/writes still do.
+ if (qual_type.isVolatileQualified()) {
+ return absl::UnimplementedError(
+ absl::StrCat("Unsupported `volatile` qualifier: ", type_string));
+ }
return *std::move(type);
}
diff --git a/rs_bindings_from_cc/ir_from_cc_test.rs b/rs_bindings_from_cc/ir_from_cc_test.rs
index 8862a05..856c64e 100644
--- a/rs_bindings_from_cc/ir_from_cc_test.rs
+++ b/rs_bindings_from_cc/ir_from_cc_test.rs
@@ -1187,3 +1187,10 @@
}}
};
}
+
+#[test]
+fn test_volatile_is_unsupported() {
+ let ir = ir_from_cc("volatile int* foo();").unwrap();
+ let f = ir.unsupported_items().find(|i| i.message.contains("volatile")).unwrap();
+ assert_eq!("foo", f.name);
+}