fork download
  1. #include <iostream>
  2.  
  3. struct A { int x; constexpr A(int i) noexcept : x{i} {} };
  4. struct B { A a; constexpr B(A a) noexcept : a{a} {} };
  5.  
  6. constexpr int foo() {
  7. A a{55};
  8. B b{a};
  9. return b.a.x;
  10. }
  11.  
  12. template<int N>
  13. void output()
  14. {
  15. std::cout << N << std::endl;
  16. }
  17.  
  18. int main() {
  19. // to be absolutely sure compile time eval'd,
  20. // pass as template arg
  21. constexpr auto b = foo();
  22. output<b>();
  23. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
55