File: common_with.compile.pass.cpp

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-6~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,418,812 kB
  • sloc: cpp: 5,290,827; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,900; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,892; xml: 953; cs: 573; fortran: 539
file content (992 lines) | stat: -rw-r--r-- 32,080 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: libcpp-no-concepts

// template<class From, class To>
// concept common_with;

#include <concepts>

template <class T, class U>
constexpr bool CheckCommonWith() noexcept {
  constexpr bool result = std::common_with<T, U>;
  static_assert(std::common_with<T, U&> == result);
  static_assert(std::common_with<T, const U&> == result);
  static_assert(std::common_with<T, volatile U&> == result);
  static_assert(std::common_with<T, const volatile U&> == result);
  static_assert(std::common_with<T, U&&> == result);
  static_assert(std::common_with<T, const U&&> == result);
  static_assert(std::common_with<T, volatile U&&> == result);
  static_assert(std::common_with<T, const volatile U&&> == result);
  static_assert(std::common_with<T&, U&&> == result);
  static_assert(std::common_with<T&, const U&&> == result);
  static_assert(std::common_with<T&, volatile U&&> == result);
  static_assert(std::common_with<T&, const volatile U&&> == result);
  static_assert(std::common_with<const T&, U&&> == result);
  static_assert(std::common_with<const T&, const U&&> == result);
  static_assert(std::common_with<const T&, volatile U&&> == result);
  static_assert(std::common_with<const T&, const volatile U&&> == result);
  static_assert(std::common_with<volatile T&, U&&> == result);
  static_assert(std::common_with<volatile T&, const U&&> == result);
  static_assert(std::common_with<volatile T&, volatile U&&> == result);
  static_assert(std::common_with<volatile T&, const volatile U&&> == result);
  static_assert(std::common_with<const volatile T&, U&&> == result);
  static_assert(std::common_with<const volatile T&, const U&&> == result);
  static_assert(std::common_with<const volatile T&, volatile U&&> == result);
  static_assert(std::common_with<const volatile T&, const volatile U&&> ==
                result);
  return result;
}

template <class T, class U>
constexpr bool HasValidCommonType() noexcept {
  return requires { typename std::common_type_t<T, U>; }
  &&std::same_as<std::common_type_t<T, U>, std::common_type_t<U, T> >;
}

