当前位置: 首页 > 知识库问答 >
问题:

这是GCC的bug吗?

阎慈
2023-03-14
#include <codecvt>
#include <string>
#include <locale>

std::string to_gbk(const std::wstring& u16_str)
{
        using Facet = std::codecvt_byname<wchar_t, char, std::mbstate_t>;
        std::wstring_convert
                <std::codecvt<wchar_t, char, std::mbstate_t>>
                wstr_2_gbk(new Facet("zh_CN.GBK"));

        return wstr_2_gbk.to_bytes(u16_str);
}

int main()
{
        to_gbk(L"");
}
[root@localhost ~]# g++ main.cpp 
In file included from /usr/include/c++/6.2.1/bits/locale_conv.h:41:0,
                 from /usr/include/c++/6.2.1/locale:43,
                 from main.cpp:3: /usr/include/c++/6.2.1/bits/unique_ptr.h: In instantiation of ‘void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = std::codecvt<wchar_t, char, __mbstate_t>]’:
/usr/include/c++++/6.2.1/bits/unique_ptr.h:236:17:   required from ‘std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = std::codecvt<wchar_t, char, __mbstate_t>; _Dp = std::default_delete<std::codecvt<wchar_t, char, __mbstate_t> >]’
/usr/include/c++/6.2.1/bits/locale_conv.h:218:7:   required from here
/usr/include/c++/6.2.1/bits/unique_ptr.h:76:2: error: ‘virtual std::codecvt<wchar_t, char, __mbstate_t>::~codecvt()’ is protected within this context
delete __ptr;
^~~~~~
In file included from /usr/include/c++/6.2.1/codecvt:41:0,
                 from main.cpp:1:
/usr/include/c++/6.2.1/bits/codecvt.h:426:7: note: declared protected here
       ~codecvt();
       ^

这是GCC的bug吗?

共有1个答案

马寒
2023-03-14

这是GCC的bug吗?

否。std::codecvt的析构函数受保护。参见[locale.codecvt](标准草案):

template <class internT, class externT, class stateT>
class codecvt : public locale::facet, public codecvt_base {
// ...
protected:
    ~codecvt();
};

显然,其他的实现选择了提高对公众的可见性,但这不是标准所要求的。

template<class I, class E, class S>
struct codecvt : std::codecvt<I, E, S>
{
    ~codecvt()
    { }
}

...

std::wstring_convert<codecvt<wchar_t, char, std::mbstate_t> >;
 类似资料:
  • 在此输入图像说明发送查询https://graph.Microsoft.com/v1.0/groups/delta?$select=DisplayName,securityIdentifier(在Microsoft graph API explorer中),并接收内部服务器错误{“错误”:{“代码”:“Service_InternalServerError”,“消息”:“遇到内部服务器错误”,“I

  • element-ui InfiniteScroll 在线地址 https://codesandbox.io/p/sandbox/hopeful-knuth-twdttl?file=%2... 我的使用方式 但是还是触发了 load 方法 默默打开 element-ui 源码调试了一下 packages/infinite-scroll/src/main.js line:69 发现这个 value 永

  • 我一直在尝试使用log类来捕获一些使用本地存储的奇怪的设备特定故障。当我进入Log类并跟踪代码时,我注意到了一个bug。 同时,这是一个Bug,还是我从用户的角度不理解它的功能?

  • 对于 GCC 的认知,很多读者还仅停留在“GCC 是一个C语言编译器”的层面,是很片面的。从本节开始,我将带领大家系统学习 GCC,本节先带领大家系统地了解一下 GCC。 谈到 GCC,就不得不提 GNU 计划。GNU 全称 GNU's Not UNIX,又被称为“革奴计划”,由理查德·斯托曼于 1983 年发起。GNU 计划的最终目标是打造出一套完全自由(即自由使用、自由更改、自由发布)、开源的

  • 问题内容: 我当时在考虑使用TIMESTAMP存储日期和时间,但是我读到它有2038年的限制。与其大量提出问题,不如将其分解成小部分,以便新手用户也易于理解。所以我的问题是: 2038年的问题到底是什么? 为什么会发生?发生时会发生什么? 我们该如何解决? 是否有使用它的其他可能的选择,而不会引起类似的问题? 当使用TIMESTAMP的现有应用程序真正发生时,我们该怎么办? 提前致谢。 问题答案:

  • 问题内容: 希望我能得到帮助,我会问一个一般性的问题: 我正在使用,并且由于没有(值,文本)(因此我可以显示文本并在代码中使用值)。由于这种泄漏,我创建 List了对象(myList),该对象与并行工作。我每个项目添加到JList我加入myList,所以同样的指标将包含相同的信息 在两个对象(JList和MYLIST)我用的方法来获得指标,并用它myList来的小狗信息… 问题:就是当我选择价值的