[Crossposted to both GCC and Clang dev lists]

Hi,

One issue facing library authors wanting to use C++11’s constexpr feature is that the same implementation must be provided for both the case of function invocation substitution and for execution at runtime. Due to the constraints on constexpr function definitions, this can force an implementation of a library function to be inefficient. To counteract this, I’d like to propose the addition of a builtin:

bool __builtin_constexpr_p()

This builtin would only be supported within constexpr function definitions. If the containing function is undergoing function invocation substitution, it returns true. Otherwise, it returns false. Hence we can implement library functions with a pattern like:

constexpr int constexpr_strncmp(const char *p, const char *q, size_t n) {

return !n ? 0 : *p != *q ? *p - *q : !*p ? 0 : constexpr_strncmp(p+1, q+1, n-1);

}

**attribute**((always_inline)) constexpr int my_strncmp(const char *p, const char *q, size_t n) {

return __builtin_constexpr_p() ? constexpr_strncmp(p, q, n) : strncmp(p, q, n);

}

Does this seem reasonable?

Thanks!

Richard