namespace BuiltinTypes {
// fundamental types
static_assert(std::common_with<void, void>);
static_assert(CheckCommonWith<int, int>());
static_assert(CheckCommonWith<int, long>());
static_assert(CheckCommonWith<int, unsigned char>());
#ifndef _LIBCPP_HAS_NO_INT128
static_assert(CheckCommonWith<int, __int128_t>());
#endif
static_assert(CheckCommonWith<int, double>());

// arrays
static_assert(CheckCommonWith<int[5], int[5]>());

// pointers
static_assert(CheckCommonWith<int*, int*>());
static_assert(CheckCommonWith<int*, const int*>());
static_assert(CheckCommonWith<int*, volatile int*>());
static_assert(CheckCommonWith<int*, const volatile int*>());
static_assert(CheckCommonWith<const int*, const int*>());
static_assert(CheckCommonWith<const int*, volatile int*>());
static_assert(CheckCommonWith<const int*, const volatile int*>());
static_assert(CheckCommonWith<volatile int*, const int*>());
static_assert(CheckCommonWith<volatile int*, volatile int*>());
static_assert(CheckCommonWith<volatile int*, const volatile int*>());
static_assert(CheckCommonWith<const volatile int*, const int*>());
static_assert(CheckCommonWith<const volatile int*, volatile int*>());
static_assert(CheckCommonWith<const volatile int*, const volatile int*>());

static_assert(CheckCommonWith<int (*)(), int (*)()>());
static_assert(CheckCommonWith<int (*)(), int (*)() noexcept>());
static_assert(CheckCommonWith<int (&)(), int (&)()>());
static_assert(CheckCommonWith<int (&)(), int (&)() noexcept>());
static_assert(CheckCommonWith<int (&)(), int (*)()>());
static_assert(CheckCommonWith<int (&)(), int (*)() noexcept>());

struct S {};
static_assert(CheckCommonWith<int S::*, int S::*>());
static_assert(CheckCommonWith<int S::*, const int S::*>());
static_assert(CheckCommonWith<int (S::*)(), int (S::*)()>());
static_assert(CheckCommonWith<int (S::*)(), int (S::*)() noexcept>());
static_assert(CheckCommonWith<int (S::*)() const, int (S::*)() const>());
static_assert(
    CheckCommonWith<int (S::*)() const, int (S::*)() const noexcept>());
static_assert(CheckCommonWith<int (S::*)() volatile, int (S::*)() volatile>());
static_assert(
    CheckCommonWith<int (S::*)() volatile, int (S::*)() volatile noexcept>());
static_assert(CheckCommonWith<int (S::*)() const volatile,
                              int (S::*)() const volatile>());
static_assert(CheckCommonWith<int (S::*)() const volatile,
                              int (S::*)() const volatile noexcept>());

// nonsense
static_assert(!CheckCommonWith<double, float*>());
static_assert(!CheckCommonWith<int, int[5]>());
static_assert(!CheckCommonWith<int*, long*>());
static_assert(!CheckCommonWith<int*, unsigned int*>());
static_assert(!CheckCommonWith<int (*)(), int (*)(int)>());
static_assert(!CheckCommonWith<int S::*, float S::*>());
static_assert(!CheckCommonWith<int (S::*)(), int (S::*)() const>());
static_assert(!CheckCommonWith<int (S::*)(), int (S::*)() volatile>());
static_assert(!CheckCommonWith<int (S::*)(), int (S::*)() const volatile>());
static_assert(!CheckCommonWith<int (S::*)() const, int (S::*)() volatile>());
static_assert(
    !CheckCommonWith<int (S::*)() const, int (S::*)() const volatile>());
static_assert(
    !CheckCommonWith<int (S::*)() volatile, int (S::*)() const volatile>());
} // namespace BuiltinTypes

