xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/initialization-constexpr.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // Constexpr:
2*7c3d14c8STreehugger Robot // We need to check that a global variable initialized with a constexpr
3*7c3d14c8STreehugger Robot // constructor can be accessed during dynamic initialization (as a constexpr
4*7c3d14c8STreehugger Robot // constructor implies that it was initialized during constant initialization,
5*7c3d14c8STreehugger Robot // not dynamic initialization).
6*7c3d14c8STreehugger Robot 
7*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-constexpr-extra.cc --std=c++11 -o %t
8*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=check_initialization_order=true %run %t 2>&1
9*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-constexpr-extra.cc --std=c++11 -o %t
10*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=check_initialization_order=true %run %t 2>&1
11*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-constexpr-extra.cc --std=c++11 -o %t
12*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=check_initialization_order=true %run %t 2>&1
13*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O3 %s %p/Helpers/initialization-constexpr-extra.cc --std=c++11 -o %t
14*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=check_initialization_order=true %run %t 2>&1
15*7c3d14c8STreehugger Robot 
16*7c3d14c8STreehugger Robot class Integer {
17*7c3d14c8STreehugger Robot   private:
18*7c3d14c8STreehugger Robot   int value;
19*7c3d14c8STreehugger Robot 
20*7c3d14c8STreehugger Robot   public:
Integer(int x=0)21*7c3d14c8STreehugger Robot   constexpr Integer(int x = 0) : value(x) {}
getValue()22*7c3d14c8STreehugger Robot   int getValue() {return value;}
23*7c3d14c8STreehugger Robot };
24*7c3d14c8STreehugger Robot Integer coolestInteger(42);
getCoolestInteger()25*7c3d14c8STreehugger Robot int getCoolestInteger() { return coolestInteger.getValue(); }
26*7c3d14c8STreehugger Robot 
main()27*7c3d14c8STreehugger Robot int main() { return 0; }
28