c++ - 在 Visual Studio 2019 中捕获 std::exception 时,请参阅对函数模板实例化消息的引用

标签 c++ windows compiler-warnings

在 Visual Studio 2019、Windows 10 中构建 C++ 控制台应用程序期间,我注意到一条烦人的消息。我有一个生成消息的模板函数:

message : see reference to function template instantiation 'int run_loop<wchar_t>(int,const char_type *[])' being compiled
    with
    [
        char_type=wchar_t
    ]

类似的代码编译得很好,在 macOS 和 Ubuntu 上没有消息,但现在我将它移植到 Windwos 并看到这个。这不是错误或警告,只是一条信息消息。我开始注释掉函数内部的代码块,发现当我注释掉std::exception时捕捉到的消息消失了。此消息是什么意思,我应该如何处理?保持原样还是我应该以其他方式重新设计我的代码?这是产生上述消息的简化代码片段:
#include <exception>

template<class char_type>
int run_loop(int argc, const char_type* argv[])
{
    try
    {
    }
    catch (const std::exception& ex)
    {
    }

    return 0;
}

int wmain(int argc, const wchar_t* argv[])
{
    return run_loop(argc, argv);
}

我的环境:

操作系统:Windows 10 Pro x64 版本 1909 操作系统版本 18363.836

IDE:Visual Studio 2019 版本 16.6.0

C++ 中的 Win32 控制台应用程序模板,具有默认设置:

Windows SDK 版本:10.0

平台工具集:Visual Studio 2019 (v142)

最佳答案

此编译器消息不代表它自己,它伴随着另一条消息。给定您的代码,完整的输出是

warning C4100: 'argv': unreferenced formal parameter
message : see reference to function template instantiation 'int run_loop(int,const char_type *[])' being compiled
with
[
char_type=wchar_t
]



所以主要信息是警告 argv是一个未引用的形式参数。编译器通过消息如何实例化模板为您提供了额外的提示。如果您有多个模板实例化并且警告仅在某些实例化时出现,这将很有用。

顺便说一句,修复该警告后,您仍然会收到相同的消息,因为 argcex也未使用。删除所有三个名称或使用它们后,您将不再收到警告和消息。

关于c++ - 在 Visual Studio 2019 中捕获 std::exception 时,请参阅对函数模板实例化消息的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61984390/

相关文章:

c++ - 如何编写一个符合STL标准的容器但其大小未知?

c++ - 具有可变数量的模板参数的简单方法

c++ - Fixed_alpha_shape_3() 是否破坏或修改原始三角剖分?

c# - RegisterPowerSettingsNotification C# pinvoke

windows - 为 XAMPP 启用 SSL 后 Apache 无法启动

c++ - 为什么 int a; a = std::max(a, x) 不发出 "uninitialized"警告

c++ - Mac OS X open Command 或同等命令的 C 头文件

vb.net - 通过网站 IP 的 TCP 连接

c# - 如何抑制 C# 警告 CS0675 : Bitwise-or operator used on a sign-extended operand

delphi - 如何摆脱被 `continue` 混淆的编译器警告?