aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ext/constexpr-builtin1.C
blob: 2d0904b6e085ebdc1695b01c70bd4a56ae57d81b (plain)
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
// PR c++/80265
// { dg-do compile { target c++14 } }

constexpr bool compare() {
  char s1[] = "foo";
  char s2[] = "fxo";
  if (!__builtin_memcmp(s1, s2, 3))
    return false;
  s2[1] = 'o';
  if (__builtin_memcmp(s1, s2, 3))
    return false;
  if (__builtin_strcmp(s1, s2))
    return false;
  return true;
}

constexpr bool length() {
  char s[] = "foo";
  if (__builtin_strlen(s) != 3)
    return false;
  return true;
}

constexpr bool find() {
  char s[] = "foo";
  if (__builtin_memchr(s, 'f', 3) != s)
    return false;
  if (__builtin_strchr(s, 'o') != s+1)
    return false;
  if (__builtin_strstr(s, "oo") != s+1)
    return false;
  return true;
}

static_assert( compare(), "" );
static_assert( length(), "" );
static_assert( find(), "" );