PR c++/86728 - C variadic generic lambda.
[official-gcc.git] / gcc / testsuite / g++.dg / ubsan / vptr-4.C
blob1c037d047dd1c19045f9a445c4ada9500dd86d43
1 // Verify that -fsanitize=vptr downcast instrumentation works properly
2 // inside of constexpr.
3 // { dg-do compile }
4 // { dg-options "-std=c++11 -fsanitize=vptr" }
6 struct S {
7   constexpr S() : a(0) {}
8   int a;
9   int f() { return 0; }
10   virtual int v() { return 0; }
13 struct T : S {
14   constexpr T() : b(0) {}
15   int b;
16   int g() { return 0; }
17   virtual int v() { return 1; }
18   constexpr const T *foo() { return (const T *) reinterpret_cast<const S *> (this); }
21 constexpr T t;
22 constexpr const T *p = t.foo ();
24 template <typename U>
25 struct V {
26   constexpr V() : a(0) {}
27   int a;
28   int f() { return 0; }
29   virtual int v() { return 0; }
32 template <typename U>
33 struct W : V<U> {
34   constexpr W() : b(0) {}
35   int b;
36   int g() { return 0; }
37   virtual int v() { return 1; }
38   constexpr const W<U> *foo() { return (const W<U> *) reinterpret_cast<const V<U> *> (this); }
41 constexpr W<int> w;
42 constexpr const W<int> *s = w.foo ();
44 template <typename U>
45 int foo (void)
47   static constexpr T t;
48   static constexpr const T *p = t.foo ();
49   static constexpr W<U> w;
50   static constexpr const W<U> *s = w.foo ();
51   return t.b + w.b;
54 int x = foo <char> ();