debug does not see a template member


  • It is Visual Studio 2017 Community 15.8.1 under Windows 7 Pro SP1, The project is MFC project but the problem is with C++ native debug session.


     // My Header
    template <class T>
    struct MyStruct
       static vector<T> m_vT;
    // initialization,any
    vector<t> MyStruct::m_vT(128);
    using MyStructWithInt = MyStruct<int>:
    // Source file Mysource.cpp
    #include "MyHeader
    // Other includes
    int main()
    vector<int> vI = MyStructInt::m_vT;

    In Debug session I can see vI in all details, but MyStructWithInt::m_vT sais 'no access' to this member.

    I understand that m_vT is compiled and placed into other section of the memory, before app entered main.

    Is this behavior of VS debugger legitimate?

    Tuesday, August 28, 2018 12:01 AM

All replies

  • >It is Visual Studio 2017 Community 15.8.1 under Windows 7 Pro SP1, The project is MFC project but the problem is with C++ native debug session.

    Can you show source for a trivial console that anyone can copy/paste into VS and compile and check the issue you're having please.


    Tuesday, August 28, 2018 10:29 AM
  • To David Lowndes:

    Thank for reply.

    Below is the simplest Console VS app:

    // Tips for Getting Started: 
    //   1. Use the Solution Explorer window to add/manage files
    //   2. Use the Team Explorer window to connect to source control
    //   3. Use the Output window to see build output and other messages
    //   4. Use the Error List window to view errors
    //   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
    //   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
    // Header pch.h
    #ifndef PCH_H
    #define PCH_H
    // TODO: add headers that you want to pre-compile here
    #endif //PCH_H

    // Source pch.cpp
    // pch.cpp: source file corresponding to pre-compiled header; necessary for compilation to succeed
    #include "pch.h"
    // In general, ignore this file, but keep it around if you are using pre-compiled headers.

    // DebugTest.cpp : This file contains the 'main' function. Program execution begins and ends there.
    #include "pch.h"
    #include <iostream>
    #include <vector>
    using namespace std;
    template <typename T>
    struct DebugStruct
      static vector<T> m_vT;
    using MyDStruct = DebugStruct<int>;
    vector<int> MyDStruct::m_vT(128);
    int main()
      vector<int> vI = MyDStruct::m_vT;
        std::cout << "Hello World!\n"; 

    In Quick Watch:

    Name Value Type
    MyDStruct::m_vT identifier "MyDStruct" is undefined

    Name Value Type
    vI { size=128 } std::vector<int,std::allocator<int> >

    By a way, pch is for precompiled header; VS refuses to build if you delete it from the project and from project properties. It happy with empty files. Strange!

    Also,  'Hello...' is added by VS, I did not ask for it.

    • Edited by Geoyar Tuesday, August 28, 2018 9:37 PM
    Tuesday, August 28, 2018 9:33 PM
  • Thanks for that.

    It would appear to me to be due to use of using here:

    using MyDStruct = DebugStruct<int>;

    since the long form: DebugStruct<int>::m_vT
    can be shown OK by the debugger.

    This reproduces in both 15.8.2 and 15.9 preview 1 for me, so please go ahead and report it to MS using the Report a Problem facility
    from the VS IDE. Be sure to supply your repro project and clear instructions on what to do to reproduce it, that way it should get
    past the first hurdle.

    When you have a link to the bug report, please post it here and I'll add a vote and comment to your report.


    Tuesday, August 28, 2018 11:37 PM
  • ALready have submitted, am waiting for confirmation.
    Wednesday, September 19, 2018 12:54 AM
  • >ALready have submitted, am waiting for confirmation.

    Got a link to the report that you can share so that we can follow up on it?


    Wednesday, September 19, 2018 1:08 PM
  • Dave,

    The link is:

    The Status: Triaged.

    Thursday, September 20, 2018 12:36 AM
  • Thanks, voted.

    Thursday, September 20, 2018 7:35 AM