https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116198

            Bug ID: 116198
           Summary: Wdeprecated-enum-enum-conversion triggers inside
                    extern "C"
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rsaxvc at gmail dot com
  Target Milestone: ---

deprecated-enum-enum-conversion warnings apply to C code compiled by G++,
should they? I'm assuming if this code would not trigger a warning in C, it
shouldn't trigger a warning in extern "C". Here's a minimal contrived example:

   #include <stdlib.h>

   extern "C"{
      enum {TWO = 2};
      enum {ONE = 1};
      void * triggerDeprecatedEnumConversion() {
         return malloc(ONE | TWO);
      }
   }

When the above code is compiled with g++ 12.2.0, -Wall -Wextra -O2 -std=c++23,
triggers this warning:

   <source>: In function 'void* triggerDeprecatedEnumConversion()':
   <source>:17:27: warning: bitwise operation between different enumeration
types '<unnamed enum>' and '<unnamed enum>' is deprecated
[-Wdeprecated-enum-enum-conversion]
      17 |         return malloc(ONE | TWO);
         |                       ~~~~^~~~~

One real-world use-case this impacts occurs in LVGL, which uses separate enums
for different parts of a bitfield that are then combined in functions in a
header, so every C++ file that includes those headers triggers this warning.
Related discussion here: https://github.com/lvgl/lvgl/issues/5119

Specific compiler version:
   xtensa-esp32s3-elf-c++.exe (crosstool-NG esp-12.2.0_20230208) 12.2.0
   Copyright (C) 2022 Free Software Foundation, Inc.
   This is free software; see the source for copying conditions.  There is NO
   warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Reply via email to