Visual Studio 2015 Error Code Invalid File

I am using VS 2015 Enterprise and I conducted a general unit test to analyze code coverage. I look at the list of private blocks for each function, and they usually seem correct. However, when I right-click the method โ†’ โ€‹โ€‹"Go to source code", some functions go to the right place in the source code (the corresponding .cpp file), but on others it tries to open the header file (the source line number is correct, but the code is in the .cpp file, not the .h file). This affects the selection of source code - functions that VS thinks in .h are not allocated in .cpp. I can not determine the difference in functions (the same visibility, the same header and source files), except, maybe, what stream they are called. Any idea why VS thinks some kind of code is in .h and not .cpp?

+5
source share
1 answer

Apparently, although VS 2015 supports the C ++ 11 function with non-static data element initializers (it compiles correctly), the coverage tool pinches this function. Here is the MCVE. I am using VS 14.0.24720.00 Update 1. To play, compile this program, then get code coverage by running it using the General Test . If x initialized, the coverage tool looks for the code for the constructor in the .h file. If you select = 0 , it will correctly define the constructor definition, as in .cpp. In my product code, this was not a constructor, but seemingly random functions, which, according to the coverage tool, were defined in the .h file. The fix, in my case, was simply to move the initialization of the data member to the constructor initialization list.

 //.h class Test { public: Test(); ~Test(); void Func1(); void Func2(); void Func3(); int x = 0; }; 

.

 // .cpp #include "Test.h" #include <iostream> Test::Test() { std::cout << "in Test()" << std::endl; } Test::~Test() { } void Test::Func1() { std::cout << "in Func1" << std::endl; Func2(); Func3(); } void Test::Func2() { std::cout << "in Func2" << std::endl; } void Test::Func3() { std::cout << "in Func3" << std::endl; } 
0
source

Source: https://habr.com/ru/post/1243790/


All Articles