namespace NoDefaultCommonType {
class T {};

static_assert(!CheckCommonWith<T, int>());
static_assert(!CheckCommonWith<int, T>());
static_assert(!CheckCommonWith<T, int[10]>());
static_assert(!CheckCommonWith<T[10], int>());
static_assert(!CheckCommonWith<T*, int*>());
static_assert(!CheckCommonWith<T*, const int*>());
static_assert(!CheckCommonWith<T*, volatile int*>());
static_assert(!CheckCommonWith<T*, const volatile int*>());
static_assert(!CheckCommonWith<const T*, int*>());
static_assert(!CheckCommonWith<volatile T*, int*>());
static_assert(!CheckCommonWith<const volatile T*, int*>());
static_assert(!CheckCommonWith<const T*, const int*>());
static_assert(!CheckCommonWith<const T*, volatile int*>());
static_assert(!CheckCommonWith<const T*, const volatile int*>());
static_assert(!CheckCommonWith<const T*, const int*>());
static_assert(!CheckCommonWith<volatile T*, const int*>());
static_assert(!CheckCommonWith<const volatile T*, const int*>());
static_assert(!CheckCommonWith<volatile T*, const int*>());
static_assert(!CheckCommonWith<volatile T*, volatile int*>());
static_assert(!CheckCommonWith<volatile T*, const volatile int*>());
static_assert(!CheckCommonWith<const T*, volatile int*>());
static_assert(!CheckCommonWith<volatile T*, volatile int*>());
static_assert(!CheckCommonWith<const volatile T*, volatile int*>());
static_assert(!CheckCommonWith<const volatile T*, const int*>());
static_assert(!CheckCommonWith<const volatile T*, volatile int*>());
static_assert(!CheckCommonWith<const volatile T*, const volatile int*>());
static_assert(!CheckCommonWith<const T*, const volatile int*>());
static_assert(!CheckCommonWith<volatile T*, const volatile int*>());
static_assert(!CheckCommonWith<const volatile T*, const volatile int*>());
static_assert(!CheckCommonWith<T&, int&>());
static_assert(!CheckCommonWith<T&, const int&>());
static_assert(!CheckCommonWith<T&, volatile int&>());
static_assert(!CheckCommonWith<T&, const volatile int&>());
static_assert(!CheckCommonWith<const T&, int&>());
static_assert(!CheckCommonWith<volatile T&, int&>());
static_assert(!CheckCommonWith<const volatile T&, int&>());
static_assert(!CheckCommonWith<const T&, const int&>());
static_assert(!CheckCommonWith<const T&, volatile int&>());
static_assert(!CheckCommonWith<const T&, const volatile int&>());
static_assert(!CheckCommonWith<const T&, const int&>());
static_assert(!CheckCommonWith<volatile T&, const int&>());
static_assert(!CheckCommonWith<const volatile T&, const int&>());
static_assert(!CheckCommonWith<volatile T&, const int&>());
static_assert(!CheckCommonWith<volatile T&, volatile int&>());
static_assert(!CheckCommonWith<volatile T&, const volatile int&>());
static_assert(!CheckCommonWith<const T&, volatile int&>());
static_assert(!CheckCommonWith<volatile T&, volatile int&>());
static_assert(!CheckCommonWith<const volatile T&, volatile int&>());
static_assert(!CheckCommonWith<const volatile T&, const int&>());
static_assert(!CheckCommonWith<const volatile T&, volatile int&>());
static_assert(!CheckCommonWith<const volatile T&, const volatile int&>());
static_assert(!CheckCommonWith<const T&, const volatile int&>());
static_assert(!CheckCommonWith<volatile T&, const volatile int&>());
static_assert(!CheckCommonWith<const volatile T&, const volatile int&>());
static_assert(!CheckCommonWith<T&, int&&>());
static_assert(!CheckCommonWith<T&, const int&&>());
static_assert(!CheckCommonWith<T&, volatile int&&>());
static_assert(!CheckCommonWith<T&, const volatile int&&>());
static_assert(!CheckCommonWith<const T&, int&&>());
static_assert(!CheckCommonWith<volatile T&, int&&>());
static_assert(!CheckCommonWith<const volatile T&, int&&>());
static_assert(!CheckCommonWith<const T&, const int&&>());
static_assert(!CheckCommonWith<const T&, volatile int&&>());
static_assert(!CheckCommonWith<const T&, const volatile int&&>());
static_assert(!CheckCommonWith<const T&, const int&&>());
static_assert(!CheckCommonWith<volatile T&, const int&&>());
static_assert(!CheckCommonWith<const volatile T&, const int&&>());
static_assert(!CheckCommonWith<volatile T&, const int&&>());
static_assert(!CheckCommonWith<volatile T&, volatile int&&>());
static_assert(!CheckCommonWith<volatile T&, const volatile int&&>());
static_assert(!CheckCommonWith<const T&, volatile int&&>());
static_assert(!CheckCommonWith<volatile T&, volatile int&&>());
static_assert(!CheckCommonWith<const volatile T&, volatile int&&>());
static_assert(!CheckCommonWith<const volatile T&, const int&&>());
static_assert(!CheckCommonWith<const volatile T&, volatile int&&>());
static_assert(!CheckCommonWith<const volatile T&, const volatile int&&>());
static_assert(!CheckCommonWith<const T&, const volatile int&&>());
static_assert(!CheckCommonWith<volatile T&, const volatile int&&>());
static_assert(!CheckCommonWith<const volatile T&, const volatile int&&>());
static_assert(!CheckCommonWith<T&&, int&>());
static_assert(!CheckCommonWith<T&&, const int&>());
static_assert(!CheckCommonWith<T&&, volatile int&>());
static_assert(!CheckCommonWith<T&&, const volatile int&>());
static_assert(!CheckCommonWith<const T&&, int&>());
static_assert(!CheckCommonWith<volatile T&&, int&>());
static_assert(!CheckCommonWith<const volatile T&&, int&>());
static_assert(!CheckCommonWith<const T&&, const int&>());
static_assert(!CheckCommonWith<const T&&, volatile int&>());
static_assert(!CheckCommonWith<const T&&, const volatile int&>());
static_assert(!CheckCommonWith<const T&&, const int&>());
static_assert(!CheckCommonWith<volatile T&&, const int&>());
static_assert(!CheckCommonWith<const volatile T&&, const int&>());
static_assert(!CheckCommonWith<volatile T&&, const int&>());
static_assert(!CheckCommonWith<volatile T&&, volatile int&>());
static_assert(!CheckCommonWith<volatile T&&, const volatile int&>());
static_assert(!CheckCommonWith<const T&&, volatile int&>());
static_assert(!CheckCommonWith<volatile T&&, volatile int&>());
static_assert(!CheckCommonWith<const volatile T&&, volatile int&>());
static_assert(!CheckCommonWith<const volatile T&&, const int&>());
static_assert(!CheckCommonWith<const volatile T&&, volatile int&>());
static_assert(!CheckCommonWith<const volatile T&&, const volatile int&>());
static_assert(!CheckCommonWith<const T&&, const volatile int&>());
static_assert(!CheckCommonWith<volatile T&&, const volatile int&>());
static_assert(!CheckCommonWith<const volatile T&&, const volatile int&>());
static_assert(!CheckCommonWith<T&&, int&&>());
static_assert(!CheckCommonWith<T&&, const int&&>());
static_assert(!CheckCommonWith<T&&, volatile int&&>());
static_assert(!CheckCommonWith<T&&, const volatile int&&>());
static_assert(!CheckCommonWith<const T&&, int&&>());
static_assert(!CheckCommonWith<volatile T&&, int&&>());
static_assert(!CheckCommonWith<const volatile T&&, int&&>());
static_assert(!CheckCommonWith<const T&&, const int&&>());
static_assert(!CheckCommonWith<const T&&, volatile int&&>());
static_assert(!CheckCommonWith<const T&&, const volatile int&&>());
static_assert(!CheckCommonWith<const T&&, const int&&>());
static_assert(!CheckCommonWith<volatile T&&, const int&&>());
static_assert(!CheckCommonWith<const volatile T&&, const int&&>());
static_assert(!CheckCommonWith<volatile T&&, const int&&>());
static_assert(!CheckCommonWith<volatile T&&, volatile int&&>());
static_assert(!CheckCommonWith<volatile T&&, const volatile int&&>());
static_assert(!CheckCommonWith<const T&&, volatile int&&>());
static_assert(!CheckCommonWith<volatile T&&, volatile int&&>());
static_assert(!CheckCommonWith<const volatile T&&, volatile int&&>());
static_assert(!CheckCommonWith<const volatile T&&, const int&&>());
static_assert(!CheckCommonWith<const volatile T&&, volatile int&&>());
static_assert(!CheckCommonWith<const volatile T&&, const volatile int&&>());
static_assert(!CheckCommonWith<const T&&, const volatile int&&>());
static_assert(!CheckCommonWith<volatile T&&, const volatile int&&>());
static_assert(!CheckCommonWith<const volatile T&&, const volatile int&&>());
} // namespace NoDefaultCommonType

