I am a little surprised that this program:
struct A {
virtual void a()=0;
};
struct B : public A {
void a() {}
};
int main() {
B b;
b.a();
b.A::a();
}
Gave me this error (gcc 4.4):
/tmp/ccfOGuBJ.o: In function `main':
test.cc:(.text+0x28): undefined reference to `A::a()'
collect2: ld returned 1 exit status
(clang 7.0.0)
Undefined symbols for architecture x86_64:
"A::a()", referenced from:
_main in test-440cc5.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I expected an attempt to call a pure function to give an explicit error, since it was declared as remote, not an implicit error. Is there no difference in the standard between "the function is not in this translation unit" and "no translation unit is functioning?"
It should be noted that an attempt to directly call a pure virtual is not considered in §10.4.
source
share