Take this simple example:
#include <iostream>
namespace foo {
constexpr int main(int argc, char* argv[]) {
}
}
int main(int argc, char* argv[])
{
return foo::main(argc, argv);
}
Depending on what the code is , clang will complain or not. If the code:
cout << "Hello!";
return 0;
clang complains:
error: constexpr never creates a constant expression [-Winvalid-constexpr]
constexpr int main(int argc, char* argv[]) {
note: the non-conference function operator <<> "cannot be used in constant expression
std::cout << "Hello!";
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../ include / C ++ / 4.8 / ostream: 530: 5: note: stated here
operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
Fairly enough, constexpr functions cannot contain any cout commands, as we know. But what happens if we do this?
for (int i = 0; i < argc; i++)
std::cout << argv[i];
clang allows this! OK, but it cannot be a constexpr function, even if it is marked as constexpr, try using it in the context of constexpr.
int arr[foo::main(argc, argv)];
! , clang? , clang, gcc :
error: constexpr 'constexpr int foo:: main (int, char **) ' return
, - , gcc .