ClangSharp icon indicating copy to clipboard operation
ClangSharp copied to clipboard

UnqualifiedDesugaredType does not return an unqualified type

Open nike4613 opened this issue 1 year ago • 2 comments

Example:

typedef int const* pcint;
pcint g();

Given the decl for g in variable gDecl, gDecl.ReturnType.CanonicalType.PointeeType.CanonicalType.UnqualifiedDesugaredType returns a BuiltinType that still represents const int.

Poking around in the sources suggests that the issue is in the fact that IsSugared returns false for qualified types. What I'd really like here is to be able to get a Type object for Handle.UnqualifiedType, which doesn't seem to exist at the moment.

nike4613 avatar Jul 16 '24 04:07 nike4613

IsSugared is just calling Ty->isSugared(): https://github.com/dotnet/ClangSharp/blob/f0501f7370c01064676f3e8100c4fe76dc3a7c62/sources/libClangSharp/ClangSharp.cpp#L5235-L5247

You'll note that UnqualifiedDesugaredType (https://source.clangsharp.dev/#ClangSharp/Types/Type.cs,2de64541a028759e) is itself just matching the behavior of Type::getUnqalifiedDesugaredType: https://clang.llvm.org/doxygen/Type_8cpp_source.html#l00605

In general ClangSharp tends to just mirror what Clang does and so you'll need to do whatever it is that Clang would expect you to do here.

tannergooding avatar Jul 17 '24 17:07 tannergooding

I think the core issue here is that ClangSharp does not have a QualType equivalent; instead, a Type represents a full QualType, but only mirrors the API of Clang's Type*. As I mentioned, I think this is resolvable by simply exposing UnqualifiedType on Type.

nike4613 avatar Jul 17 '24 22:07 nike4613