I came across this blog post about using different overload resolution methods to make compile errors more readable, and I’m wondering if there are any changes I can make as a caller of a templated function to get similar readability improvements. Specifically, I have a CMake project in Visual Studio 2022 that I’m compiling with MSVC, and calls to std::make_shared with invalid parameters are hard to read the logs for. The error generated is not in my source code:
G:\VisualStudio\VC\Tools\MSVC\14.43.34808\include\xutility(502): error C2672: 'std::construct_at': no matching overloaded function found
Since this is the line where the actual compile error is, it’s what Visual Studio shows in the Error List window, which doesn’t actually help me fix the error. Every time this happens, I have to skim through the notes of that compile error to somewhere in the middle where it says where the make_shared function template was instantiated, i.e. the line in my code that needs to be fixed:
23:34:01:880 G:\VisualStudio\VC\Tools\MSVC\14.43.34808\include\xutility(502): note: the template instantiation context (the oldest one first) is
23:34:01:880 C:\sourcefile.cpp(123): note: see reference to function template instantiation 'std::shared_ptr<MyClass> std::make_shared<MyClass,WrongParam>(WrongParam)' being compiled
(This particular error generates 49 lines of compiler output, and the location in my source code that actually has the problem only shows up here on line 22.) This is unnecessarily time-consuming, so I would like to not have to do it.
There are two possible approaches I’ve thought of to solving the problem that I have questions about:
- Is there a better way to construct
std::shared_ptrs that would result in more readable compile errors while still being idiomatic? Usingnewinstead ofmake_shareddoes this, but isn’t idiomatic. - Can I customize how Visual Studio generates Error List entries from the raw compiler output and make it automatically find the line I’m looking for? This blog post says how to get things from stdout into the Error List, but I think I would need to configure CMake to run a post-build custom command that parses the build output, and I don’t know how to do that.
To be clear, this question is not about how to fix a particular compile error–I understand how to find the right information in the compiler output to do that. This question is about practices that minimize the amount of work it takes to find the right line in the compiler output, preferably by making Visual Studio find it instead of me.