[Bug c++/124834] Devirtualization should not attempt to call pure virtual functions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124834
--- Comment #7 from Halalaluyafail3 ---
(In reply to Drea Pinski from comment #6)
> >Note that the call to foo is never actually reached, so the undefined
> >behavior does not happen.
>
> Yes but isn't that is the same as doing:
> ```
> int f();
>
> int g()
> {
> f();
> }
>
> int main()
> {
> return 0;
> }
> ```
>
> The undefined behavior is not reached here either.
f is odr-used here, so it will be IFNDR. But since foo in the original example
is a pure virtual function and the call is not using an explicitly qualified
name, A::foo is not named by the expression foo(). If it was not like this
then:
struct C{
virtual void bar()=0;
void baz(){
bar();
}
};
Would be invalid without a definition of C::bar. The original example is doing
the same thing as this, just inside of the constructor.
[Bug c++/124834] Devirtualization should not attempt to call pure virtual functions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124834 --- Comment #4 from Drea Pinski --- r0-61719-g585b44d301a56e changed it from an error to a warning and it was an error since 1996.
[Bug c++/124834] Devirtualization should not attempt to call pure virtual functions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124834
--- Comment #6 from Drea Pinski ---
>Note that the call to foo is never actually reached, so the undefined behavior
>does not happen.
Yes but isn't that is the same as doing:
```
int f();
int g()
{
f();
}
int main()
{
return 0;
}
```
The undefined behavior is not reached here either.
[Bug c++/124834] Devirtualization should not attempt to call pure virtual functions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124834 --- Comment #8 from Halalaluyafail3 --- Additionally, the undefined behavior in the original example comes from [class.abstract] saying that using the pure virtual function in this context is undefined behavior.
[Bug c++/124834] Devirtualization should not attempt to call pure virtual functions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124834 --- Comment #5 from Drea Pinski --- (In reply to Drea Pinski from comment #4) > r0-61719-g585b44d301a56e changed it from an error to a warning and it was an > error since 1996. https://inbox.sourceware.org/gcc-patches/[email protected]/ was when the request to turn the error into an warning happened.
[Bug c++/124834] Devirtualization should not attempt to call pure virtual functions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124834 --- Comment #3 from Drea Pinski --- Now GCC 3.4.6 used to error out and not just warn though: :4: error: abstract virtual `virtual void A::foo()' called from constructor
[Bug c++/124834] Devirtualization should not attempt to call pure virtual functions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124834 --- Comment #2 from Drea Pinski --- (In reply to Halalaluyafail3 from comment #1) > It seems to be accepted in GCC 4, so I suppose it is a regression albeit a > very old one. It was not accepted in GCC 4. godbolt does not support linking with GCC 4.
[Bug c++/124834] Devirtualization should not attempt to call pure virtual functions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124834 --- Comment #1 from Halalaluyafail3 --- It seems to be accepted in GCC 4, so I suppose it is a regression albeit a very old one.
