Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See reference to function template instantiation message when catch std::exception in Visual Studio 2019

I've noticed an annoying message during a build of C++ console application in Visual Studio 2019, Windows 10. I have a template function which produces a message:

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

Similar code compiles fine with no the message on macOS and Ubuntu, but now I'm porting it to Windwos and see this. It is not error or warning, just an info message. I started to comment out code blocks inside of the funtion and found that when I commented out std::exception catching the message disappeared. What does this message mean and how should I deal with it? Leave it as is or should I redisign my code in some another way? Here is the simplified code snippet that produces the above message:

#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);
}

My environment:

OS: Windows 10 Pro x64 Version 1909 OS build 18363.836

IDE: Visual Studio 2019 version 16.6.0

Win32 Console application template in C++ with default settings:

Windows SDK Version: 10.0

Platform Toolset: Visual Studio 2019 (v142)

like image 408
C0DEF52 Avatar asked Sep 05 '25 03:09

C0DEF52


1 Answers

This compiler messages does not stand for its own, it accompanies another message. Given your code the complete output is

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
]

So the main message is the warning that argv is an unreferenced formal parameter. The compilers gives you an additional hint with the message how the template was instantiated. That can be useful if you have multiple instantiations of a template and the warning only occurs with some instantiations.

BTW, after fixing that warning you still get the same message because argc and ex are also unused. After removing all three names or using them you don't get the warning and the message any more.

like image 87
Werner Henze Avatar answered Sep 07 '25 20:09

Werner Henze