Compiler bug report: type of conditional operator involving rvalues

Compiler bug report: type of conditional operator involving rvalues

Bug description: the type of an expression consisting of a ternary conditional operator Cond ? E1 : E2, where E1 and E2 have identical rvalue types, should be of the same rvalue type. However, it appears to be an lvalue.

Compiler version: "icpc version 14.0.1 (gcc version 4.7.0 compatibility)"

OS: "Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux"

Sample program:

#include <iostream>
 
class A {
public:
  A() {}
  A(const A& other) { std::cout << "copy ctor\n"; }
  A(A&& other)      { std::cout << "move ctor\n"; }
};
 
int main()
{
  A a1;
  A a2;
  A a3 = true ? std::move(a1) : std::move(a2);
}

Expected output "move ctor"

Actual output: "copy ctor"

 

 

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

It's only a problem on Linux. It works on Windows.

I'll file a bug to the compiler team for it. Thanks very much for reporting and the test case.

Jennifer

FYI.

This bug is fixed in 15.0 now. The latest 15.0 is update 2 that just released last week.

Thanks,

Jennifer

Leave a Comment

Please sign in to add a comment. Not a member? Join today