If operator =
is declared as default as shown below, the intel c++ compiler will give you an error message when compiling, but since it can be compiled without any problems with gcc or clang, is there not enough options for compiling?
error message
icpc-std=c++17sample.cpp
ld:/tmp/icpczIU0ix.o: (.rodata._ZTV6Entity[_ZTV6Entity]+0x10)— undefined reference to `Entity:: operator=(Entity const&)'
source code
#include<iostream>
classEntity {
public:
Entity() = default;
virtualEntity&operator=(Entity const&) = default;
public:
int index;
};
Entity e1 = Entity();
int main() {
std::cout<<e1.index;
return(0);
}
environment
Intel Compiler:icpc(ICCC) 19.0.5.281 20190815
OS:Archlinux
add
I reported it to an Intel forum and it was accepted as a bug.
https://software.intel.com/en-us/forums/intel-c-compiler/topic/837004
In P0135R1Guaranteed copyelion
Tx=T(T(T(T(T/));)
Entity e1=Entity();
Of course
Entity e1;
is treated as .According to C++17 Features Supported by Intel® C++ Compiler, the P0135R1 is already supported in Version 19.0.1, so the question may be a compiler bug.
Sayuri, as you said, there is a suspected bug on the Intel C++ Compiler side.
On the other hand, Intel C++ Compiler(icc) 19.0.1 seems to work as expected with non-virtual copy assignment operators.
https://godbolt.org/z/aCnsXa
C++ recommends that the copy assignment operator be a non-virtual member function.Unless there is a strong reason to make it a virtual member function, if it is the code you are asking, obviously non-virtual is recommended.
C.60: Make copy assignment non-virtual
, take the parameter by const&
, and return by non-const&
© 2024 OneMinuteCode. All rights reserved.