Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions paddle/common/enforce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ limitations under the License. */
REGISTER_LOG_SIMPLY_STR(std::string);
COMMON_DECLARE_int32(call_stack_level);
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 目标的构建检查里。

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 代码。

static_assert(PaddleCxx20CompileProbe());

Comment on lines +26 to +30
class StrSizeCmp {
public:
bool operator()(const std::string& lhs, const std::string& rhs) const {
Expand Down
Loading