[clang] Detect a return value of Ref<T> & RefPtr<T> (PR #81580)

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 13 15:56:56 PST 2024


================
@@ -118,6 +118,26 @@ bool isCtorOfRefCounted(const clang::FunctionDecl *F) {
          || FunctionName == "Identifier";
 }
 
+bool isReturnValueRefCounted(const clang::FunctionDecl *F) {
+  assert(F);
+  auto *type = F->getReturnType().getTypePtrOrNull();
+  while (type) {
+    if (auto *elaboratedT = dyn_cast<ElaboratedType>(type)) {
+      type = elaboratedT->desugar().getTypePtrOrNull();
+      continue;
+    }
+    if (auto *specialT = dyn_cast<TemplateSpecializationType>(type)) {
----------------
haoNoQ wrote:

`.getTypePtrOrNull()` can be dropped here as well:
```suggestion
  QualType type = F->getReturnType();
  while (!type.isNull()) {
    if (auto *elaboratedT = type->getAs<ElaboratedType>()) {
      type = elaboratedT->desugar();
      continue;
    }
    if (auto *specialT = type->getAs<TemplateSpecializationType>()) {
```

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


More information about the cfe-commits mailing list