Skip to content

Commit 01bd2b4

Browse files
authored
Merge pull request #75202 from swiftlang/gaborh/export-static-properties
[cxx-interop] Export accessors of static properties to C++
2 parents 08b4f3a + fe1a4b5 commit 01bd2b4

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ class DeclAndTypePrinter::Implementation
10911091

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

10971097
auto *typeDeclContext = dyn_cast<NominalTypeDecl>(AFD->getParent());
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// 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
4+
5+
// RUN: %target-interop-build-clangxx -c %s -I %t -o %t/swift-class-execution.o
6+
// 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
7+
8+
// RUN: %target-codesign %t/swift-class-execution
9+
// RUN: %target-run %t/swift-class-execution
10+
11+
// REQUIRES: executable_test
12+
13+
14+
#include "class.h"
15+
#include <assert.h>
16+
#include <cstdio>
17+
18+
using namespace Class;
19+
20+
int main() {
21+
auto x = FileUtilities::getShared();
22+
assert(x.getField() == 42);
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
// RUN: %empty-directory(%t)
3+
// RUN: %target-swift-frontend %s -typecheck -module-name Class -clang-header-expose-decls=all-public -emit-clang-header-path %t/class.h
4+
// RUN: %FileCheck %s < %t/class.h
5+
6+
// RUN: %check-interop-cxx-header-in-clang(%t/class.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY)
7+
8+
public class FileUtilities {
9+
public static let shared = FileUtilities()
10+
public let field = 42;
11+
}
12+
13+
// CHECK: SWIFT_INLINE_THUNK FileUtilities FileUtilities::getShared() {

0 commit comments

Comments
 (0)