[PATCH] D36368: Fix type printing of array template args

John McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 29 01:17:43 PDT 2021


rjmccall added inline comments.


================
Comment at: clang/lib/AST/TemplateBase.cpp:109
+  }
+  return true;
+}
----------------
Hmm.  This seems unnecessarily complex.  Oh, and I think I suggested the comparison wrong for pointer depth.

Is there a case where the following doesn't work?

```
static unsigned getArrayDepth(QualType type) {
  unsigned count = 0;
  while (const auto *arrayType = type->getAsArrayTypeUnsafe()) {
    count++;
    type = arrayType->getElementType();
  }
  return count;
}

static bool needsAmpersandOnTemplateArg(QualType paramType, QualType argType,
                                        ASTContext &Ctx) {
  if (!paramType->isPointerType())
    return false;
  if (argType->isFunctionType())
    return true;
  if (argType->isArrayType())
    return getArrayDepth(argType) < getArrayDepth(paramType->getPointeeType());
  return false;
}
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D36368/new/

https://reviews.llvm.org/D36368



More information about the llvm-commits mailing list