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

问题描述 投票:0回答:1

[我在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);
}

我的环境:

OS:Windows 10 Pro x64版本1909 OS内部版本18363.836

IDE:Visual Studio 2019版本16.6.0

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

Windows SDK版本:10.0

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

c++ windows compiler-warnings
1个回答
0
投票
此编译器消息并不代表其自身,它伴随着另一条消息。鉴于您的代码完整的输出是

警告C4100:'argv':未引用的形式参数消息:请参见对正在编译的函数模板实例化'int run_loop(int,const char_type * [])'的引用与[char_type = wchar_t]

因此,主要消息是argv是未引用的形式参数。至于可能取决于如何实例化模板的模板,编译器为您提供了有关如何实例化模板的其他提示。

BTW,更正了该警告之后,您仍然会收到相同的消息,因为argcex也未被使用。删除所有三个名称或使用它们后,您将不再收到警告和消息。

© www.soinside.com 2019 - 2024. All rights reserved.