Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7873 Discussions

Compiler bug report: type of conditional operator involving rvalues

Rene_van_Oostrum
Beginner
183 Views

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:

[cpp]

#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);

}

[/cpp]

Expected output "move ctor"

Actual output: "copy ctor"

 

 

0 Kudos
2 Replies
JenniferJ
Moderator
183 Views

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

0 Kudos
JenniferJ
Moderator
183 Views

FYI.

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

Thanks,

Jennifer

0 Kudos
Reply