Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++20 compatibility: a lot of warnings #8916

Open
5 of 6 tasks
MacDada opened this issue Apr 23, 2023 · 5 comments
Open
5 of 6 tasks

C++20 compatibility: a lot of warnings #8916

MacDada opened this issue Apr 23, 2023 · 5 comments

Comments

@MacDada
Copy link

MacDada commented Apr 23, 2023

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: [ESP-8266]
  • Core Version: [v3.0.2]
  • Development Env: [Platformio]
  • Operating System: [MacOS]

Settings in IDE

  • Module: [nodemcuv2]

Problem Description

I've set a flag to compile with the latest (available) standard: -std=gnu++20.

It works, but it produces a lot of warnings, for example:

.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_si2c.cpp:576:33: warning: '++' expression of 'volatile'-qualified type is deprecated [-Wvolatile]
  576 |         twi_data = twi_txBuffer[twi_txBufferIndex++];
      |                                 ^~~~~~~~~~~~~~~~~
.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_si2c.cpp:579:9: warning: '--' expression of 'volatile'-qualified type is deprecated [-Wvolatile]
  579 |         bitCount--;
      |         ^~~~~~~~
.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_si2c.cpp:588:18: warning: compound assignment with 'volatile'-qualified left operand is deprecated [-Wvolatile]
  588 |         twi_data <<= 1;
      |         ~~~~~~~~~^~~~~
.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_si2c.

They are all connected to the fact that starting with C++20, some of the volatile operations are deprecated: https://blog.feabhas.com/2021/05/modern-embedded-c-deprecation-of-volatile/

  1. Is there a plan for better support of C++20?
  2. Are you open for PRs in this matter?
@mcspr
Copy link
Collaborator

mcspr commented Apr 23, 2023

C++20, probably not before also switching to GCC12 or latter
https://en.cppreference.com/w/cpp/compiler_support
earlephilhower/arduino-pico#1379

afaik there is a paper about de-deprecation of these operations
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2327r1.pdf

Notably, gcc already implements it in master version (12, 13 include it already?)
https://cplusplus.github.io/CWG/issues/2654.html
gcc-mirror/gcc@1360290

Also, https://docs.platformio.org/en/latest/projectconf/sections/env/options/build/build_src_flags.html and https://docs.platformio.org/en/latest/scripting/index.html should limit build flag to just your project files (unless our headers somehow interfere)

@MacDada
Copy link
Author

MacDada commented Apr 23, 2023

C++20, probably not before also switching to GCC12 or latter

Well, I was confused at first, but C++20 is working with the current setup (GCC 10.3.0), but it's experimental.

-std=gnu++20 Conform to the ISO 2020 C++ draft standard with
GNU extensions (experimental and incomplete
support). Same as -std=gnu++2a.

https://community.platformio.org/t/std-gnu-20-is-shown-as-201709-nodemcuarduino/32514/3

https://docs.platformio.org/en/latest/projectconf/sections/env/options/build/build_src_flags.html

I've tried it and I still still get the warnings.

Actually, yeah – I wish I could somehow "separate" flags for my and external code…

@MacDada
Copy link
Author

MacDada commented Apr 30, 2023

I have temporarily disabled all volatile warnings: MacDada/DnWiFiDoorLock@5533426

@mcspr
Copy link
Collaborator

mcspr commented Apr 30, 2023

or if they fix the issues in the libs (not gonna happen ;p)

Feel free to provide a PR :)

Volatile use in I2C master seems to originate from old SDK behaviour where OS (aka ETS) timers were serviced as soon as the peripheral timer expired. This is no longer the case, timers are handled in a task instead. So, I would guess it might be pretty safe to just remove volatile code in those sections.

I2C slave code is using pin ISR, so some sync logic still needs to happen somewhere.
But we could also just mask interrupts while inside some of critical sections; manual memw and asm memory to sync vars still applies here, probably don't need to use volatile to enforce desired behaviour

Which libraries other than I2C are affected?

@MacDada
Copy link
Author

MacDada commented Apr 30, 2023

Feel free to provide a PR :)

Ok, will try – I was asking about that at the beginning: 2. Are you open for PRs in this matter? :-)

Mostly because after playing with C++/uC/Arduino/ESP8266/PIO for a year already, I can see that a lot of the projects are… kinda abandonware… Even simple issues/PRs get not answered/merged for many months… Hence asking if I'm gonna waste my time, trying to do anything – hopefully not!

I would guess it might be pretty safe to just remove volatile code in those sections.

Oooof, my C++ brain is too small for that, yet. I might try simple substitution from the "short" foo++ into extended foo = foo + 1 version, but more complicated analysis are most likely outside of my abilities ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants