std :: destry_at差异是主要编译器之间的差异吗?

发布于 2025-02-09 21:28:57 字数 760 浏览 1 评论 0原文

使用:使用COMPILER Explorer:

#include <iostream>
#include <memory>

struct test
{
  test(int i)
  {
    std::cout << "test::test("<<i<<")\n";
  }
  ~test()
  {
    std::cout << "~test()\n";
  }
};

template<>
void std::destroy_at(test* p) 
{
  std::cout<<"std::destroy_at<test>\n";
  p->~test();
}

int
main ()
{
  auto sp = std::make_shared<test>(3);
  return 33;
}

使用C ++ 20与GCC X86-64或Clang X86-64提供预期输出:

Program returned: 33
test::test(3)
std::destroy_at<test>
~test()

但是X64 MSVC v19.32给出:

Program returned: 33
test::test(3)
~test()

好像STD :: DESTON_AT在这里无效。

这种符合行为,我的误解还是MSVC不符合或误解?

Using compiler explorer with:

#include <iostream>
#include <memory>

struct test
{
  test(int i)
  {
    std::cout << "test::test("<<i<<")\n";
  }
  ~test()
  {
    std::cout << "~test()\n";
  }
};

template<>
void std::destroy_at(test* p) 
{
  std::cout<<"std::destroy_at<test>\n";
  p->~test();
}

int
main ()
{
  auto sp = std::make_shared<test>(3);
  return 33;
}

Gives the expected output using C++20 with gcc x86-64 or clang x86-64:

Program returned: 33
test::test(3)
std::destroy_at<test>
~test()

But x64 msvc v19.32 gives:

Program returned: 33
test::test(3)
~test()

As if the std::destroy_at has no effect here.

Is this conforming behavior, my misunderstanding or a msvc non conformance or misconfiguration?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

指尖上得阳光 2025-02-16 21:28:57

专业化标准库功能为“ noreferrer”> ub自C ++ 20 以来。

Specializing standard library functions is UB since C++20.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文