Why references can't be used with compile time functions?
问题 I have two snippets. The first snippet: #include <string> template <typename T> constexpr bool foo(T&&) { return false; } int main() { std::string a; if constexpr (foo(a)) { } } The second snippet: #include <string> template <typename T> constexpr bool foo(T&&) { return false; } int main() { std::string a; std::string& x = a; if constexpr (foo(x)) { } } The first one compiles, but the second one does not compile (error message: error: the value of ‘x’ is not usable in a constant expression .