0

I'm trying to output the full type of a typedef in the build log of Visual Studio; even for possibly failing typedefs, f.e. when a partial specialisation is missing. My specific version is 2019 but i also tried and failed with 2010 and 2015.

The only possible solution for this i could find is here but it doesn't work in Visual Studio.

Here's the testcode:

template<typename T>
struct Printer;
template <typename T>
struct ST;
template <>
struct ST<int&> {
    typedef int T;
};
template <typename T>
struct S {
    Printer<typename ST<T>::T> t;
};
int main() {
    typedef int& intref;
    S<intref> testi;

    typedef float& floatref;
    S<floatref> testf;

    typedef short& shortref;
    Printer<shortref> testsi;
}

And here is a godbolt

For this example, i'd like to see somewhere an output of

  1. "int" for the existing specialization
  2. "float&" for the missing specialization
  3. "short&" or "short int&" for the simple case
jesses
  • 559
  • 3
  • 15
  • 1
    It is *visual* C++, best to use the product the way it was intended. Nobody ever looks at a build log, they hover the mouse over the red squiggles. Which shows int& – Hans Passant Oct 16 '20 at 16:43
  • @HansPassant That's the best interpretation of "visual" i've ever heard :) I updated the code to show the limits of the squiggles. I first hoped that the "Code Analysis" would correctly report the type and it does for the really trivial cases but for the one currently in the question it doesn't. – jesses Oct 19 '20 at 08:12

1 Answers1

2

If I am placing the mouse cursor over the test incomplete object I can see the type passed as template argument see picture, it is not very clean but it is the only way I have found up to now.

enter image description here

MaB
  • 33
  • 2
  • I updated the code to show the limits of the squiggles. I first hoped that the "Code Analysis" would correctly report the type and it does for the really trivial cases but for the one currently in the question it doesn't. – jesses Oct 19 '20 at 08:15
  • @jesses what do you mean ? If my mouse hovers `````` in ```S testf;``` I see the ```typedef float& floatref``` and for ```testf``` I have ```S``` – MaB Oct 19 '20 at 19:27
  • Sorry, I oversimplified the example when i tried to narrow it down; in the codebase i have to work with the places where template expansion in the build log would be helpful are much more complex. I hope it's more clear now with the added missing specialization. – jesses Oct 21 '20 at 08:07
  • In addition to this method, it seems that there is no particularly good method to meet your needs. – Barrnet Chou Oct 22 '20 at 07:12
  • @BarrnetChou there is the "Code Analysis" which sometimes outputs more than the compiler – jesses Oct 22 '20 at 07:31
  • So, do you mean that the complete type can be obtained by code analysis? Have you solved this problem? I searched a lot of information and did not find a better method. – Barrnet Chou Oct 23 '20 at 08:18
  • @BarrnetChou In a few cases i observed "Code Analysis" to report more expanded types than the compiler. But for the code above it doesn't. – jesses Oct 23 '20 at 12:43
  • So, there is still no better solution to this problem. – Barrnet Chou Oct 26 '20 at 07:12