Skip to content

Commit 03855b9

Browse files
committed
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
2 parents a939f41 + 4c481c8 commit 03855b9

8 files changed

Lines changed: 35 additions & 15 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#pragma once
7+
#include_next <stdatomic.h>
8+
9+
/* The ATOMIC_VAR_INIT macro was deprecated in:
10+
* - C17
11+
* - C++20
12+
* and removed in subsequent standards.
13+
* Since users may change the standard version for their projects,
14+
* IDF should remain compatible across different standards.
15+
*/
16+
#if __STDC_VERSION__ > 201710L || __cplusplus > 202002L
17+
# ifndef ATOMIC_VAR_INIT
18+
# define ATOMIC_VAR_INIT(val) (val)
19+
# endif
20+
#endif

components/newlib/test_apps/newlib/main/test_misaligned_mem_performance.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#define MAX_MEMTEST_SIZE 4096
1313

14-
uint32_t test_function_dest_src_size(void (*foo)(), bool pass_size)
14+
uint32_t test_function_dest_src_size(void (*foo)(...), bool pass_size)
1515
{
1616
uint32_t ccount1, ccount2;
1717
char* test_des = heap_caps_aligned_alloc(32, MAX_MEMTEST_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);

docs/en/api-guides/c.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ In general, all C features supported by the compiler (currently GCC) can be used
1717
C Version
1818
---------
1919

20-
**GNU dialect of ISO C17** (``--std=gnu17``) is the current default C version in ESP-IDF.
20+
**GNU dialect of ISO C23** (``--std=gnu23``) is the current default C version in ESP-IDF.
2121

2222
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:
2323

@@ -38,4 +38,4 @@ The following features are not supported in ESP-IDF.
3838
Nested Function Pointers
3939
^^^^^^^^^^^^^^^^^^^^^^^^
4040

41-
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.
41+
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.

docs/en/api-guides/cplusplus.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The following C++ features are supported:
2626
C++ Language Standard
2727
---------------------
2828

29-
By default, ESP-IDF compiles C++ code with C++23 language standard with GNU extensions (``-std=gnu++23``).
29+
By default, ESP-IDF compiles C++ code with C++26 language standard with GNU extensions (``-std=gnu++26``).
3030

3131
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:
3232

@@ -182,7 +182,7 @@ Designated Initializers
182182

183183
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.
184184

185-
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.
185+
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.
186186

187187

188188
``iostream``

docs/zh_CN/api-guides/c.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Newlib 的版本号记录在 :component_file:`newlib/sbom.yml` 文件中。
1717
C 版本
1818
------
1919

20-
**ISO C17 的 GNU 方言** (``--std=gnu17``) 是 ESP-IDF 中当前默认的 C 语言版本。
20+
**ISO C23 的 GNU 方言** (``--std=gnu23``) 是 ESP-IDF 中当前默认的 C 语言版本。
2121

2222
使用不同的语言标准编译某个组件的源代码,请在组件的 ``CMakeLists.txt`` 文件中设置所需的编译器标志:
2323

@@ -38,4 +38,4 @@ ESP-IDF 不支持以下功能。
3838
嵌套函数的指针
3939
^^^^^^^^^^^^^^
4040

41-
**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 不允许从栈执行代码,因此不支持使用指向嵌套函数的指针。
41+
**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 不允许从栈执行代码,因此不支持使用指向嵌套函数的指针。

docs/zh_CN/api-guides/cplusplus.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ESP-IDF 支持以下 C++ 功能:
2626
C++ 语言标准
2727
---------------------
2828

29-
默认情况下,ESP-IDF 使用 C++23 语言标准和 GNU 扩展 (``-std=gnu++23``) 编译 C++ 代码。
29+
默认情况下,ESP-IDF 使用 C++26 语言标准和 GNU 扩展 (``-std=gnu++26``) 编译 C++ 代码。
3030

3131
要使用其他语言标准编译特定组件的源代码,请按以下步骤,在组件的 CMakeLists.txt 文件中设置所需的编译器标志:
3232

@@ -182,7 +182,7 @@ ESP-IDF 希望应用程序入口点 ``app_main`` 以 C 链接定义。当 ``app_
182182

183183
许多 ESP-IDF 组件会以 :ref:`api_reference_config_structures` 作为初始化函数的参数。用 C 编写的 ESP-IDF 示例通常使用 `指定初始化器 <https://en.cppreference.com/w/c/language/struct_initialization>`_,以可读且可维护的方式填充有关结构体。
184184

185-
C 和 C++ 语言对于指定初始化器有不同的规则。例如,C++23(当前在 ESP-IDF 中默认使用)不支持无序指定初始化、嵌套指定初始化、混合使用指定初始化器和常规初始化器,而对数组进行指定初始化。因此,当将 ESP-IDF 的 C 示例移植到 C++ 时,可能需要对结构体初始化器进行一些更改。详细信息请参阅 `C++ aggregate initialization reference <https://en.cppreference.com/w/cpp/language/aggregate_initialization>`_。
185+
C 和 C++ 语言对于指定初始化器有不同的规则。例如,C++26(当前在 ESP-IDF 中默认使用)不支持无序指定初始化、嵌套指定初始化、混合使用指定初始化器和常规初始化器,而对数组进行指定初始化。因此,当将 ESP-IDF 的 C 示例移植到 C++ 时,可能需要对结构体初始化器进行一些更改。详细信息请参阅 `C++ aggregate initialization reference <https://en.cppreference.com/w/cpp/language/aggregate_initialization>`_。
186186

187187

188188
``iostream``

tools/cmake/build.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ function(__build_set_default_build_specifications)
159159
# function, which must be called after project().
160160
# Please update docs/en/api-guides/c.rst, docs/en/api-guides/cplusplus.rst and
161161
# tools/test_apps/system/cxx_build_test/main/test_cxx_standard.cpp when changing this.
162-
list(APPEND c_compile_options "-std=gnu17")
163-
list(APPEND cxx_compile_options "-std=gnu++2b")
162+
list(APPEND c_compile_options "-std=gnu23")
163+
list(APPEND cxx_compile_options "-std=gnu++26")
164164
endif()
165165

166166
idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND)
@@ -183,7 +183,7 @@ function(__linux_build_set_lang_version)
183183

