fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. constexpr std::string appendStringC(std::string s)
  5. {
  6. return s + " Constexpr func";
  7. }
  8.  
  9. std::string appendString(std::string s)
  10. {
  11. return s + " Regular func";
  12. }
  13.  
  14. int main()
  15. {
  16. std::string s1 = "String 1";
  17. std::string s2 = "String 2";
  18. std::cout << std::endl
  19. << appendStringC(s1) << std::endl
  20. << appendString(s2) << std::endl;
  21. return 0;
  22. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'constexpr std::string appendStringC(std::string)':
prog.cpp:4:23: error: invalid type for parameter 1 of constexpr function 'constexpr std::string appendStringC(std::string)'
 constexpr std::string appendStringC(std::string s)
                       ^
In file included from /usr/include/c++/5/string:52:0,
                 from /usr/include/c++/5/bits/locale_classes.h:40,
                 from /usr/include/c++/5/bits/ios_base.h:41,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 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:4:23: error: invalid return type 'std::string {aka std::basic_string<char>}' of constexpr function 'constexpr std::string appendStringC(std::string)'
 constexpr std::string appendStringC(std::string s)
                       ^
stdout
Standard output is empty