Skip to content

Can't obtain full type of the non-template type parameter in clang frontend #57562

Closed
@DoDoENT

Description

@DoDoENT

Consider this example:

template< typename T, auto ... dims >
struct NDArray;

struct Dimension
{
    using value_type = unsigned short;

    value_type size{ value_type( 0 ) };
};

template < typename ConcreteDim >
struct DimensionImpl : Dimension {}; 

struct Width : DimensionImpl< Width  > {};
struct Height: DimensionImpl< Height > {};

inline constexpr Width  W;
inline constexpr Height H;

NDArray< float, W > bla;

Clang reports the error as

error: implicit instantiation of undefined template 'NDArray<float, {{{0}}}>

while GCC provides full type information:

error: aggregate 'NDArray<float, Width{DimensionImpl<Width>{Dimension{0}}}> bla' has incomplete type and cannot be defined

In my code, I'm using libTooling to obtain full type names of some C++ code, and I've noticed that in cases such as the above, Clang simply writes {{{0}}} instead of Width{DimensionImpl<Width>{Dimension{0}}}. This is problematic for me as my tool should behave differently if this {{{0}}} is actually Width than if it's actually Height.

I'm obtaining type information in libTooling using this snippet:

bool VisitVarDecl( clang::VarDecl * varDecl )
{
     auto canonicalType{ varDecl->getType().getCanonicalType().getAsString() };
     // make some decisions based on canonicalType
     return true;
}

However, clang appears to correctly resolve overloads taking NDArray< float, W > vs NDArray< float, H >, so this means that clang actually does have a distinction between those two types.

However, how to obtain the full name of the type?

Also, would you consider putting the full name of the type in the clang's error as well (the way GCC does)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions