@@ -413,3 +413,92 @@ namespace AddressOf {
413
413
constexpr _Complex float F = {3 , 4 };
414
414
static_assert (__builtin_addressof(F) == &F, " " );
415
415
}
416
+
417
+ namespace std {
418
+ template <typename T> struct remove_reference { using type = T; };
419
+ template <typename T> struct remove_reference <T &> { using type = T; };
420
+ template <typename T> struct remove_reference <T &&> { using type = T; };
421
+ template <typename T>
422
+ constexpr typename std::remove_reference<T>::type&& move(T &&t) noexcept {
423
+ return static_cast <typename std::remove_reference<T>::type &&>(t);
424
+ }
425
+ }
426
+ // / The std::move declaration above gets translated to a builtin function.
427
+ namespace Move {
428
+ #if __cplusplus >= 202002L
429
+ consteval int f_eval () { // expected-note 12{{declared here}} \
430
+ // ref-note 12{{declared here}}
431
+ return 0 ;
432
+ }
433
+
434
+ // / From test/SemaCXX/cxx2a-consteval.
435
+ struct Copy {
436
+ int (*ptr)();
437
+ constexpr Copy (int (*p)() = nullptr) : ptr(p) {}
438
+ consteval Copy (const Copy&) = default;
439
+ };
440
+
441
+ constexpr const Copy &to_lvalue_ref (const Copy &&a) {
442
+ return a;
443
+ }
444
+
445
+ void test () {
446
+ constexpr const Copy C;
447
+ // there is no the copy constructor call when its argument is a prvalue because of garanteed copy elision.
448
+ // so we need to test with both prvalue and xvalues.
449
+ { Copy c (C); }
450
+ { Copy c ((Copy (&f_eval))); } // expected-error {{cannot take address of consteval}} \
451
+ // ref-error {{cannot take address of consteval}}
452
+ { Copy c (std::move (C)); }
453
+ { Copy c (std::move (Copy (&f_eval))); } // expected-error {{is not a constant expression}} \
454
+ // expected-note {{to a consteval}} \
455
+ // ref-error {{is not a constant expression}} \
456
+ // ref-note {{to a consteval}}
457
+ { Copy c (to_lvalue_ref ((Copy (&f_eval)))); } // expected-error {{is not a constant expression}} \
458
+ // expected-note {{to a consteval}} \
459
+ // ref-error {{is not a constant expression}} \
460
+ // ref-note {{to a consteval}}
461
+ { Copy c (to_lvalue_ref (std::move (C))); }
462
+ { Copy c (to_lvalue_ref (std::move (Copy (&f_eval)))); } // expected-error {{is not a constant expression}} \
463
+ // expected-note {{to a consteval}} \
464
+ // ref-error {{is not a constant expression}} \
465
+ // ref-note {{to a consteval}}
466
+ { Copy c = Copy (C); }
467
+ { Copy c = Copy (Copy (&f_eval)); } // expected-error {{cannot take address of consteval}} \
468
+ // ref-error {{cannot take address of consteval}}
469
+ { Copy c = Copy (std::move (C)); }
470
+ { Copy c = Copy (std::move (Copy (&f_eval))); } // expected-error {{is not a constant expression}} \
471
+ // expected-note {{to a consteval}} \
472
+ // ref-error {{is not a constant expression}} \
473
+ // ref-note {{to a consteval}}
474
+ { Copy c = Copy (to_lvalue_ref (Copy (&f_eval))); } // expected-error {{is not a constant expression}} \
475
+ // expected-note {{to a consteval}} \
476
+ // ref-error {{is not a constant expression}} \
477
+ // ref-note {{to a consteval}}
478
+ { Copy c = Copy (to_lvalue_ref (std::move (C))); }
479
+ { Copy c = Copy (to_lvalue_ref (std::move (Copy (&f_eval)))); } // expected-error {{is not a constant expression}} \
480
+ // expected-note {{to a consteval}} \
481
+ // ref-error {{is not a constant expression}} \
482
+ // ref-note {{to a consteval}}
483
+ { Copy c; c = Copy (C); }
484
+ { Copy c; c = Copy (Copy (&f_eval)); } // expected-error {{cannot take address of consteval}} \
485
+ // ref-error {{cannot take address of consteval}}
486
+ { Copy c; c = Copy (std::move (C)); }
487
+ { Copy c; c = Copy (std::move (Copy (&f_eval))); } // expected-error {{is not a constant expression}} \
488
+ // expected-note {{to a consteval}} \
489
+ // ref-error {{is not a constant expression}} \
490
+ // ref-note {{to a consteval}}
491
+ { Copy c; c = Copy (to_lvalue_ref (Copy (&f_eval))); } // expected-error {{is not a constant expression}} \
492
+ // expected-note {{to a consteval}} \
493
+ // ref-error {{is not a constant expression}} \
494
+ // ref-note {{to a consteval}}
495
+ { Copy c; c = Copy (to_lvalue_ref (std::move (C))); }
496
+ { Copy c; c = Copy (to_lvalue_ref (std::move (Copy (&f_eval)))); } // expected-error {{is not a constant expression}} \
497
+ // expected-note {{to a consteval}} \
498
+ // ref-error {{is not a constant expression}} \
499
+ // ref-note {{to a consteval}}
500
+ }
501
+ #endif
502
+ constexpr int A = std::move(5 );
503
+ static_assert (A == 5 , " " );
504
+ }
0 commit comments