The DependentNameType must have a non-null NSS. This property could be
violated during typo correction.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
clang/lib/Sema/SemaTemplate.cpp | ||
---|---|---|
4869 | two concerns here:
| |
clang/test/Parser/cxx-template-decl.cpp | ||
296 | If I understand right, AddObservationFn gets typo-corrected to AddObservation (the function). When we go to check whether it's valid, we look up the name and get the type instead (injected-class-name). so we figure "missing typename" but actually everything's just totally confused. The "best" solution I guess would be not allowing typo-correction to the shadowed name. So does requiring !Arg.getAsExpr().containsErrors() in the check for inserting typename work? |
clang/lib/Sema/SemaTemplate.cpp | ||
---|---|---|
4869 | yeah, the current fix is not quite ideal. thinking more about this, I think we should not recover if the arg is DeclRefExpr, reasons:
| |
clang/test/Parser/cxx-template-decl.cpp | ||
296 |
Yes, exactly. The inconsistence between different decls resolved by typo correction (function) and the name lookup (class) leads to the crash.
it might be possible, but I'm not sure this would fit the design of typo-correction, or make it worse
so, yeah it seems reasonable to fix the typo correction client side, to make it suggest a type decl (rather than a non-type decl) for this particular case. Maybe a better way to fix the issue:
either 1 or 2 can fix this particular crash case (1 will improve the diagnostic), but I think we need both -- as we can't guarantee there is no typo correction running into that code path.
unfortunately, this is not possible at the moment -- the error-bit isn't propagated from TypoExpr to the corrected Expr, this is because the transformation of TypoExpr -> Expr is not straightforward,
if we want to propagate the error-bit from typo-expr to the built DeclRefExpr, we need to carry the error-bit through the above code path somehow, which seems non-trivial. |
Yeah, I think you're right, and this small version of the patch seems good.
if the arg is a DeclRefExpr (no typo correction), we'll never into this branch - the lookup should find the responding ValueDecl, which is not a TypeDecl
I think this is true but I don't feel certain. @rsmith could think of an exception if anyone can. (Only important if the exception is common enough we really need to offer the typename recovery.
Agree that if we've already done typo correction then offering further recovery isn't necessary and in fact often does more harm than good.
clang/lib/Sema/SemaTemplate.cpp | ||
---|---|---|
4869 | Assertion message doesn't really say anything more than the assertion itself. (DependentScopeDeclRefExpr must be relative to some specified scope!) |
two concerns here: