fork download
  1. #include <string>
  2. #include <array>
  3.  
  4. constexpr int foo(){
  5. std::string s = "FooBar";
  6. return s.find('B');
  7. }
  8.  
  9. int main() {
  10. std::array<int, foo()> arr;
  11. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'constexpr int foo()':
prog.cpp:5:18: error: variable 's' of non-literal type 'std::string {aka std::basic_string<char>}' in 'constexpr' function
  std::string s = "FooBar";
                  ^
In file included from /usr/include/c++/5/string:52:0,
                 from prog.cpp:1:
/usr/include/c++/5/bits/basic_string.h:2508:11: note: 'std::basic_string<char>' is not literal because:
     class basic_string
           ^
/usr/include/c++/5/bits/basic_string.h:2508:11: note:   'std::basic_string<char>' has a non-trivial destructor
prog.cpp: In function 'int main()':
prog.cpp:10:21: error: 'constexpr int foo()' called in a constant expression
  std::array<int, foo()> arr;
                     ^
prog.cpp:10:23: note: in template argument for type 'unsigned int' 
  std::array<int, foo()> arr;
                       ^
stdout
Standard output is empty