Confused about -Wabi with type tag on virtual method

John Steele Scott
Fri Mar 26 11:08:04 GMT 2021

I have a component which ships a C++ library to be integrated into a larger project. To allow both pieces to upgrade their version of GCC independently, we use -Wabi in the component to warn us away from ABI-incompatibilities.

Since the larger project is currently using GCC 8.3 (devtoolset-8), we have -Wabi=13 in the component. My understanding is that this should warn us if the component uses some construct which requires a *newer* ABI than 13. But the following code (minimal example, type tag dispatch on a virtual function is key here) is warning about a change made in ABI 12:

$ cat abi.cpp
constexpr struct my_tag_t {} my_tag;

struct A
  virtual int foo (my_tag_t, int x) = 0;

int bar (A &a, int x)
  return, x);
$ g++-10 -Wabi=13 -c abi.cpp
abi.cpp: In function ‘int bar(A&, int)’:
abi.cpp:10:15: warning: empty class ‘my_tag_t’ parameter passing ABI changes in ‘-fabi-version=12’ (GCC 8) [-Wabi]
   10 |   return, x);
      |          ~~~~~^~~~~~~~~~~

If I force the component to use ABI 11 (-fabi-version-11), the warning goes away. But isn't this the opposite of what I want? Now the component is using the older/incompatible ABI compared to the larger project.

Am I using -Wabi all wrong, or is this perhaps a bug?

As a workaround I can change my virtual function signature to accept "const my_tag_t &". Is this the best approach?



More information about the Gcc-help mailing list