[cxx-interop] noexcept specifier before function attributes (#74780)

In #74516 the `SWIFT_NOEXCEPT` specifier is added to the imported Swift
functions in C++ mode, but it is added after the function attributes. It seems
that the tests only do `-fsyntax-only`, which seems not to catch an error like
"expected function body after function declarator" when the header is
used without that flag.

Flip the attributes and the specifier around in the printer, and flip
them in all the tests.

The tests were using `%check-in-clang`, but it only checks importing as
an objective-c-header. Add a parallel `%check-in-clang-cxx` to test also
in C++. It uses C++17 because of some details in the imported headers and
disables a warning about variadic macros that was promoted to an error
and was blocking passing the tests. The clang-importer-sdk gets the
minimal set of files to compile the two modified tests as C++. The files
are mostly empty, except `cstddef` that imports the equivalent C header.
Some modifications were needed in `ctypes.h` because the header was
using features only available in C and not C++.
This commit is contained in:
Daniel Rodríguez Troitiño
2024-06-27 22:49:03 -07:00
committed by GitHub
parent b1fc313f22
commit 00e866ae53
11 changed files with 31 additions and 8 deletions

View File

@@ -0,0 +1,6 @@
#ifndef _LIBCPP_CSTDDEF
#define _LIBCPP_CSTDDEF
#include <stddef.h>
#endif

View File

@@ -242,7 +242,10 @@ typedef OpaqueTypedefForFP2 (*FunctionPointerReturningOpaqueTypedef2)(void);
size_t returns_size_t();
// This will probably never be serializable.
#if !defined(__cplusplus)
// C++ error: unnamed struct cannot be defined in the result type of a function
typedef struct { int x; int y; } *(*UnserializableFunctionPointer)(void);
#endif
//===---
// Unions
@@ -308,7 +311,10 @@ typedef struct ModRM {
// Arrays
//===---
void useArray(char x[4], char y[], char z[][8]);
#if !defined(__cplusplus)
// error: static array size is a C99 feature, not permitted in C++
void staticBoundsArray(const char x[static 4]);
#endif
void useBigArray(char max_size[4096], char max_size_plus_one[4097]);
void useBigArray2d(char max_size[][4096], char max_size_plus_one[][4097]);