Merge branch 'contrib/github_pr_11025' into 'master'

Enable support for C++23 in esp-idf (GitHub PR)

Closes IDFGH-9684

See merge request espressif/esp-idf!23144
This commit is contained in:
Jakob Hasse 2023-04-19 15:53:46 +08:00
commit d82eb6942c
4 changed files with 11 additions and 6 deletions

View File

@ -32,7 +32,7 @@ extern "C" {
* - MACRO_ARGS(__VA_ARGS__) if __VA_ARGS__ was not empty
* - MACRO_NO_ARGS() if __VA_ARGS__ was empty
*
* @note In the future, we want to switch to C++20. We also want to become compatible with clang. Hence, we provide two
* @note In the future, we want to become compatible with clang. Hence, we provide two
* versions of the following macros which are using variadic arguments. One is using the GNU extension ##__VA_ARGS__.
* The other is using the C++20 feature __VA_OPT__(,). This allows users to compile their code with standard C++20
* enabled instead of the GNU extension. Below C++20, we haven't found any good alternative to using ##__VA_ARGS__.

View File

@ -288,7 +288,7 @@ void esp_log_writev(esp_log_level_t level, const char* tag, const char* format,
/// Log at ``ESP_LOG_ERROR`` level. @see ``printf``,``ESP_LOGE``,``ESP_DRAM_LOGE``
/**
* In the future, we want to switch to C++20. We also want to become compatible with clang.
* In the future, we want to become compatible with clang.
* Hence, we provide two versions of the following macros which are using variadic arguments.
* The first one is using the GNU extension \#\#__VA_ARGS__. The second one is using the C++20 feature __VA_OPT__(,).
* This allows users to compile their code with standard C++20 enabled instead of the GNU extension.

View File

@ -23,14 +23,14 @@ esp-idf-cxx Component
C++ language standard
---------------------
By default, ESP-IDF compiles C++ code with C++20 language standard with GNU extensions (``-std=gnu++20``).
By default, ESP-IDF compiles C++ code with C++23 language standard with GNU extensions (``-std=gnu++23``).
To compile the source code of a certain component using a different language standard, set the desired compiler flag in the component CMakeLists.txt file:
.. code-block:: cmake
idf_component_register( ... )
target_compile_options(${COMPONENT_LIB} PRIVATE -std=gnu++2b)
target_compile_options(${COMPONENT_LIB} PRIVATE -std=gnu++11)
Use ``PUBLIC`` instead of ``PRIVATE`` if the public header files of the component also need to be compiled with the same language standard.

View File

@ -129,7 +129,12 @@ function(__build_set_lang_version)
# Use latest supported versions.
# Please update docs/en/api-guides/cplusplus.rst when changing this.
set(c_std gnu17)
set(cxx_std gnu++20)
if(NOT ${env_idf_toolchain} STREQUAL "clang")
set(cxx_std gnu++23)
else()
# TODO: IDF-7241 - remove the exception for clang
set(cxx_std gnu++20)
endif()
else()
enable_language(C CXX)
# Building for Linux target, fall back to an older version of the standard
@ -149,7 +154,7 @@ function(__build_set_lang_version)
"${preferred_c_versions}. Please upgrade the host compiler.")
endif()
set(preferred_cxx_versions gnu++20 gnu++2a gnu++17 gnu++14)
set(preferred_cxx_versions gnu++23 gnu++20 gnu++2a gnu++17 gnu++14)
set(ver_found FALSE)
foreach(cxx_version ${preferred_cxx_versions})
check_cxx_compiler_flag("-std=${cxx_version}" ver_${cxx_version}_supported)