Bug#1000974: copy_move_algo.hpp:1083:10: error: ‘__fallthrough__’ was not declared in this scope; did you mean ‘fallthrough’?

Darrick J. Wong
2021-12-05T17:57:04Z

On Sun, Dec 05, 2021 at 06:33:40PM +0100, Thomas Goirand wrote:
> On 12/5/21 4:50 PM, Giovanni Mascellani wrote:
> > reassign 1000974 xfslibs-dev
> > severity 1000974 important
> > retitle 1000974 xfs/linux.h defines common word "fallthrough" breaking
> > unrelated headers
> > thanks
> >
> > Hi,
> >
> > On 04/12/21 23:36, Thomas Goirand wrote:
> >> On 12/4/21 5:11 PM, Giovanni Mascellani wrote:
> >>> Could you try running that compilation command with g++ -E, so you can
> >>> see what BOOST_FALLTHROUGH is actually begin replaced with?
> >>
> >> Oh, sorry, now I get what you meant (did a c++ --help to understand what
> >> -E was doing). Here's the result in
> >> CMakeFiles/seastar.dir/src/core/file.cc.o:
> >>
> >> __attribute__((__attribute__((__fallthrough__))));
> >>
> >> Probably, there's a mistake, and it should really be:
> >>
> >> __attribute__((__fallthrough__));
> >>
> >> instead, which is the source of the trouble?
> >
> > It seems that the problem goes this way:
> >
> >  * Boost defines in /usr/include/boost/config/compiler/gcc.hpp:
> >
> > #define BOOST_FALLTHROUGH __attribute__((fallthrough))
> >
> >  * But /usr/include/xfs/linux.h defines:
> >
> > #define fallthrough __attribute__((__fallthrough__))
> >
> > So the "fallthrough" in Boost's definition is expanded again and causes
> > the problem.
> >
> > I think xfs/linux.h is at fault here, because it aggressively defines a
> > common word (while Boost namespaces all its definitions with a BOOST_
> > prefix). Unfortunately the C/C++ preprocessor makes it easy to break
> > other headers if you define stuff too liberally. This wold also, for
> > example, break any program that use the name "fallthrough" for a
> > variable, which is a completely reasonable name to use. A simple example
> > could be:
> > ---
> > #include <xfs/linux.h>
> >
> > int main() {
> >     int fallthrough = 0;
> >     return fallthrough;
> > }
> > ---
> > which fails compilation with:
> > ---
> > $ LANG=C gcc test.c
> > test.c: In function 'main':
> > test.c:4:5: warning: 'fallthrough' attribute not followed by ';'
> > [-Wattributes]
> >     4 |     int fallthrough = 0;
> >       |     ^~~
> > test.c:4:21: error: expected identifier or '(' before '=' token
> >     4 |     int fallthrough = 0;
> >       |                     ^
> > In file included from test.c:1:
> > test.c:5:12: error: expected expression before '__attribute__'
> >     5 |     return fallthrough;
> >       |            ^~~~~~~~~~~
> > ---
> >
> > You can probably work around this problem by undefining "fallthrough"
> > just after the xfs/linux.h header. In the meantime I am reassigning this
> > bug to xfslibs-dev.

Yeah, sorry. This is braindamage from the Linux kernel (because hey, we
share libxfs between kernel and userspace) that I mistakenly let escape
because the authors of the kernel patch didn't try to help us when they
forced this stupid mess on us. All this BS because some compiler
writers didn't like their static checkers to have to use regular
expressions for compatibility with existing codebases, and the language
standard people decided to introduce a breaking change to "standardize"
it.

Will fix ASAP.

--D

> >
> > Giovanni.
>
>
> Hi,
>
> I can confirm that commenting away line 373 to 381 of xfs/linux.h solve
> the troubles when building Ceph. Downgrading to 5.13.0-1 (using
> snapshot.d.o) also solved the trouble, showing that 5.14.0 really is the
> trouble here.
>
> Thanks Giovanni for finding this out.
>
> Cheers,
>
> Thomas Goirand (zigo)