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