Compiler warnings: assignment discards 'const' qualifier from pointer target type

Description

Compiling LVGL (v8.0.2) code (RISC-V GCC, 8.3.0) I see these warnings:

lvgl/src/widgets/lv_checkbox.c:123:13: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

lvgl/src/core/lv_obj.c:132:18: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

lvgl/src/extra/widgets/tabview/lv_tabview.c:84:25: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

lvgl/src/extra/widgets/tabview/lv_tabview.c:93:24: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

lvgl/src/extra/widgets/tabview/lv_tabview.c:95:37: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

lvgl/src/extra/widgets/tabview/lv_tabview.c:97:37: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

lvgl/src/extra/widgets/tabview/lv_tabview.c:196:21: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

lvgl/src/widgets/lv_checkbox.c:123:13: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

lvgl/src/core/lv_obj.c:132:18: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

lvgl/src/extra/widgets/tabview/lv_tabview.c:84:25: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

lvgl/src/extra/widgets/tabview/lv_tabview.c:93:24: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

lvgl/src/extra/widgets/tabview/lv_tabview.c:95:37: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

lvgl/src/extra/widgets/tabview/lv_tabview.c:97:37: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

lvgl/src/extra/widgets/tabview/lv_tabview.c:196:21: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

What MCU/Processor/Board and compiler are you using?

RISC-V (GCC 8.3.0), custom platform

What do you want to achieve?

Clean LVGL build with no discarded-qualifiers warnings.
I’d like to treat them as errors (-Werror), but currently LVGL prevents me from doing this.
It should be easy to fix these.

What have you tried so far?

Adding -Wno-discarded-qualifiers option: the build works, but I’d like to avoid having to add this option.

Code to reproduce

N/A

Screenshot and/or video

(cc @kisvegabor)

Currently, our CI uses -Wno-discarded-qualifiers; this would need to be changed if we are going to consider this a disallowed warning.

Unfortunately, I can’t see these warnings with GCC 7.5.0, but I agree that it’d be better to enable them.

If @embeddedt also agrees the enable discarded-qualifiers warnings, @marcinh0001, can you send a PR with the fixes?

1 Like

I could, but as I explained in another thread, I’m required to add copyright notices to all files I modify, even slightly. I’d like to avoid it, it’s too many files.
Would it be possible for someone else to get rid of discarded-qualifiers warnings?

I can do it, however, I need to find a way of getting them to show up first, as when I enabled -Wdiscarded-qualifiers locally last week, they weren’t appearing.

Thanks. I think you’ll need a sufficiently fussy compiler (probably meaning modern?)
I don’t have a full view of which GCC versions are / aren’t fussy about it, but these two I use definitely are:

  • 8.3.0 for RISC-V
  • 10.2.0 for x86 used under mingw

And, needless to say, you need to get rid of the -Wno-discarded-qualifiers option.

Resurrecting an older thread on purpose :slight_smile:

I am having the same issues. Environment is

Win 11 pro
PlatformIO using Arduino framework
lvgl 8.3.4
ESP32DEV module
when compiling lvgl, i get several messages like

warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]   
             new_map[1] = "";

when using squarline studio 1.2.x, even more of such messages show up. Unfortunately, when I try to disable warning by specifying
-Wno-discarded-qualifiers
I get informed that this is not allowed in a C++ compile environment. Now, there shouldn’t be any warnings when compiling anyhow, so - what do I have to do to have this situation remedied?

With best regards

Volker Bandke

Same here, I’m working with the latest version of LVGL and PlatformIO using the Arduino Framework.
I would like to suppress this warning using the build flag -Wno-discarded-qualifiers
However, as previously mentioned, this is not allowed in C++.

Is there another way to suppress this warning globally?

corrects the warning:

src\core\lv_obj.c 143

const char * txt;
txt = "Á";
const uint8_t * txt_u8; 
txt_u8 = (const uint8_t *)txt;

const uint8_t * txt_u8;
txt_u8 = (const uint8_t *)txt;

src\extra\widgets\tabview 81
const char ** new_map;

src\extra\widgets\tabview 107
tabview->map = (char **)new_map;

src\extra\widgets\tabview 228
tabview->map[0] = (char *)"";

\src\widgets\lv_checkbox.c 125
cb->txt = (char *)"Check box";

Great! Are you going to issue a pull request?