Skip to content

Commit

Permalink
Merge pull request #75202 from swiftlang/gaborh/export-static-properties
Browse files Browse the repository at this point in the history
[cxx-interop] Export accessors of static properties to C++
  • Loading branch information
Xazax-hun authored Jul 15, 2024
2 parents 08b4f3a + fe1a4b5 commit 01bd2b4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/PrintAsClang/DeclAndTypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ class DeclAndTypePrinter::Implementation

if (outputLang == OutputLanguageMode::Cxx) {
// FIXME: Support operators.
if (AFD->isOperator() || (AFD->isStatic() && AFD->isImplicit()))
if (AFD->isOperator() || (AFD->isStatic() && AFD->isImplicit() && !isa<AccessorDecl>(AFD)))
return;

auto *typeDeclContext = dyn_cast<NominalTypeDecl>(AFD->getParent());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend %S/swift-class-static-variables.swift -typecheck -module-name Class -clang-header-expose-decls=all-public -emit-clang-header-path %t/class.h

// RUN: %target-interop-build-clangxx -c %s -I %t -o %t/swift-class-execution.o
// RUN: %target-interop-build-swift %S/swift-class-static-variables.swift -o %t/swift-class-execution -Xlinker %t/swift-class-execution.o -module-name Class -Xfrontend -entry-point-function-name -Xfrontend swiftMain

// RUN: %target-codesign %t/swift-class-execution
// RUN: %target-run %t/swift-class-execution

// REQUIRES: executable_test


#include "class.h"
#include <assert.h>
#include <cstdio>

using namespace Class;

int main() {
auto x = FileUtilities::getShared();
assert(x.getField() == 42);
}
13 changes: 13 additions & 0 deletions test/Interop/SwiftToCxx/class/swift-class-static-variables.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -typecheck -module-name Class -clang-header-expose-decls=all-public -emit-clang-header-path %t/class.h
// RUN: %FileCheck %s < %t/class.h

// RUN: %check-interop-cxx-header-in-clang(%t/class.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY)

public class FileUtilities {
public static let shared = FileUtilities()
public let field = 42;
}

// CHECK: SWIFT_INLINE_THUNK FileUtilities FileUtilities::getShared() {

0 comments on commit 01bd2b4

Please sign in to comment.