struct BadBasicCommonType {
  // This test is ill-formed, NDR. If it ever blows up in our faces: that's a good thing.
  // In the meantime, the test should be included. If compiler support is added, then an include guard
  // should be placed so the test doesn't get deleted.
};

namespace std {
template <>
struct common_type<BadBasicCommonType, int> {
  using type = BadBasicCommonType;
};

template <>
struct common_type<int, BadBasicCommonType> {
  using type = int;
};
} // namespace std
static_assert(requires {
  typename std::common_type_t<BadBasicCommonType, int>;
});
static_assert(requires {
  typename std::common_type_t<int, BadBasicCommonType>;
});
static_assert(!std::same_as<std::common_type_t<BadBasicCommonType, int>,
                            std::common_type_t<int, BadBasicCommonType> >);
static_assert(!CheckCommonWith<BadBasicCommonType, int>());

struct DullCommonType {};
static_assert(!std::convertible_to<DullCommonType, int>);

struct T1 {};
static_assert(!std::convertible_to<DullCommonType, T1>);

namespace std {
template <>
struct common_type<T1, int> {
  using type = DullCommonType;
};

template <>
struct common_type<int, T1> {
  using type = DullCommonType;
};
} // namespace std
static_assert(HasValidCommonType<T1, int>());
static_assert(!CheckCommonWith<T1, int>());

