PR c++/86728 - C variadic generic lambda.
[official-gcc.git] / gcc / testsuite / g++.dg / ubsan / align-2.C
blob3e4f5485d02b2944408acfafcf57eda4823ff2d2
1 // Limit this to known non-strict alignment targets.
2 // { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } }
3 // { dg-options "-fsanitize=alignment -Wall -Wno-unused-variable -std=c++11" }
5 typedef const long int L;
6 struct S { long int l; char buf[1 + sizeof (int) + sizeof (L)]; } s;
7 struct T { char a; int b; long int c; } __attribute__((packed));
8 struct U { long int a; struct T b; } u;
10 int
11 main (void)
13   int *p = (int *) &s.buf[1];
14   L *l = (L *) &s.buf[1 + sizeof(int)];
16   int &r = *p;
17   auto &r2 = *p;
18   L &lr = *l;
20   // Try an rvalue reference.
21   auto &&r3 = *p;
23   // Don't evaluate the reference initializer twice.
24   int i = 1;
25   int *q = &i;
26   int &qr = ++*q;
27   if (i != 2)
28     __builtin_abort ();
30   int *s = &u.b.b;
31   L *t = &u.b.c;
32   int &r4 = *s;
33   auto &r5 = *s;
34   L &lr2 = *t;
35   auto &&r6 = *s;
38 // { dg-output "\.C:16:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" }
39 // { dg-output "\.C:17:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" }
40 // { dg-output "\.C:18:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'const L', which requires \[48] byte alignment.*" }
41 // { dg-output "\.C:21:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" }
42 // { dg-output "\.C:32:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" }
43 // { dg-output "\.C:33:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment.*" }
44 // { dg-output "\.C:34:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'const L', which requires \[48] byte alignment.*" }
45 // { dg-output "\.C:35:\[0-9]*:\[\^\n\r]*reference binding to misaligned address 0x\[0-9a-fA-F]* for type 'int', which requires 4 byte alignment" }