Intel C++ Compiler Default Declares Operator to Error Compiling

Asked 1 years ago, Updated 1 years ago, 39 views

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

c++

2022-09-30 21:43

2 Answers

In P0135R1Guaranteed copyelion

  • If the initializer expression is a prvalue and the cv-unqualified version of the source type is the same class as the class of the destination, the initializer expression is used to initialize the destination object.[Example:Tx=T(T(T(T(T/));)

because it is considered that
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.


2022-09-30 21:43

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&


2022-09-30 21:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.