mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-03 10:30:58 +02:00
Merge branch 'feature/update-gnu-standards' into 'master'
feat(build): update gnu17->gnu23 and gnu++2b->gnu++26 See merge request espressif/esp-idf!41014
This commit is contained in:
20
components/newlib/platform_include/stdatomic.h
Normal file
20
components/newlib/platform_include/stdatomic.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#pragma once
|
||||
#include_next <stdatomic.h>
|
||||
|
||||
/* The ATOMIC_VAR_INIT macro was deprecated in:
|
||||
* - C17
|
||||
* - C++20
|
||||
* and removed in subsequent standards.
|
||||
* Since users may change the standard version for their projects,
|
||||
* IDF should remain compatible across different standards.
|
||||
*/
|
||||
#if __STDC_VERSION__ > 201710L || __cplusplus > 202002L
|
||||
# ifndef ATOMIC_VAR_INIT
|
||||
# define ATOMIC_VAR_INIT(val) (val)
|
||||
# endif
|
||||
#endif
|
@@ -11,7 +11,7 @@
|
||||
|
||||
#define MAX_MEMTEST_SIZE 4096
|
||||
|
||||
uint32_t test_function_dest_src_size(void (*foo)(), bool pass_size)
|
||||
uint32_t test_function_dest_src_size(void (*foo)(...), bool pass_size)
|
||||
{
|
||||
uint32_t ccount1, ccount2;
|
||||
char* test_des = heap_caps_aligned_alloc(32, MAX_MEMTEST_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
|
@@ -17,7 +17,7 @@ In general, all C features supported by the compiler (currently GCC) can be used
|
||||
C Version
|
||||
---------
|
||||
|
||||
**GNU dialect of ISO C17** (``--std=gnu17``) is the current default C version in ESP-IDF.
|
||||
**GNU dialect of ISO C23** (``--std=gnu23``) is the current default C version in ESP-IDF.
|
||||
|
||||
To compile the source code of a certain component using a different language standard, set the desired compiler flag in the component's ``CMakeLists.txt`` file:
|
||||
|
||||
@@ -38,4 +38,4 @@ The following features are not supported in ESP-IDF.
|
||||
Nested Function Pointers
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The **GNU dialect of ISO C17** supports `nested functions <https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html>`_. However, ESP-IDF does not support referencing nested functions as pointers. This is due to the fact that the GCC compiler generates a `trampoline <https://gcc.gnu.org/onlinedocs/gccint/Trampolines.html>`_ (i.e., small piece of executable code) on the stack when a pointer to a nested function is referenced. ESP-IDF does not permit executing code from a stack, thus use of pointers to nested functions is not supported.
|
||||
The **GNU dialect of ISO C23** supports `nested functions <https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html>`_. However, ESP-IDF does not support referencing nested functions as pointers. This is due to the fact that the GCC compiler generates a `trampoline <https://gcc.gnu.org/onlinedocs/gccint/Trampolines.html>`_ (i.e., small piece of executable code) on the stack when a pointer to a nested function is referenced. ESP-IDF does not permit executing code from a stack, thus use of pointers to nested functions is not supported.
|
||||
|
@@ -26,7 +26,7 @@ The following C++ features are supported:
|
||||
C++ Language Standard
|
||||
---------------------
|
||||
|
||||
By default, ESP-IDF compiles C++ code with C++23 language standard with GNU extensions (``-std=gnu++23``).
|
||||
By default, ESP-IDF compiles C++ code with C++26 language standard with GNU extensions (``-std=gnu++26``).
|
||||
|
||||
To compile the source code of a certain component using a different language standard, set the desired compiler flag in the component's ``CMakeLists.txt`` file:
|
||||
|
||||
@@ -182,7 +182,7 @@ Designated Initializers
|
||||
|
||||
Many of the ESP-IDF components use :ref:`api_reference_config_structures` as arguments to the initialization functions. ESP-IDF examples written in C routinely use `designated initializers <https://en.cppreference.com/w/c/language/struct_initialization>`_ to fill these structures in a readable and a maintainable way.
|
||||
|
||||
C and C++ languages have different rules with regards to the designated initializers. For example, C++23 (currently the default in ESP-IDF) does not support out-of-order designated initialization, nested designated initialization, mixing of designated initializers and regular initializers, and designated initialization of arrays. Therefore, when porting ESP-IDF C examples to C++, some changes to the structure initializers may be necessary. See the `C++ aggregate initialization reference <https://en.cppreference.com/w/cpp/language/aggregate_initialization>`_ for more details.
|
||||
C and C++ languages have different rules with regards to the designated initializers. For example, C++26 (currently the default in ESP-IDF) does not support out-of-order designated initialization, nested designated initialization, mixing of designated initializers and regular initializers, and designated initialization of arrays. Therefore, when porting ESP-IDF C examples to C++, some changes to the structure initializers may be necessary. See the `C++ aggregate initialization reference <https://en.cppreference.com/w/cpp/language/aggregate_initialization>`_ for more details.
|
||||
|
||||
|
||||
``iostream``
|
||||
|
@@ -17,7 +17,7 @@ Newlib 的版本号记录在 :component_file:`newlib/sbom.yml` 文件中。
|
||||
C 版本
|
||||
------
|
||||
|
||||
**ISO C17 的 GNU 方言** (``--std=gnu17``) 是 ESP-IDF 中当前默认的 C 语言版本。
|
||||
**ISO C23 的 GNU 方言** (``--std=gnu23``) 是 ESP-IDF 中当前默认的 C 语言版本。
|
||||
|
||||
使用不同的语言标准编译某个组件的源代码,请在组件的 ``CMakeLists.txt`` 文件中设置所需的编译器标志:
|
||||
|
||||
@@ -38,4 +38,4 @@ ESP-IDF 不支持以下功能。
|
||||
嵌套函数的指针
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
**ISO C17 的 GNU 方言** 支持 `嵌套函数 <https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html>`_,但 ESP-IDF 不支持将嵌套函数引用为指针。这是因为 GCC 编译器在引用嵌套函数的指针时,会在栈上生成一个 `跳板 <https://gcc.gnu.org/onlinedocs/gccint/Trampolines.html>`_ (即,一小段可执行代码),ESP-IDF 不允许从栈执行代码,因此不支持使用指向嵌套函数的指针。
|
||||
**ISO C23 的 GNU 方言** 支持 `嵌套函数 <https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html>`_,但 ESP-IDF 不支持将嵌套函数引用为指针。这是因为 GCC 编译器在引用嵌套函数的指针时,会在栈上生成一个 `跳板 <https://gcc.gnu.org/onlinedocs/gccint/Trampolines.html>`_ (即,一小段可执行代码),ESP-IDF 不允许从栈执行代码,因此不支持使用指向嵌套函数的指针。
|
||||
|
@@ -26,7 +26,7 @@ ESP-IDF 支持以下 C++ 功能:
|
||||
C++ 语言标准
|
||||
---------------------
|
||||
|
||||
默认情况下,ESP-IDF 使用 C++23 语言标准和 GNU 扩展 (``-std=gnu++23``) 编译 C++ 代码。
|
||||
默认情况下,ESP-IDF 使用 C++26 语言标准和 GNU 扩展 (``-std=gnu++26``) 编译 C++ 代码。
|
||||
|
||||
要使用其他语言标准编译特定组件的源代码,请按以下步骤,在组件的 CMakeLists.txt 文件中设置所需的编译器标志:
|
||||
|
||||
@@ -182,7 +182,7 @@ ESP-IDF 希望应用程序入口点 ``app_main`` 以 C 链接定义。当 ``app_
|
||||
|
||||
许多 ESP-IDF 组件会以 :ref:`api_reference_config_structures` 作为初始化函数的参数。用 C 编写的 ESP-IDF 示例通常使用 `指定初始化器 <https://en.cppreference.com/w/c/language/struct_initialization>`_,以可读且可维护的方式填充有关结构体。
|
||||
|
||||
C 和 C++ 语言对于指定初始化器有不同的规则。例如,C++23(当前在 ESP-IDF 中默认使用)不支持无序指定初始化、嵌套指定初始化、混合使用指定初始化器和常规初始化器,而对数组进行指定初始化。因此,当将 ESP-IDF 的 C 示例移植到 C++ 时,可能需要对结构体初始化器进行一些更改。详细信息请参阅 `C++ aggregate initialization reference <https://en.cppreference.com/w/cpp/language/aggregate_initialization>`_。
|
||||
C 和 C++ 语言对于指定初始化器有不同的规则。例如,C++26(当前在 ESP-IDF 中默认使用)不支持无序指定初始化、嵌套指定初始化、混合使用指定初始化器和常规初始化器,而对数组进行指定初始化。因此,当将 ESP-IDF 的 C 示例移植到 C++ 时,可能需要对结构体初始化器进行一些更改。详细信息请参阅 `C++ aggregate initialization reference <https://en.cppreference.com/w/cpp/language/aggregate_initialization>`_。
|
||||
|
||||
|
||||
``iostream``
|
||||
|
@@ -159,8 +159,8 @@ function(__build_set_default_build_specifications)
|
||||
# function, which must be called after project().
|
||||
# Please update docs/en/api-guides/c.rst, docs/en/api-guides/cplusplus.rst and
|
||||
# tools/test_apps/system/cxx_build_test/main/test_cxx_standard.cpp when changing this.
|
||||
list(APPEND c_compile_options "-std=gnu17")
|
||||
list(APPEND cxx_compile_options "-std=gnu++2b")
|
||||
list(APPEND c_compile_options "-std=gnu23")
|
||||
list(APPEND cxx_compile_options "-std=gnu++26")
|
||||
endif()
|
||||
|
||||
idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND)
|
||||
@@ -183,7 +183,7 @@ function(__linux_build_set_lang_version)
|
||||
|
||||
# Building for Linux target, fall back to an older version of the standard
|
||||
# if the preferred one is not supported by the compiler.
|
||||
set(preferred_c_versions gnu17 gnu11 gnu99)
|
||||
set(preferred_c_versions gnu23 gnu17 gnu11 gnu99)
|
||||
set(ver_found FALSE)
|
||||
foreach(c_version ${preferred_c_versions})
|
||||
check_c_compiler_flag("-std=${c_version}" ver_${c_version}_supported)
|
||||
@@ -198,7 +198,7 @@ function(__linux_build_set_lang_version)
|
||||
"${preferred_c_versions}. Please upgrade the host compiler.")
|
||||
endif()
|
||||
|
||||
set(preferred_cxx_versions gnu++2b gnu++20 gnu++2a gnu++17 gnu++14)
|
||||
set(preferred_cxx_versions gnu++26 gnu++2b 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)
|
||||
|
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
/*
|
||||
* Current GCC-14.2.0 value for -std=gnu++23 and -std=gnu++2b.
|
||||
* The latest available C++ standard in current IDF's GCC: gnu++26.
|
||||
* If you change the C++ standard for IDF, you also need to change this.
|
||||
*/
|
||||
static_assert(__cplusplus == 202302L);
|
||||
static_assert(__cplusplus == 202400L);
|
||||
|
Reference in New Issue
Block a user