struct CommonTypeImplicitlyConstructibleFromInt {
  explicit(false) CommonTypeImplicitlyConstructibleFromInt(int);
};
static_assert(requires {
  static_cast<CommonTypeImplicitlyConstructibleFromInt>(0);
});

struct T2 {};
static_assert(
    !std::convertible_to<CommonTypeImplicitlyConstructibleFromInt, T2>);

namespace std {
template <>
struct common_type<T2, int> {
  using type = CommonTypeImplicitlyConstructibleFromInt;
};

template <>
struct common_type<int, T2> {
  using type = CommonTypeImplicitlyConstructibleFromInt;
};
} // namespace std
static_assert(HasValidCommonType<T2, int>());
static_assert(!CheckCommonWith<T2, int>());

struct CommonTypeExplicitlyConstructibleFromInt {
  explicit CommonTypeExplicitlyConstructibleFromInt(int);
};
static_assert(requires {
  static_cast<CommonTypeExplicitlyConstructibleFromInt>(0);
});

struct T3 {};
static_assert(
    !std::convertible_to<CommonTypeExplicitlyConstructibleFromInt, T2>);

namespace std {
template <>
struct common_type<T3, int> {
  using type = CommonTypeExplicitlyConstructibleFromInt;
};

template <>
struct common_type<int, T3> {
  using type = CommonTypeExplicitlyConstructibleFromInt;
};
} // namespace std
static_assert(HasValidCommonType<T3, int>());
static_assert(!CheckCommonWith<T3, int>());

struct T4 {};
struct CommonTypeImplicitlyConstructibleFromT4 {
  explicit(false) CommonTypeImplicitlyConstructibleFromT4(T4);
};
static_assert(requires(T4 t4) {
  static_cast<CommonTypeImplicitlyConstructibleFromT4>(t4);
});

namespace std {
template <>
struct common_type<T4, int> {
  using type = CommonTypeImplicitlyConstructibleFromT4;
};

template <>
struct common_type<int, T4> {
  using type = CommonTypeImplicitlyConstructibleFromT4;
};
} // namespace std
static_assert(HasValidCommonType<T4, int>());
static_assert(!CheckCommonWith<T4, int>());

struct T5 {};
struct CommonTypeExplicitlyConstructibleFromT5 {
  explicit CommonTypeExplicitlyConstructibleFromT5(T5);
};
static_assert(requires(T5 t5) {
  static_cast<CommonTypeExplicitlyConstructibleFromT5>(t5);
});

namespace std {
template <>
struct common_type<T5, int> {
  using type = CommonTypeExplicitlyConstructibleFromT5;
};

template <>
struct common_type<int, T5> {
  using type = CommonTypeExplicitlyConstructibleFromT5;
};
} // namespace std
static_assert(HasValidCommonType<T5, int>());
static_assert(!CheckCommonWith<T5, int>());

struct T6 {};
struct CommonTypeNoCommonReference {
  CommonTypeNoCommonReference(T6);
  CommonTypeNoCommonReference(int);
};

namespace std {
template <>
struct common_type<T6, int> {
  using type = CommonTypeNoCommonReference;
};

template <>
struct common_type<int, T6> {
  using type = CommonTypeNoCommonReference;
};

template <>
struct common_type<T6&, int&> {};

template <>
struct common_type<int&, T6&> {};

template <>
struct common_type<T6&, const int&> {};

template <>
struct common_type<int&, const T6&> {};

template <>
struct common_type<T6&, volatile int&> {};

template <>
struct common_type<int&, volatile T6&> {};

template <>
struct common_type<T6&, const volatile int&> {};

template <>
struct common_type<int&, const volatile T6&> {};

template <>
struct common_type<const T6&, int&> {};

template <>
struct common_type<const int&, T6&> {};

template <>
struct common_type<const T6&, const int&> {};

template <>
struct common_type<const int&, const T6&> {};

template <>
struct common_type<const T6&, volatile int&> {};

template <>
struct common_type<const int&, volatile T6&> {};

template <>
struct common_type<const T6&, const volatile int&> {};

template <>
struct common_type<const int&, const volatile T6&> {};

template <>
struct common_type<volatile T6&, int&> {};

template <>
struct common_type<volatile int&, T6&> {};

template <>
struct common_type<volatile T6&, const int&> {};

template <>
struct common_type<volatile int&, const T6&> {};

template <>
struct common_type<volatile T6&, volatile int&> {};

template <>
struct common_type<volatile int&, volatile T6&> {};

template <>
struct common_type<volatile T6&, const volatile int&> {};

template <>
struct common_type<volatile int&, const volatile T6&> {};

template <>
struct common_type<const volatile T6&, int&> {};

template <>
struct common_type<const volatile int&, T6&> {};

template <>
struct common_type<const volatile T6&, const int&> {};

template <>
struct common_type<const volatile int&, const T6&> {};

template <>
struct common_type<const volatile T6&, volatile int&> {};

template <>
struct common_type<const volatile int&, volatile T6&> {};

template <>
struct common_type<const volatile T6&, const volatile int&> {};

template <>
struct common_type<const volatile int&, const volatile T6&> {};
} // namespace std

