I'm wary of this code because of the warning that's being thrown, but I can't for the life of me see how it could be dangerous in this case unless the lambda expression does something funky with 'this'. Am I being paranoid or am I missing something? GCC didn't generate a warning for it on my linux box, but MSVC did. How exactly is 'this' captured in the lambda expression? Is the behavior implementation defined regarding how 'this' is used in the expression?
Is the behavior implementation defined regarding how 'this' is used in the expression?
You'll be in undefined behaviour territory if Timer's constructor calls that lambda. If you ensure that your Test object gets fully constructed before the Timer calls that function then you should be fine.