184184
# Building for Linux target, fall back to an older version of the standard
185185
# if the preferred one is not supported by the compiler.
186-
set(preferred_c_versions gnu17 gnu11 gnu99)
186+
set(preferred_c_versions gnu23 gnu17 gnu11 gnu99)
187187
set(ver_found FALSE)
188188
foreach(c_version ${preferred_c_versions})
189189
check_c_compiler_flag("-std=${c_version}" ver_${c_version}_supported)
@@ -198,7 +198,7 @@ function(__linux_build_set_lang_version)
198198
"${preferred_c_versions}. Please upgrade the host compiler.")
199199
endif()
200200

201-
set(preferred_cxx_versions gnu++2b gnu++20 gnu++2a gnu++17 gnu++14)
201+
set(preferred_cxx_versions gnu++26 gnu++2b gnu++20 gnu++2a gnu++17 gnu++14)
202202
set(ver_found FALSE)
203203
foreach(cxx_version ${preferred_cxx_versions})
204204
check_cxx_compiler_flag("-std=${cxx_version}" ver_${cxx_version}_supported)

tools/test_apps/system/cxx_build_test/main/test_cxx_standard.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
66
/*
7-
* Current GCC-14.2.0 value for -std=gnu++23 and -std=gnu++2b.
7+
* The latest available C++ standard in current IDF's GCC: gnu++26.
88
* If you change the C++ standard for IDF, you also need to change this.
99
*/
10-
static_assert(__cplusplus == 202302L);
10+
static_assert(__cplusplus == 202400L);

0 commit comments

Comments
 (0)