[cfe-dev] Compile-time ternary operator
Anton Bachin
antonbachin at yahoo.com
Fri Jan 18 08:29:58 PST 2013
Hello,
I am making use of the ternary operator (?:) in a compile-time computation. An illustrative example:
constexpr int array[] = {1};
constexpr int value = true ? array[0] : array[-1];
int main()
{
return 0;
}
In the actual program, the condition determines whether it is safe to perform the access in the false-case.
Clang fails to compile this program, complaining about the out-of-bounds access in the false-case. This is the case with clang++ 3.1 on BSD and OS X.
GCC 4.7 compiles the program just fine.
Is this a bug or the intent? If it's a bug, has it been fixed in 3.2?
Thank you,
Anton
More information about the cfe-dev
mailing list