Skip to content

[24.08] fix ODR violation: many files had the wrong definition of Enum

Sam James requested to merge thesamesam/gwenview:backport-odr-fix into release/24.08

This enum has a different number of values, depending on whether gwenview is configured with the semanticinfo backend "none" or fake/baloo.

In order to avoid Undefined Behavior, every file that includes sorting.h also has to include config-gwenview.h before sorting.h, which was not true. Solve this by including the config header inside the sorting.h header.

Fixes link failures when LTO is enabled, since LTO allows the compiler to do whole-program optimization and type-check across the entire program:

/var/tmp/portage/kde-apps/gwenview-24.08.0/work/gwenview-24.08.0/app/../lib/sorting.h:37:6: error: type ‘Gwenview::Sorting::Enum’ violates the C++ One Definition Rule [-Werror=odr]
   37 | enum Enum {
      |      ^
/var/tmp/portage/kde-apps/gwenview-24.08.0/work/gwenview-24.08.0/app/../lib/sorting.h:37:6: note: an enum with different number of values is defined in another translation unit
   37 | enum Enum {
      |      ^
lto1: some warnings being treated as errors
lto-wrapper: fatal error: /usr/bin/x86_64-pc-linux-gnu-g++ returned 1 exit status
compilation terminated.
/usr/libexec/gcc/x86_64-pc-linux-gnu/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

Fixes: https://bugs.gentoo.org/921649 (cherry picked from commit b5cc2145)

Merge request reports

Loading