template <typename T, typename U>
constexpr bool HasCommonReference() noexcept {
  return requires { typename std::common_reference_t<T, U>; };
}

static_assert(HasValidCommonType<T6, int>());
static_assert(!HasCommonReference<const T6&, const int&>());
static_assert(!CheckCommonWith<T6, int>());

struct T7 {};
struct CommonTypeNoMetaCommonReference {
  CommonTypeNoMetaCommonReference(T7);
  CommonTypeNoMetaCommonReference(int);
};

namespace std {
template <>
struct common_type<T7, int> {
  using type = CommonTypeNoMetaCommonReference;
};

template <>
struct common_type<int, T7> {
  using type = CommonTypeNoMetaCommonReference;
};

template <>
struct common_type<T7&, int&> {
  using type = void;
};

template <>
struct common_type<int&, T7&> {
  using type = void;
};

template <>
struct common_type<T7&, const int&> {
  using type = void;
};

template <>
struct common_type<int&, const T7&> {
  using type = void;
};

template <>
struct common_type<T7&, volatile int&> {
  using type = void;
};

template <>
struct common_type<int&, volatile T7&> {
  using type = void;
};

template <>
struct common_type<T7&, const volatile int&> {
  using type = void;
};

template <>
struct common_type<int&, const volatile T7&> {
  using type = void;
};

template <>
struct common_type<const T7&, int&> {
  using type = void;
};

template <>
struct common_type<const int&, T7&> {
  using type = void;
};

template <>
struct common_type<const T7&, const int&> {
  using type = void;
};

template <>
struct common_type<const int&, const T7&> {
  using type = void;
};

template <>
struct common_type<const T7&, volatile int&> {
  using type = void;
};

template <>
struct common_type<const int&, volatile T7&> {
  using type = void;
};

template <>
struct common_type<const T7&, const volatile int&> {
  using type = void;
};

template <>
struct common_type<const int&, const volatile T7&> {
  using type = void;
};

template <>
struct common_type<volatile T7&, int&> {
  using type = void;
};

template <>
struct common_type<volatile int&, T7&> {
  using type = void;
};

template <>
struct common_type<volatile T7&, const int&> {
  using type = void;
};

template <>
struct common_type<volatile int&, const T7&> {
  using type = void;
};

template <>
struct common_type<volatile T7&, volatile int&> {
  using type = void;
};

template <>
struct common_type<volatile int&, volatile T7&> {
  using type = void;
};

template <>
struct common_type<volatile T7&, const volatile int&> {
  using type = void;
};

template <>
struct common_type<volatile int&, const volatile T7&> {
  using type = void;
};

template <>
struct common_type<const volatile T7&, int&> {
  using type = void;
};

template <>
struct common_type<const volatile int&, T7&> {
  using type = void;
};

template <>
struct common_type<const volatile T7&, const int&> {
  using type = void;
};

template <>
struct common_type<const volatile int&, const T7&> {
  using type = void;
};

template <>
struct common_type<const volatile T7&, volatile int&> {
  using type = void;
};

template <>
struct common_type<const volatile int&, volatile T7&> {
  using type = void;
};

template <>
struct common_type<const volatile T7&, const volatile int&> {
  using type = void;
};

template <>
struct common_type<const volatile int&, const volatile T7&> {
  using type = void;
};
} // namespace std
static_assert(HasValidCommonType<T7, int>());
static_assert(HasValidCommonType<const T7&, const int&>());
static_assert(HasCommonReference<const T7&, const int&>());
static_assert(
    !HasCommonReference<std::common_type_t<T7, int>&,
                        std::common_reference_t<const T7&, const int&> >());
