]> git.lyx.org Git - features.git/commit
Avoid dangling-reference warning in several places
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 8 Nov 2023 17:07:14 +0000 (18:07 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 10 Nov 2023 09:36:52 +0000 (10:36 +0100)
commitc2653e451cd4ffb162a25267f86ad40d0c956f61
tree25d7bb1ae597f56a68a03cf8d65dfb1403bf4750
parent3698281943611647738baba1b33a3bd08518e410
Avoid dangling-reference warning in several places

This new warning in gcc 13 is annoying because it happens in certain
parts of our code where it is harmless to pass a temporary variable to
a function that returns a reference.

This patch introduces a new pair of macros,
LYX_BEGIN_MUTE_GCC_WARNING(warn) and LYX_END_MUTE_GCC_WARNING, which
can be used to define a block of code where a given GCC warning is disabled.

The macros are no-ops with compilers other than gcc, although some
compilers that pretend to be GCC make be mis-detected. The worse that
can happen AFAIU is a bunch of warnings.

The macro relies on an intimidating set of for nested macros. The goal
of these macros is to build a nested string bit by bit. Here is how it
works:

PRAGMA_IGNORE(dangling-reference)
  => PRAGMA_IGNORE_1(-Wdangling-reference)
  => PRAGMA_IGNORE_2("-Wdangling-reference")
  => PRAGMA_IGNORE_3(GCC diagnostic ignored "-Wdangling-reference")
  => _Pragma("GCC diagnostic ignored \""-Wdangling-reference\"")

The next question is: what is _Pragma() good for? Well, it is a
version of #pragma that can be used in a macro.

And finally, what are those pragmas good for? The 'push' and 'pop'
ones make changes to warnings local. The 'ignored' ones allow
to disable some warnings. And disabling -Wpragmas ensures that we do
not have a warning if we try to disable a warning that is not
supported by the compiler.
configure.ac
src/Mover.h
src/WordList.h
src/frontends/FontMetrics.h