summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/init/addr-const1.C
blob: 3b4637a4144e59ff2ddf1571c62fe9aa9513a9ad (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
38
// { dg-do run }

// Copyright (C) 2003 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 19 Apr 2003 <nathan@codesourcery.com>

// PR 9881. address-constant-expression not static initialized

struct bar {
  double p;
}; // bar
    
bar v;
static bool error = false;

struct foo {
  static double *a;
  static double *b;
  static double storage;
};

struct baz {
  baz () {
    if (foo::a != &v.p)
      error = true;
    if (foo::b != &foo::storage)
      error = true;
  }
};

baz f; // Get constructor to run before any other non-static initializers

double *foo::a = &(((bar *)(&v))->p);
double *foo::b = &(((bar *)(&foo::storage))->p);
double foo::storage = 0.0;

int main() {
  return error;
}