mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
PrintAsClang is supposed to emit declarations in the same order regardless of the compiler’s internal state, but we have repeatedly found that our current criteria are inadequate, resulting in non-functionality-affecting changes to generated header content. Add a diagnostic that’s emitted when this happens soliciting a bug report. Since there *should* be no cases where the compiler fails to order declarations, this diagnostic is never actually emitted. Instead, we test this change by enabling `-verify` on nearly all PrintAsClang tests to make sure they are unaffected. This did demonstrate a missing criterion that only mattered in C++ mode: extensions that varied only in their generic signature were not sorted stably. Add a sort criterion for this.
66 lines
2.0 KiB
C++
66 lines
2.0 KiB
C++
// RUN: %empty-directory(%t)
|
|
|
|
// RUN: %target-swift-frontend %S/init-in-cxx.swift -module-name Init -clang-header-expose-decls=all-public -typecheck -verify -emit-clang-header-path %t/inits.h
|
|
|
|
// RUN: %target-interop-build-clangxx -c %s -I %t -o %t/swift-init-execution.o
|
|
// RUN: %target-interop-build-swift %S/init-in-cxx.swift -o %t/swift-init-execution -Xlinker %t/swift-init-execution.o -module-name Init -Xfrontend -entry-point-function-name -Xfrontend swiftMain
|
|
|
|
// RUN: %target-codesign %t/swift-init-execution
|
|
// RUN: %target-run %t/swift-init-execution | %FileCheck %s
|
|
|
|
// REQUIRES: executable_test
|
|
|
|
#include <assert.h>
|
|
#include "inits.h"
|
|
|
|
int main() {
|
|
using namespace Init;
|
|
|
|
auto smallStruct = FirstSmallStruct::init();
|
|
assert(smallStruct.getX() == 42);
|
|
auto smallStruct2 = FirstSmallStruct::init(24);
|
|
assert(smallStruct2.getX() == 24);
|
|
|
|
auto largeStruct = LargeStruct::init();
|
|
assert(largeStruct.getX1() == 0);
|
|
assert(largeStruct.getX2() == 0);
|
|
assert(largeStruct.getX3() == 0);
|
|
assert(largeStruct.getX4() == 0);
|
|
assert(largeStruct.getX5() == 0);
|
|
assert(largeStruct.getX6() == 0);
|
|
auto largeStruct2 = LargeStruct::init(99, smallStruct2);
|
|
assert(largeStruct2.getX1() == 99);
|
|
assert(largeStruct2.getX2() == 24);
|
|
assert(largeStruct2.getX3() == -99);
|
|
assert(largeStruct2.getX4() == 0);
|
|
assert(largeStruct2.getX5() == 11);
|
|
assert(largeStruct2.getX6() == 99 * 24);
|
|
|
|
{
|
|
StructWithRefCountStoredProp structWithRefCountStoredProp =
|
|
StructWithRefCountStoredProp::init();
|
|
(void)structWithRefCountStoredProp;
|
|
(void)StructWithRefCountStoredProp::init(22);
|
|
}
|
|
// CHECK: create RefCountedClass -1
|
|
// CHECK-NEXT: create RefCountedClass 22
|
|
// CHECK-NEXT: destroy RefCountedClass 22
|
|
// CHECK-NEXT: destroy RefCountedClass -1
|
|
|
|
{
|
|
auto x = FinalClass::init(FirstSmallStruct::init(78));
|
|
assert(x.getProp().getX() == 78);
|
|
}
|
|
|
|
{
|
|
auto x = DerivedClass::init(1, 2);
|
|
assert(x.getX() == 5);
|
|
}
|
|
|
|
{
|
|
auto x = DerivedClassTwo::init(1, 2);
|
|
assert(x.getX() == 3);
|
|
}
|
|
return 0;
|
|
}
|