Strange local variable cv::VideoCapture allocated

Hi

I am using clang-6 to compile this C++ code and I see a strange temporary variable allocated at expression address 0x7ff1131536e8.

If I change the ternary operator at line 483 to an if-else, the temporary is not allocated.

Thanks

Variables:

Hi Adrian,

This question would probably be better in cfe-dev since it's about
Clang and the C++ AST rather than anything LLVM, but I'll do my
best...

I am using clang-6 to compile this C++ code and I see a strange temporary variable allocated at expression address 0x7ff1131536e8.

There are several temporaries in that code, and that address
represents none of them (or all, if you prefer).

The easiest one to explain is from the most deeply nested at
0x7ff113153200. It's because the conditional operator is an
expression, which means it has to produce a value with a single,
well-specified type. In this case the LHS (read call) wants to be a
bool and the RHS wants to be a cv::VideoCapture.

According to C++ rules that bool can be implicitly converted to a
cv::VideoCapture via one of its constructors (which takes an int). So
cv::VideoCapture is chosen as the final type and Clang materializes
temporaries to produce a value with that type. That's probably not
what you want.

I'm afraid I don't know about the outer temporaries. Definitely one for cfe-dev.

Cheers.

Tim.

Got it. Thank you Tim. This is what I need. I will send future questions like this to cfe-dev.