Skip to content

[CI] add C++20 compile probe#79445

Open
gouzil wants to merge 1 commit into
PaddlePaddle:developfrom
gouzil:codex/cxx20-common-probe
Open

[CI] add C++20 compile probe#79445
gouzil wants to merge 1 commit into
PaddlePaddle:developfrom
gouzil:codex/cxx20-common-probe

Conversation

@gouzil

@gouzil gouzil commented Jul 8, 2026

Copy link
Copy Markdown
Member

PR Category

Environment Adaptation

PR Types

Devs

Description

本 PR 在 paddle/common/enforce.cc 增加一个最小 C++20 编译探针:

  • 使用 consteval,这是 C++20 才支持的语言特性;static_assert 只是把该探针真正实例化使用起来。
  • paddle/common/enforce.cc 会被编入 commoncommon_static,用于覆盖 Paddle 公共编译链路。
  • 目标是在 CI 或不同构建选项仍以 C++17、或工具链尚未完整支持 C++20 时,尽早暴露适配问题。

该改动不引入运行时逻辑,不改变现有错误处理行为,只用于编译期验证。

验证:

  • prek
  • ninja -C build common common_static -j8
  • 本地确认同一探针在 -std=c++20 下通过,在 -std=c++17 下因 consteval 编译失败

是否引起精度变化

否。该 PR 只新增编译期探针,不涉及算子实现、数值计算或运行时执行路径。

Copilot AI review requested due to automatic review settings July 8, 2026 16:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a minimal C++20 compile-time probe to paddle/common/enforce.cc to surface toolchain / build-flag mismatches early in CI by requiring a C++20-only language feature to compile.

Changes:

  • Add a consteval-based compile probe plus static_assert in paddle/common/enforce.cc to force instantiation at compile time.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread paddle/common/enforce.cc
Comment on lines +26 to +30
// C++20 compile probe: consteval is C++20-only, and this file is built into
// common and common_static.
consteval bool PaddleCxx20CompileProbe() { return true; }
static_assert(PaddleCxx20CompileProbe());

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已完成初审。发现一个会影响现有 C++17 fallback 构建路径的阻塞问题,具体证据和建议已放在行级评论里;修复后请提交新的 commit 以便复查。

当前还有部分检查仍在运行中,后续也请以完整 CI 结果为准。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

Comment thread paddle/common/enforce.cc
namespace {
// C++20 compile probe: consteval is C++20-only, and this file is built into
// common and common_static.
consteval bool PaddleCxx20CompileProbe() { return true; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 优先级:P1

这里无条件使用 consteval 会破坏仓库当前仍显式保留的 C++17 构建路径。cmake/flags.cmake 里 GCC < 11 仍会追加 -std=c++17,Windows 分支也设置 CMAKE_CXX_STANDARD 17;同时 paddle/common/CMakeLists.txt 会把本文件编入 commoncommon_static。在这些路径下,本行会直接语法失败(例如 c++ -std=c++17 -I. -fsyntax-only paddle/common/enforce.cc 会报 consteval does not name a type),导致现有受支持构建无法通过。

处理要求:请针对该评论修复并提交新的 commit。

请在同一个 PR 中先统一构建策略,再保留这个探针。可选方向之一是正式移除这些 C++17 fallback 并让配置阶段直接失败,例如:

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
   CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11)
  message(FATAL_ERROR "GCC >= 11 is required for the C++20 baseline.")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")

如果 GCC < 11 / Windows 的 C++17 路径还需要继续保留,则这个探针不能无条件放在会被这些路径编译的公共源文件中,需要先加条件或改放到只覆盖 C++20 目标的构建检查里。

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Paddle-CI-Agent | pr_review | 2026-07-09 00:39:31

📋 Review 摘要

PR 概述:在 enforce.cc 中增加 C++20-only consteval 编译探针,覆盖 common / common_static 编译链路。
变更范围paddle/common/enforce.cc
影响面 TagEnvironment Adaptation Execute Infrastructure

问题

级别 文件 概述
🔴 Bug paddle/common/enforce.cc:28 无条件 C++20 探针与 CMake 保留的 C++17 fallback 冲突,GCC < 11 / Windows 构建会在 common 编译阶段失败

📝 PR 规范检查

描述结构符合模板;标题 Tag [CI] 不在当前模板枚举中,建议改为与本 PR 影响面一致的官方 Tag。

标题建议(可直接复制):

  • [Environment Adaptation] add C++20 compile probe

总体评价

该探针能覆盖公共编译目标,但当前实现会使构建系统仍显式允许的 C++17 fallback 路径失效。需要先同步更新 CMake 工具链基线声明,或保留这些 fallback 的可编译性。

Comment thread paddle/common/enforce.cc
namespace {
// C++20 compile probe: consteval is C++20-only, and this file is built into
// common and common_static.
consteval bool PaddleCxx20CompileProbe() { return true; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug 这里无条件使用 consteval,会让仓库仍显式配置为 C++17 的构建路径直接失败。

paddle/common/enforce.cc 会进入 commoncommon_static,但 cmake/flags.cmake 目前仍对 GCC < 11 走 -std=c++17 fallback,并在 WIN32 下设置 CMAKE_CXX_STANDARD 17。因此这些被 CMake 接受的配置会在编译本文件时失败,而不是按构建系统声明的兼容路径继续工作。

建议修复方式:如果 Paddle 基线已经切到 C++20,请同步修改 cmake/flags.cmake,删除这些 C++17 fallback 或在 configure 阶段对 GCC < 11 / 当前 Windows 工具链给出明确 FATAL_ERROR;如果这些 fallback 仍需保留,则不要在公共源文件中放置无条件 C++20-only 代码。

@paddle-bot paddle-bot Bot added the contributor External developers label Jul 8, 2026
@paddle-bot

paddle-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants