Repository: apple/swift
File: lib/ClangImporter/SwiftifyDecl.cpp (C++)

Code before:
    return false; // Only C++ methods have implicit params
}

static size_t getNumParams(const clang::ObjCMethodDecl* D) {
    return D->param_size();
}
static size_t getNumParams(const clang::FunctionDecl* D) {
    return D->getNumParams();
}
} // namespace

template<typename T>
static bool swiftifyImpl(ClangImporter::Implementation &Self,
                         SwiftifyInfoFunctionPrinter &printer,
                         const AbstractFunctionDecl *MappedDecl,
                         const T *ClangDecl) {
  DLOG_SCOPE("Checking '" << *ClangDecl << "' for bounds and lifetime info\n");

  if (ClangDecl->hasAttrs())
    for (auto attr : ClangDecl->getAttrs())
      if (auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr))
        if (swiftAttr->getAttribute() == "no_safe_wrapper") {
          DLOG("skipping function with no_safe_wrapper\n");
          return false;
        }

  // FIXME: for private macro generated functions we do not serialize the
  // SILFunction's body anywhere triggering assertions.
  if (ClangDecl->getAccess() == clang::AS_protected ||
      ClangDecl->getAccess() == clang::AS_private)
    return false;

  if (ClangDecl->isImplicit()) {
    DLOG("implicit functions lack lifetime and bounds info\n");
    return false;
  }

  clang::ASTContext &clangASTContext = Self.getClangASTContext();

  const clang::Module *OwningModule = getOwningModule(ClangDecl);
  bool IsInBridgingHeader = MappedDecl->getModuleContext()->getName().str() == CLANG_HEADER_MODULE_NAME;
  ASSERT(OwningModule || IsInBridgingHeader);
  ForwardDeclaredConcreteTypeVisitor CheckForwardDecls(OwningModule);

  if (wouldBeIllegalInitializer(MappedDecl)) {
    DLOG("illegal initializer\n");
    return false;
  }

  // We only attach the macro if it will produce an overload. Any __counted_by
  // will produce an overload, since UnsafeBufferPointer is still an improvement

Review comment (suggestion):
nit: These should statements should probably have braces around them. IMO an if statement should use braces if the statement involves more than one expression, e.g., contains nested if statements etc.

```suggestion
  if (ClangDecl->hasAttrs()) {
    for (auto *attr : ClangDecl->getAttrs()) {
      if (auto *swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr);
          swiftAttr && swiftAttr->getAttribute() == "no_safe_wrapper") {
        DLOG("skipping function with no_safe_wrapper\n");
        return false;
      }
    }
  }

```

Code after:
    return false; // Only C++ methods have implicit params
}

static size_t getNumParams(const clang::ObjCMethodDecl* D) {
    return D->param_size();
}
static size_t getNumParams(const clang::FunctionDecl* D) {
    return D->getNumParams();
}
} // namespace

template<typename T>
static bool swiftifyImpl(ClangImporter::Implementation &Self,
                         SwiftifyInfoFunctionPrinter &printer,
                         const AbstractFunctionDecl *MappedDecl,
                         const T *ClangDecl) {
  DLOG_SCOPE("Checking '" << *ClangDecl << "' for bounds and lifetime info\n");

  if (ClangDecl->hasAttrs()) {
    for (auto *attr : ClangDecl->getAttrs()) {
      if (auto *swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr);
          swiftAttr && swiftAttr->getAttribute() == "no_safe_wrapper") {
        DLOG("skipping function with no_safe_wrapper\n");
        return false;
      }
    }
  }

  // FIXME: for private macro generated functions we do not serialize the
  // SILFunction's body anywhere triggering assertions.
  if (ClangDecl->getAccess() == clang::AS_protected ||
      ClangDecl->getAccess() == clang::AS_private)
    return false;

  if (ClangDecl->isImplicit()) {
    DLOG("implicit functions lack lifetime and bounds info\n");
    return false;
  }

  clang::ASTContext &clangASTContext = Self.getClangASTContext();

  const clang::Module *OwningModule = getOwningModule(ClangDecl);
  bool IsInBridgingHeader = MappedDecl->getModuleContext()->getName().str() == CLANG_HEADER_MODULE_NAME;
  ASSERT(OwningModule || IsInBridgingHeader);
  ForwardDeclaredConcreteTypeVisitor CheckForwardDecls(OwningModule);

  if (wouldBeIllegalInitializer(MappedDecl)) {
    DLOG("illegal initializer\n");
    return false;
  }