xref: /aosp_15_r20/external/clang/test/SemaCXX/constexpr-duffs-device.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -std=c++1y -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li // expected-no-diagnostics
copy(const char * from,unsigned long count,char * to)4*67e74705SXin Li constexpr void copy(const char *from, unsigned long count, char *to) {
5*67e74705SXin Li         unsigned long n = (count + 7) / 8;
6*67e74705SXin Li         switch(count % 8) {
7*67e74705SXin Li         case 0: do {    *to++ = *from++;
8*67e74705SXin Li         case 7:         *to++ = *from++;
9*67e74705SXin Li         case 6:         *to++ = *from++;
10*67e74705SXin Li         case 5:         *to++ = *from++;
11*67e74705SXin Li         case 4:         *to++ = *from++;
12*67e74705SXin Li         case 3:         *to++ = *from++;
13*67e74705SXin Li         case 2:         *to++ = *from++;
14*67e74705SXin Li         case 1:         *to++ = *from++;
15*67e74705SXin Li                 } while(--n > 0);
16*67e74705SXin Li         }
17*67e74705SXin Li }
18*67e74705SXin Li 
19*67e74705SXin Li struct S {
20*67e74705SXin Li   char stuff[14];
SS21*67e74705SXin Li   constexpr S() : stuff{} {
22*67e74705SXin Li     copy("Hello, world!", 14, stuff);
23*67e74705SXin Li   }
24*67e74705SXin Li };
25*67e74705SXin Li 
streq(const char * a,const char * b)26*67e74705SXin Li constexpr bool streq(const char *a, const char *b) {
27*67e74705SXin Li   while (*a && *a == *b) ++a, ++b;
28*67e74705SXin Li   return *a == *b;
29*67e74705SXin Li }
30*67e74705SXin Li 
31*67e74705SXin Li static_assert(streq(S().stuff, "Hello, world!"), "should be same");
32*67e74705SXin Li static_assert(!streq(S().stuff, "Something else"), "should be different");
33