[llvm-dev] Strange local variable cv::VideoCapture allocated

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Sun Jun 9 02:02:34 PDT 2019

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

On Sun, 9 Jun 2019 at 03:47, Adrian Tong via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> 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.



More information about the llvm-dev mailing list