google / autocxx

Tool for safe ergonomic Rust/C++ interop driven from existing C++ headers
https://docs.rs/autocxx
Apache License 2.0
2.26k stars 144 forks source link

Support C++ deprecated attribute to reduce warnings #1403

Open ShaddyDC opened 1 month ago

ShaddyDC commented 1 month ago

I've got some C++ code that uses the deprecated attribute, say like this (renaming stuff for simplicity, so my apologies if the warning below is off):

   [[deprecated( "foo is deprecated and will be removed in the next version." )]]
   virtual int foo() = 0;

Autocxx then generates this code for it:

inline int foo_autocxx_wrapper_0x4c2f5dcd019b1af8(Bar& autocxx_gen_this)  { return autocxx_gen_this.foo(); }

Then, when compiling, I get warnings such as this:

warning: crate-sys@0.1.0: In file included from /home/space/repos/export-server/target/debug/build/crate-sys-a317d4556f361b64/out/autocxx-build-dir/cxx/gen0.cxx:10:
warning: crate-sys@0.1.0: /home/space/repos/export-server/target/debug/build/crate-sys-a317d4556f361b64/out/autocxx-build-dir/include/autocxxgen_ffi.h: In function ‘int foo_autocxx_wrapper_0x4c2f5dcd019b1af8(Bar&)’:
warning: crate-sys@0.1.0: /home/space/repos/export-server/target/debug/build/crate-sys-a317d4556f361b64/out/autocxx-build-dir/include/autocxxgen_ffi.h:318:131: warning: ‘foo is deprecated and will be removed in the next version. [-Wdeprecated-declarations]
warning: crate-sys@0.1.0:   318 | inline int foo_autocxx_wrapper_0x4c2f5dcd019b1af8(Bar& autocxx_gen_this)  { return autocxx_gen_this.foo(); }
warning: crate-sys@0.1.0:       |                                                                                    ~~~~~~~~~~~~~~~~~~~~^~
...

Because the project I'm using this with has a lot of those functions, this generates a lot of noise and hides actual problems, whether I use the deprecated functions or not.

I suggest this behaviour instead:

  1. Suppress all existing warnings by disabling deprecated-declarations
  2. Annotate corresponding rust functions with #[deprecated] and the given warning message

Then we should get warnings only when using the actually bad functionality in rust.

adetaylor commented 1 month ago

I like the idea and I'd be happy to accept a pull request!