static_assert(!CheckCommonWith<T7, int>());

struct CommonWithInt {
  operator int() const volatile;
};

namespace std {
template <>
struct common_type<CommonWithInt, int> {
  using type = int;
};

template <>
struct common_type<int, CommonWithInt> : common_type<CommonWithInt, int> {};

template <>
struct common_type<CommonWithInt&, int&> : common_type<CommonWithInt, int> {};

template <>
struct common_type<int&, CommonWithInt&> : common_type<CommonWithInt, int> {};

template <>
struct common_type<CommonWithInt&, const int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<int&, const CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<CommonWithInt&, volatile int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<int&, volatile CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<CommonWithInt&, const volatile int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<int&, const volatile CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const CommonWithInt&, int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const int&, CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const CommonWithInt&, const int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const int&, const CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const CommonWithInt&, volatile int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const int&, volatile CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const CommonWithInt&, const volatile int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const int&, const volatile CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<volatile CommonWithInt&, int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<volatile int&, CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<volatile CommonWithInt&, const int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<volatile int&, const CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<volatile CommonWithInt&, volatile int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<volatile int&, volatile CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<volatile CommonWithInt&, const volatile int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<volatile int&, const volatile CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const volatile CommonWithInt&, int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const volatile int&, CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const volatile CommonWithInt&, const int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const volatile int&, const CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const volatile CommonWithInt&, volatile int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const volatile int&, volatile CommonWithInt&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const volatile CommonWithInt&, const volatile int&>
    : common_type<CommonWithInt, int> {};

template <>
struct common_type<const volatile int&, const volatile CommonWithInt&>
    : common_type<CommonWithInt, int> {};
} // namespace std
static_assert(CheckCommonWith<CommonWithInt, int>());

struct CommonWithIntButRefLong {
  operator int() const volatile;
};

namespace std {
template <>
struct common_type<CommonWithIntButRefLong, int> {
  using type = int;
};

template <>
struct common_type<int, CommonWithIntButRefLong>
    : common_type<CommonWithIntButRefLong, int> {};

template <>
struct common_type<CommonWithIntButRefLong&, int&> {
  using type = long;
};

template <>
struct common_type<int&, CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<CommonWithIntButRefLong&, const int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<int&, const CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<CommonWithIntButRefLong&, volatile int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<int&, volatile CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<CommonWithIntButRefLong&, const volatile int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<int&, const volatile CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const CommonWithIntButRefLong&, int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const int&, CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const CommonWithIntButRefLong&, const int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const int&, const CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const CommonWithIntButRefLong&, volatile int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const int&, volatile CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const CommonWithIntButRefLong&, const volatile int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const int&, const volatile CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<volatile CommonWithIntButRefLong&, int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<volatile int&, CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<volatile CommonWithIntButRefLong&, const int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<volatile int&, const CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<volatile CommonWithIntButRefLong&, volatile int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<volatile int&, volatile CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<volatile CommonWithIntButRefLong&, const volatile int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<volatile int&, const volatile CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const volatile CommonWithIntButRefLong&, int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const volatile int&, CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const volatile CommonWithIntButRefLong&, const int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const volatile int&, const CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const volatile CommonWithIntButRefLong&, volatile int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const volatile int&, volatile CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const volatile CommonWithIntButRefLong&, const volatile int&>
    : common_type<CommonWithIntButRefLong&, int&> {};

template <>
struct common_type<const volatile int&, const volatile CommonWithIntButRefLong&>
    : common_type<CommonWithIntButRefLong&, int&> {};
} // namespace std
static_assert(CheckCommonWith<CommonWithIntButRefLong, int>());

int main(int, char**) { return 0; }