1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -triple x86_64-linux-gnu %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -triple x86_64-linux-gnu %s -fexperimental-new-constant-interpreter
6 // expected-error@+1 {{must be initialized by a constant expression}}
7 constexpr int *k
= (int *) __builtin_assume_aligned(p
, 16, n
= 5);
9 constexpr void *l
= __builtin_assume_aligned(p
, 16);
11 // expected-error@+2 {{must be initialized by a constant expression}}
12 // expected-note@+1 {{cast from 'void *' is not allowed in a constant expression}}
13 constexpr int *c
= (int *) __builtin_assume_aligned(p
, 16);
15 // expected-error@+2 {{must be initialized by a constant expression}}
16 // expected-note@+1 {{alignment of the base pointee object (4 bytes) is less than the asserted 16 bytes}}
17 constexpr void *m
= __builtin_assume_aligned(&n
, 16);
19 // expected-error@+2 {{must be initialized by a constant expression}}
20 // expected-note@+1 {{offset of the aligned pointer from the base pointee object (-2 bytes) is not a multiple of the asserted 4 bytes}}
21 constexpr void *q1
= __builtin_assume_aligned(&n
, 4, 2);
22 // expected-error@+2 {{must be initialized by a constant expression}}
23 // expected-note@+1 {{offset of the aligned pointer from the base pointee object (2 bytes) is not a multiple of the asserted 4 bytes}}
24 constexpr void *q2
= __builtin_assume_aligned(&n
, 4, -2);
25 constexpr void *q3
= __builtin_assume_aligned(&n
, 4, 4);
26 constexpr void *q4
= __builtin_assume_aligned(&n
, 4, -4);
29 // expected-error@+2 {{must be initialized by a constant expression}}
30 // expected-note@+1 {{alignment of the base pointee object (1 byte) is less than the asserted 16 bytes}}
31 constexpr void *r1
= __builtin_assume_aligned(&ar1
[2], 16);
33 static char ar2
[6] __attribute__((aligned(32)));
34 // expected-error@+2 {{must be initialized by a constant expression}}
35 // expected-note@+1 {{offset of the aligned pointer from the base pointee object (2 bytes) is not a multiple of the asserted 16 bytes}}
36 constexpr void *r2
= __builtin_assume_aligned(&ar2
[2], 16);
37 constexpr void *r3
= __builtin_assume_aligned(&ar2
[2], 16, 2);
38 // expected-error@+2 {{must be initialized by a constant expression}}
39 // expected-note@+1 {{offset of the aligned pointer from the base pointee object (1 byte) is not a multiple of the asserted 16 bytes}}
40 constexpr void *r4
= __builtin_assume_aligned(&ar2
[2], 16, 1);
42 constexpr int* x
= __builtin_constant_p((int*)0xFF) ? (int*)0xFF : (int*)0xFF;
43 // expected-error@+2 {{must be initialized by a constant expression}}
44 // expected-note@+1 {{value of the aligned pointer (255) is not a multiple of the asserted 32 bytes}}
45 constexpr void *s1
= __builtin_assume_aligned(x
, 32);
46 // expected-error@+2 {{must be initialized by a constant expression}}
47 // expected-note@+1 {{value of the aligned pointer (250) is not a multiple of the asserted 32 bytes}}
48 constexpr void *s2
= __builtin_assume_aligned(x
, 32, 5);
49 constexpr void *s3
= __builtin_assume_aligned(x
, 32, -1);