Skip to content

C++20 编译失败 #1131

@hchunhui

Description

@hchunhui

Describe the bug
librime-lua 收到一个报告,用 -std=c++20 编译失败:
hchunhui/librime-lua#427

经分析实际上应该是 librime rime/common.h 中一处与 C++20 不兼容。

To Reproduce
最小复现样例:

#include <iostream>
#include <filesystem>

class path : public std::filesystem::path {
  // from rime/common.h:130
  friend std::ostream& operator<<(std::ostream& os, const path& p) {
    return os << p.u8string();
  }
};

环境:

gcc (Debian 14.2.0-19) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

编译命令:

g++ -std=c++20 foo.cc

报错:

foo.cc: In function ‘std::ostream& operator<<(std::ostream&, const path&)’:
foo.cc:7:15: error: no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘std::u8string’ {aka ‘std::__cxx11::basic_string<char8_t>’})
    7 |     return os << p.u8string();
      |            ~~ ^~ ~~~~~~~~~~~~
      |            |               |
      |            |               std::u8string {aka std::__cxx11::basic_string<char8_t>}
      |            std::ostream {aka std::basic_ostream<char>}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions