[cfe-dev] constexpr with builtin

Sebastian Redl sebastian.redl at getdesigned.at
Mon Sep 9 06:31:52 PDT 2013


On 09.09.2013, at 15:13, fil wrote:

> Apologies, this is the code block that does not compile:
> 
> inline constexpr uint8_t test(uint64_t value)
> {
> 	return __builtin_clzll(value);
> }

I believe the simple test that makes the code above not compile does not evaluate potential results of conditional expressions: only one branch needs to be a constant expression, and the test does not reason about "value == value" always taking one branch. So the version with the tautological test will compile by itself, but you'll never be able to use it in a constexpr context, versus the simple function above is recognized as not being constexpr.

Making built-in functions with simple arithmetic meanings constexpr is a different issue.

Sebastian



More information about the cfe-dev mailing list