6
6
#include < aws/crt/Variant.h>
7
7
#include < aws/testing/aws_test_harness.h>
8
8
9
+ #if defined(_WIN32)
10
+ # define AWS_VARIANTTEST_WINDOWS_API __declspec (dllexport)
11
+ #else
12
+ # define AWS_VARIANTTEST_WINDOWS_API
13
+ #endif
14
+
9
15
const char *s_variant_test_str = " This is a string, that should be long enough to avoid small string optimizations" ;
10
16
11
17
static int s_VariantBasicOperandsCompile (struct aws_allocator *allocator, void *ctx)
@@ -241,13 +247,6 @@ static int s_VariantWithMoveOnlyUnderlyingType(struct aws_allocator *allocator,
241
247
* The __declspec(dllexport) directive exports class member function on Windows platform. We enable it when
242
248
* building shared libraries. In the past, this directive caused msvc to generate special copy members for classes
243
249
* containing Crt::Variant with move-only underlying types, which led to compile-time errors. */
244
-
245
- #if defined(_WIN32)
246
- # define AWS_VARIANTTEST_WINDOWS_API __declspec (dllexport)
247
- #else
248
- # define AWS_VARIANTTEST_WINDOWS_API
249
- #endif
250
-
251
250
struct AWS_VARIANTTEST_WINDOWS_API MoveOnlyVariantTestResult
252
251
{
253
252
MoveOnlyVariant m_result;
@@ -283,13 +282,6 @@ static int s_VariantWithCopyOnlyUnderlyingType(struct aws_allocator *allocator,
283
282
* The __declspec(dllexport) directive exports class member function on Windows platform. We enable it when
284
283
* building shared libraries. In the past, this directive caused msvc to generate special copy members for classes
285
284
* containing Crt::Variant with copy-only underlying types, which led to compile-time errors. */
286
-
287
- #if defined(_WIN32)
288
- # define AWS_VARIANTTEST_WINDOWS_API __declspec (dllexport)
289
- #else
290
- # define AWS_VARIANTTEST_WINDOWS_API
291
- #endif
292
-
293
285
struct AWS_VARIANTTEST_WINDOWS_API CopyOnlyVariantTestResult
294
286
{
295
287
CopyOnlyVariant m_result;
@@ -300,25 +292,76 @@ static int s_VariantWithCopyOnlyUnderlyingType(struct aws_allocator *allocator,
300
292
301
293
AWS_TEST_CASE (VariantWithCopyOnlyUnderlyingType, s_VariantWithCopyOnlyUnderlyingType)
302
294
303
- static int s_VariantNoexceptConstructible(struct aws_allocator *allocator, void *ctx)
295
+ // Test Variant with underlying type without default constructor.
296
+ // If it compiles, it's considered success.
297
+ static int s_VariantWithNoDefaultConstructibleUnderlyingType(struct aws_allocator *allocator, void *ctx)
304
298
{
305
299
(void )ctx;
306
300
307
301
Aws::Crt::ApiHandle apiHandle (allocator);
308
302
309
- struct NothorwConstructibleTestType
303
+ struct NoDefaultConstructibleTestType
310
304
{
311
- NothorwConstructibleTestType () noexcept = default ;
305
+ explicit NoDefaultConstructibleTestType (int ) {}
306
+ NoDefaultConstructibleTestType () = delete ;
312
307
};
313
308
314
- using NothrowConstructibleVariant = Aws::Crt::Variant<NothorwConstructibleTestType >;
309
+ using NoDefaultConstructibleVariant = Aws::Crt::Variant<NoDefaultConstructibleTestType >;
315
310
311
+ /* Regression test.
312
+ * The __declspec(dllexport) directive exports class member function on Windows platform. We enable it when
313
+ * building shared libraries. In the past, this directive caused msvc to generate special copy members for classes
314
+ * containing Crt::Variant with copy-only underlying types, which led to compile-time errors. */
315
+ struct AWS_VARIANTTEST_WINDOWS_API NoDefaultConstructibleVariantTestResult
316
+ {
317
+ NoDefaultConstructibleVariant m_result;
318
+ };
319
+
320
+ NoDefaultConstructibleTestType testType (1 );
321
+ NoDefaultConstructibleVariant variant (testType);
322
+
323
+ return AWS_OP_SUCCESS;
324
+ }
325
+
326
+ AWS_TEST_CASE (VariantWithNoDefaultConstructibleUnderlyingType, s_VariantWithNoDefaultConstructibleUnderlyingType)
327
+
328
+ static int s_VariantNothrowConstructible(struct aws_allocator *allocator, void *ctx)
329
+ {
330
+ (void )ctx;
331
+
332
+ Aws::Crt::ApiHandle apiHandle (allocator);
333
+
334
+ struct NothrowConstructibleTestType
335
+ {
336
+ NothrowConstructibleTestType () noexcept = default ;
337
+ };
338
+ using NothrowConstructibleVariant = Aws::Crt::Variant<NothrowConstructibleTestType>;
316
339
ASSERT_INT_EQUALS (1 , std::is_nothrow_constructible<NothrowConstructibleVariant>::value);
317
340
318
341
return AWS_OP_SUCCESS;
319
342
}
320
343
321
- AWS_TEST_CASE (VariantNoexceptConstructible, s_VariantNoexceptConstructible)
344
+ AWS_TEST_CASE (VariantNothrowConstructible, s_VariantNothrowConstructible)
345
+
346
+ static int s_VariantThrowConstructible(struct aws_allocator *allocator, void *ctx)
347
+ {
348
+ (void )ctx;
349
+
350
+ Aws::Crt::ApiHandle apiHandle (allocator);
351
+
352
+ struct ThrowConstructibleTestType
353
+ {
354
+ // Must be user-defined to be non-nothrow.
355
+ ThrowConstructibleTestType () {}
356
+ };
357
+
358
+ using ThrowConstructibleVariant = Aws::Crt::Variant<ThrowConstructibleTestType>;
359
+ ASSERT_INT_EQUALS (0 , std::is_nothrow_constructible<ThrowConstructibleVariant>::value);
360
+
361
+ return AWS_OP_SUCCESS;
362
+ }
363
+
364
+ AWS_TEST_CASE (VariantThrowConstructible, s_VariantThrowConstructible)
322
365
323
366
struct TestStringOnlyVisitor
324
367
{
0 commit comments