[clang] [clang] Fix crash in concept deprecation (PR #98622)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 17 11:17:41 PDT 2024


================
@@ -7416,10 +7416,11 @@ NamedDecl *Sema::ActOnVariableDeclarator(
     tryToFixVariablyModifiedVarType(TInfo, R, D.getIdentifierLoc(),
                                     /*DiagID=*/0);
 
-  if (const AutoType *AutoT = R->getAs<AutoType>())
-    CheckConstrainedAuto(
-        AutoT,
-        TInfo->getTypeLoc().getContainedAutoTypeLoc().getConceptNameLoc());
+  if (const AutoType *AutoT = R->getAs<AutoType>()) {
+    AutoTypeLoc Loc = TInfo->getTypeLoc().getContainedAutoTypeLoc();
----------------
mizvekov wrote:

But here we are not just asking for the location of constrained auto.

A TypeLoc is not just a SourceLocation, it's a QualType *with* source locations.

The reason you are starting with a TypeLoc is that you are also interested in the source location.

This is a bit confusing because in a lot of places we pass both a QualType and a TypeLoc, which is mostly redundant. That might induce folks into thinking that a TypeLoc is just source locations on the side, which is not true.

But presently, they are not always redundant though. There are some cases we store both separately, and apply some transformations, like type deduction, only to the QualType, and leave the TypeLoc alone.
I think this is not ideal though, and seems to be mostly due to tech debt.

As an aside, if all you need to do is mark the concepts as used, you might as well do that earlier when the AutoType is formed, for example around the calls to `ASTContext::getAutoType` in `SemaType.cpp` / `ConvertDeclSpecToType`.


https://github.com/llvm/llvm-project/pull/98622


More information about the cfe-commits mailing list