const-init-cxx1y.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // RUN: not %clang_cc1 -verify -triple x86_64-apple-darwin -emit-llvm -o - %s -std=c++1y | FileCheck %s
  2. struct A {
  3. constexpr A() : n(1) {}
  4. ~A();
  5. int n;
  6. };
  7. struct B : A {
  8. A a[3];
  9. constexpr B() {
  10. ++a[0].n;
  11. a[1].n += 2;
  12. a[2].n = n + a[1].n;
  13. }
  14. };
  15. B b;
  16. // CHECK: @b = global {{.*}} i32 1, {{.*}} { i32 2 }, {{.*}} { i32 3 }, {{.*}} { i32 4 }
  17. // CHECK-NOT: _ZN1BC
  18. namespace ModifyStaticTemporary {
  19. struct A { int &&temporary; int x; };
  20. constexpr int f(int &r) { r *= 9; return r - 12; }
  21. A a = { 6, f(a.temporary) };
  22. // CHECK: @_ZGRN21ModifyStaticTemporary1aE = private global i32 54
  23. // CHECK: @_ZN21ModifyStaticTemporary1aE = global {{.*}} i32* @_ZGRN21ModifyStaticTemporary1aE, i32 42
  24. A b = { 7, ++b.temporary };
  25. // CHECK: @_ZGRN21ModifyStaticTemporary1bE = private global i32 8
  26. // CHECK: @_ZN21ModifyStaticTemporary1bE = global {{.*}} i32* @_ZGRN21ModifyStaticTemporary1bE, i32 8
  27. // Can't emit all of 'c' as a constant here, so emit the initial value of
  28. // 'c.temporary', not the value as modified by the partial evaluation within
  29. // the initialization of 'c.x'.
  30. A c = { 10, (++c.temporary, b.x) };
  31. // CHECK: @_ZGRN21ModifyStaticTemporary1cE = private global i32 10
  32. // CHECK: @_ZN21ModifyStaticTemporary1cE = global {{.*}} zeroinitializer
  33. }
  34. // CHECK: __cxa_atexit({{.*}} @_ZN1BD1Ev {{.*}} @b
  35. // CHECK: define
  36. // CHECK-NOT: @_ZGRN21ModifyStaticTemporary1cE
  37. // CHECK: store {{.*}} @_ZGRN21ModifyStaticTemporary1cE, {{.*}} @_ZN21ModifyStaticTemporary1cE
  38. // CHECK: add
  39. // CHECK: store
  40. // CHECK: load {{.*}} @_ZN21ModifyStaticTemporary1bE
  41. // CHECK: store {{.*}} @_ZN21ModifyStaticTemporary1cE