fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int x;
  5.  
  6. constexpr int foo(bool b ){
  7. return b ? 123 : x;
  8. }
  9.  
  10. int bar[foo(true)]; // ok
  11.  
  12. //int baz[foo(false)]; // size of array 'baz' is not an integral constant-expression
  13. bool b;
  14. //int bbb[foo(b)]; //array bound is not an integer constant before
  15.  
  16. int main() {
  17. // your code goes here
  18. x = 42;
  19.  
  20. cout << foo(true) <<endl;
  21. cout << foo(false) <<endl;
  22.  
  23.  
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
123
42