I have a lambda which uses a const char * defined in function scope. The lambda is executed after the function returns.
void function() {
const char * UNLOCK_RESULT = "unlockResult";
..
..
TestStep::verifyDictionary(test, [UNLOCK_RESULT](TestStep::Dictionary& dict){
return 1 == dict[UNLOCK_RESULT].toInt();
});
...
}
If I look at the assembly that GCC generates, the actual char array holding the "unlockResult" is statically allocated. But I was wondering if this is guaranteed by the standard as in theory the const char * is of function scope. Is the capture of const char * undefined behaviour or is this allowed by the standard because of some exception around C++ handling of const char * strings.
I know I can change:
const char * UNLOCK_RESULT=""
to
constexpr const char * UNLOCK_RESULT=""
And then the discussion falls away because I don't even need to capture it, but I am curious about the const char * case.