Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions test/Interop/Cxx/class/Inputs/member-variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include <type_traits>
#include <optional>

#if defined(_MSC_VER)
#define NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
#else
#define NO_UNIQUE_ADDRESS [[no_unique_address]]
#endif

class MyClass {
public:
const int const_member = 23;
Expand All @@ -17,19 +23,19 @@ struct Empty {

struct HasZeroSizedField {
int a;
[[no_unique_address]] Empty b;
NO_UNIQUE_ADDRESS Empty b;
short c;
[[no_unique_address]] Empty d;
NO_UNIQUE_ADDRESS Empty d;
int* e;
[[no_unique_address]] Empty f;
NO_UNIQUE_ADDRESS Empty f;

int get_a() const { return a; }
short get_c() const { return c; }
void set_c(short c) { this->c = c; }
};

struct ReuseOptionalFieldPadding {
[[no_unique_address]] std::optional<int> a = {2};
NO_UNIQUE_ADDRESS std::optional<int> a = {2};
char c;
char get_c() const { return c; }
void set_c(char c) { this->c = c; }
Expand All @@ -40,7 +46,7 @@ struct ReuseOptionalFieldPadding {
using OptInt = std::optional<int>;

struct ReuseOptionalFieldPaddingWithTypedef {
[[no_unique_address]] OptInt a;
NO_UNIQUE_ADDRESS OptInt a;
char c;
char get_c() const { return c; }
void set_c(char c) { this->c = c; }
Expand All @@ -59,7 +65,7 @@ struct NonStandardLayoutClass {
static_assert(std::is_standard_layout_v<NonStandardLayoutClass<int>> == false);

struct ReuseNonStandardLayoutFieldPadding {
[[no_unique_address]] NonStandardLayoutClass<int> a;
NO_UNIQUE_ADDRESS NonStandardLayoutClass<int> a;
char c;
char get_c() const { return c; }
void set_c(char c) { this->c = c; }
Expand All @@ -69,7 +75,7 @@ struct ReuseNonStandardLayoutFieldPadding {

template<typename T>
struct ReuseDependentFieldPadding {
[[no_unique_address]] struct { private: T x; public: char pad_me; } a;
NO_UNIQUE_ADDRESS struct { private: T x; public: char pad_me; } a;
char c;
char get_c() const { return c; }
void set_c(char c) { this->c = c; }
Expand All @@ -94,7 +100,7 @@ struct EmptyNotImported {

struct LastFieldNoUniqueAddress {
char c;
[[no_unique_address]] EmptyNotImported p0;
NO_UNIQUE_ADDRESS EmptyNotImported p0;

LastFieldNoUniqueAddress(const LastFieldNoUniqueAddress &other) {}
LastFieldNoUniqueAddress(LastFieldNoUniqueAddress &&other) {}
Expand Down
10 changes: 9 additions & 1 deletion test/Interop/Cxx/class/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ module MemoryLayout {
requires cplusplus
}

module MemberVariables {
// This header is shared between 3 test cases. It's built with -verify in
// test/Interop/Cxx/class/member-variables-typechecker.swift, which is defeated
// if the test just picks up a cached module. We could set the module cache path
// explicitly, but that would rebuild CxxStdlib which is really slow.
module MemberVariablesNoDiagnostics {
header "member-variables.h"
requires cplusplus
}
module MemberVariablesDiagnostics {
header "member-variables.h"
requires cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-ide-test -print-module -module-to-print=MemberVariables -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
// RUN: %target-swift-ide-test -print-module -module-to-print=MemberVariablesNoDiagnostics -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s

// CHECK: struct MyClass {
// CHECK-NEXT: init()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %target-typecheck-verify-swift -I %S/Inputs -enable-experimental-cxx-interop

import MemberVariables
import MemberVariablesDiagnostics

var s = MyClass()
s.const_member = 42 // expected-error {{cannot assign to property: 'const_member' setter is inaccessible}}
2 changes: 1 addition & 1 deletion test/Interop/Cxx/class/zero-sized-field.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// REQUIRES: executable_test

import StdlibUnittest
import MemberVariables
import MemberVariablesNoDiagnostics

var FieldsTestSuite = TestSuite("Generating code with zero sized fields")

Expand Down