New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AST] AutoType within AutoTypeLoc is missing deduced type. #42259
Comments
I investigated this a bit. What seems to be happening is:
[1] llvm-project/clang/lib/Sema/SemaDecl.cpp Line 11353 in a2976c4
[2]
|
Naively, I would think the solution ought to be that, in addition to calling VDecl->setType(), Sema::DeduceVariableDeclarationType() should also call VDecl->setTypeSourceInfo(). However, I don't at this stage understand how these types (Type / TypeLoc / TypeSourceInfo) interact well enough to know how to construct a TypeSourceInfo in that place. |
I heard that Ilya Biryukov and Richard Smith had a conversation about this bug, and it wasn't totally trivial. |
A couple of issues:
So, I think we could change our model so that we store the deduced type in the TypeSourceInfo of a variable. It would require some contortions in deserialization, and perhaps elsewhere. But I don't think we want to change our model for functions, where it's important that we preserve the declared type. So far, the consistency argument (the TypeSourceInfo should always represent the declared type) has won out over the convenience-for-tooling argument, especially given that tooling will need to deal with the deduced-type-is-not-in-the-TSI case anyway to properly handle functions with deduced return types. But perhaps someone can come up with a smart design that gives us the best of both worlds (perhaps we could represent the auto type in the TSI as a type that is canonically an undeduced auto but that tracks the deduced type via some type sugar?) |
Note, it's RecursiveASTVisitor that ignores the type and visits the TSI in the case where we have a TSI. Would it be reasonable to change the behaviour of RecursiveASTVisitor here? The actual tooling use cases (at least, the ones we've come across in clangd that I'm aware of) should "just work" if RAV visited the deduced type. |
Extended Description
the program
auto x = 4;
has an AST that looks like:VarDecl type=T1
T1 is correctly an auto type that wraps int.
However T2 is undeduced: it's ASTContext::getAutoDeductType().
This irregularity makes it harder/slower to write tools that (e.g.) care what an
auto
under the cursor expands to.The text was updated successfully, but these errors were encountered: