Skip to content

问询 - 08-literal-type-0 #35

@lost-42

Description

@lost-42

测试环境:

  • 操作系统: arch linux
  • 编译器: gcc version 15.2.1 20251112 (GCC) & clang version 21.1.6

在学习这一节的时候, 关于 constexpr std::string 的部分遇到了一些困难, 想寻求一下帮助和指教.

按照 LiteralType 的描述, 如果是一个 class type, 必须有一个 constexpr 的析构函数才能成为字面量类型. 而 ~basic_string 在 C++20 标准前都不是 constexpr. 按照 dslings/cpp11/xmake.lua 里面设置的 C++17 标准始终无法通过编译. (PS: dslings/en/cpp11/xmake.lua 里没有设置 C++17 标准).

但是将 C++ 标准设置为 C++20 后仍然可能无法通过编译(g++ 和 libstdc++ 库). 关于这部分, constexpr std::string update 里面提到了是不同库的表现差异. 按照这篇文章里面的结论, 我替换成了 clang 和 libc++ 库, 可以成功编译. 而如果继续用 g++ 和 libstdc++ 就必须写成 static constexpr std::string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions