26444(es84) in VS 2019 project RRS feed

  • Question

  • It is VS2019 v. 16.0.0, C++ workspace. The project is MFC dialog-based exe file.

    The OS is Win 7 Pro SP1.

    Problem: VS issues 26444 message on code lines that were perfectly OK in VS2017.

    After I downloaded and installed VS2019 Community v.16.0.0 I copied whole project folder into project directory of VS2019.I compiled and run it with Win SDK 10.017763.0 and VS platform v142. All was almost fine, but couple minutes I saw in CPP file this:

    and the similar in this cpp file. Hovering over green line opens text:

    "Struct spin_params<int> 

    26444 Avoid unnamed objectswith custom constructors and destructors (es.84"

    Build with v141 (VS2017) goes OK, without green lines.

    I will show the C++ code:

    // definition of spin_params

    template <typename T> struct spin_params {

    // Constructors spin_params(string_t& name, T lowerVal, T upperVal, T delta, T pos, int nPrecision = 0) : ms_name(name), ms_lowerVal(lowerVal), ms_upperVal(upperVal), ms_delta(delta), ms_pos(pos), ms_nPrecision(nPrecision) {} spin_params() {} {} ~spin_params(){} spin_params<T> operator =(const spin_params<T>& rhs) { .............................. } // Members string_t ms_name; T ms_lowerVal; T ms_upperVal; T ms_delta; T ms_pos; int ms_nPrecision; };

    // Definition of std::variant var_sp_types using var_sp_types = variant<spin_params<char>, spin_params<uint8_t>, spin_params<int>, spin_params<unsigned int>, spin_params<long>, spin_params<unsigned long>, spin_params<float>, spin_params<double>>; // Vector that contains var_sp_types vector<var_sp_types>& vSpinParams; // vSpinParams is populated with instances of spin_params<int> and spin_params<double> spin_params<int> spInt; spin_params<double> spDouble; vector<var_sp_types>::const_iterator it = vSpinParams.begin(); vector<var_sp_types>::const_iterator itE = vSpinParams.end();

    // Read spin_params<int and spin_params<double> from variants in the vector using

    //std::get<type>(variant instance) if (it != itE) { spInt = get<spin_params<int>>(*it++); m_spEpochs.InitSpin(spInt, &m_edEpochs), ++m_nSpinCnt; if (it != itE) { spInt = get<spin_params<int>>(*it++); m_spBatch.InitSpin(spInt, &m_edBatch), ++m_nSpinCnt; if (it != itE) { spDouble = get<spin_params<double>>(*it++); m_spLearnRate.InitSpin(spDouble, &m_edLearnRate), ++m_nSpinCnt; ......................................................

    It might be bug because the spin_params is mentioned as a type only.

    Anyway, how can I get rid of these messages?

    Wednesday, April 10, 2019 10:37 PM

All replies

  • Hello,

    Thanks for posting here.

    >>Anyway, how can I get rid of these messages?

    As MSDN shows, these seems to be the code analysis warnings. Code analysis runs automatically in the background and warnings display as green squiggles.

    Click Tools>Options>Text Editor > C/C++ > Advanced > Code analysis: set disable background code analysis as True.

    Best wishes,

    Jack Zhang

    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Thursday, April 11, 2019 3:35 AM
  • One other way you can get rid of this code analysis warning is by changing the default constructor and destructor to the following.

    spin_params() = default;
    ~spin_params() = default;

    Since this is warning you about doing what you are doing with a class with a custom constructor and destructor, where your current default constructor and destructor are empty.

    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Saturday, April 13, 2019 10:19 AM
  • Thanks for reply.

    Unfortunately, it does mot work.

    Monday, April 15, 2019 12:38 AM
  • Maybe it is not correct to assign the result of get to an iterator. Consider this:

       spin_params<int> value = get<spin_params<int>>(*it++);

    Adjust InitSpin too.

    Monday, April 15, 2019 5:46 AM
  • This is exactly what I dud: please look at code in the first post

    spInt was defined as spin_params<int> = ...

    Besides, in my opinion, get should return value of type it asked to return, and it is job for compiler decide is it possible to convert the result as requested.

    It seems that complaint of the Code Analyst is about type in get<spin_params<int>>(...)

    Tuesday, April 16, 2019 2:10 AM
  • Then use local variables like this:


       spin_params<int> spInt = get<spin_params<int>>(*it++);


    or adjust (fix) the ‘=’ operator:


       spin_params<T>& operator = ( const spin_params<T>& rhs )


           . . .



    Tuesday, April 16, 2019 5:08 AM
  • Thanks for reply.

    Did you check your recommendations?

    SpInt is local for this functions, and again, in my opinion it is type name for specialization of get to be used.

    I understand that get right Code Analyzator is very, very difficult, but I am not happy with what we have in VS 2019.

    For example, I got warnings for local vector<double> vD; that the variable is not initialized. But implicitly called vector's constructor did exactly that and vD is a legitimate empty vector.

    In more complicated example Analyzator asks to cast int a and int B to 8-byte variables before calculate c = a*b. Generally it is true, but in this code a and b are declared as static inline cons int and initialized to 32, so c = 1024All it could be calculated in compile time. Of course, it is hard for analyzator, but I would appreciate option to silence that warninng.

    So the best option is to turn analyzator OFF.

    Wednesday, April 17, 2019 1:11 AM
  • Hi,

    Have you got any updates? If your case has been solved, please help to mark answers. If not, just feel free to contact us.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Jeanine Zhang

    Thursday, May 2, 2019 9:23 AM
  • No, I got no updates for Analyzer. The Updates for VS 2019 all have installed, last is 16.0.3.

    I do not know the issue is solved, I just turn Analyzer off.

    I understand it is very hard to account for so many things in code analysis. Sometimes warnings from Analyzer are very useful, but if they are not, the user should have possibility to set his/her own options for analysis, in my opinion.

    Regarding get<spin_params<double/int/others>>(...) .I think that might be corrected.

    I will happy to cooperate.

    Anyway, thanks for reply.

    Thursday, May 2, 2019 2:56 PM
  • "So the best option is to turn analyzator OFF". Absolutely correct! Code Analyzator is buggy. Especially if it shows a lot of errors (not warnings!) in STL. As far as I see Microsoft's developers doesn't use it themselves. So why should we?
    Thursday, July 18, 2019 6:22 AM