@@ -390,6 +390,80 @@ constexpr typename std::remove_reference<T>::type&& move(T &&t) noexcept {
390
390
}
391
391
// / The std::move declaration above gets translated to a builtin function.
392
392
namespace Move {
393
+ #if __cplusplus >= 202002L
394
+ consteval int f_eval () { // expected-note 12{{declared here}} \
395
+ // ref-note 12{{declared here}}
396
+ return 0 ;
397
+ }
398
+
399
+ // / From test/SemaCXX/cxx2a-consteval.
400
+ struct Copy {
401
+ int (*ptr)();
402
+ constexpr Copy (int (*p)() = nullptr) : ptr(p) {}
403
+ consteval Copy (const Copy&) = default;
404
+ };
405
+
406
+ constexpr const Copy &to_lvalue_ref (const Copy &&a) {
407
+ return a;
408
+ }
409
+
410
+ void test () {
411
+ constexpr const Copy C;
412
+ // there is no the copy constructor call when its argument is a prvalue because of garanteed copy elision.
413
+ // so we need to test with both prvalue and xvalues.
414
+ { Copy c (C); }
415
+ { Copy c ((Copy (&f_eval))); } // expected-error {{cannot take address of consteval}} \
416
+ // ref-error {{cannot take address of consteval}}
417
+ { Copy c (std::move (C)); }
418
+ { Copy c (std::move (Copy (&f_eval))); } // expected-error {{is not a constant expression}} \
419
+ // expected-note {{to a consteval}} \
420
+ // ref-error {{is not a constant expression}} \
421
+ // ref-note {{to a consteval}}
422
+ { Copy c (to_lvalue_ref ((Copy (&f_eval)))); } // expected-error {{is not a constant expression}} \
423
+ // expected-note {{to a consteval}} \
424
+ // ref-error {{is not a constant expression}} \
425
+ // ref-note {{to a consteval}}
426
+ { Copy c (to_lvalue_ref (std::move (C))); }
427
+ { Copy c (to_lvalue_ref (std::move (Copy (&f_eval)))); } // expected-error {{is not a constant expression}} \
428
+ // expected-note {{to a consteval}} \
429
+ // ref-error {{is not a constant expression}} \
430
+ // ref-note {{to a consteval}}
431
+ { Copy c = Copy (C); }
432
+ { Copy c = Copy (Copy (&f_eval)); } // expected-error {{cannot take address of consteval}} \
433
+ // ref-error {{cannot take address of consteval}}
434
+ { Copy c = Copy (std::move (C)); }
435
+ { Copy c = Copy (std::move (Copy (&f_eval))); } // expected-error {{is not a constant expression}} \
436
+ // expected-note {{to a consteval}} \
437
+ // ref-error {{is not a constant expression}} \
438
+ // ref-note {{to a consteval}}
439
+ { Copy c = Copy (to_lvalue_ref (Copy (&f_eval))); } // expected-error {{is not a constant expression}} \
440
+ // expected-note {{to a consteval}} \
441
+ // ref-error {{is not a constant expression}} \
442
+ // ref-note {{to a consteval}}
443
+ { Copy c = Copy (to_lvalue_ref (std::move (C))); }
444
+ { Copy c = Copy (to_lvalue_ref (std::move (Copy (&f_eval)))); } // expected-error {{is not a constant expression}} \
445
+ // expected-note {{to a consteval}} \
446
+ // ref-error {{is not a constant expression}} \
447
+ // ref-note {{to a consteval}}
448
+ { Copy c; c = Copy (C); }
449
+ { Copy c; c = Copy (Copy (&f_eval)); } // expected-error {{cannot take address of consteval}} \
450
+ // ref-error {{cannot take address of consteval}}
451
+ { Copy c; c = Copy (std::move (C)); }
452
+ { Copy c; c = Copy (std::move (Copy (&f_eval))); } // expected-error {{is not a constant expression}} \
453
+ // expected-note {{to a consteval}} \
454
+ // ref-error {{is not a constant expression}} \
455
+ // ref-note {{to a consteval}}
456
+ { Copy c; c = Copy (to_lvalue_ref (Copy (&f_eval))); } // expected-error {{is not a constant expression}} \
457
+ // expected-note {{to a consteval}} \
458
+ // ref-error {{is not a constant expression}} \
459
+ // ref-note {{to a consteval}}
460
+ { Copy c; c = Copy (to_lvalue_ref (std::move (C))); }
461
+ { Copy c; c = Copy (to_lvalue_ref (std::move (Copy (&f_eval)))); } // expected-error {{is not a constant expression}} \
462
+ // expected-note {{to a consteval}} \
463
+ // ref-error {{is not a constant expression}} \
464
+ // ref-note {{to a consteval}}
465
+ }
466
+ #endif
393
467
constexpr int A = std::move(5 );
394
468
static_assert (A == 5 , " " );
395
469
}
0 commit comments