Bug 60277 - Bogus "inline function virtual ..." used but never defined
Summary: Bogus "inline function virtual ..." used but never defined
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 9.3
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2014-02-19 19:57 UTC by Paul Pluzhnikov
Modified: 2021-12-03 05:45 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.1.0, 9.3.0
Known to fail: 8.1.0, 8.5.0, 9.1.0, 9.2.0
Last reconfirmed: 2018-05-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Pluzhnikov 2014-02-19 19:57:41 UTC
Test case:

struct Foo {
  inline virtual void func() = 0;
};

struct Bar : public Foo {
  void func() { }
};

int main()
{
  Foo *f = new Bar;
  f->func();
}


Using trunk:
g++ (GCC) 4.9.0 20140219 (experimental)

g++ -c -Wall -Wextra t.cc
t.cc:2:23: warning: inline function 'virtual void Foo::func()' used but never defined
   inline virtual void func() = 0;
                       ^


But Foo::func is never actually used.

Analysis by Nick Lewycky:


The relevant [basic.odr]/2 text is:
  "A virtual member function is odr-used if it is not pure. A non-overloaded function whose name appears as a potentially-evaluated expression or a member of a set of candidate functions, if selected by overload resolution when referred to from a potentially-evaluated expression, is odr-used, unless it is a pure virtual function and its name is not explicitly qualified."

Since the function isn't ODR-used, there's no need for it to have a definition:
  "An inline function shall be defined in every translation unit in which it is odr-used." [basic.odr]/3
Comment 1 Nick Lewycky 2014-02-19 21:07:12 UTC
Furthermore, if the testcase ended with:

  f->Foo::func();

then the warning should be issued.
Comment 2 Jason Merrill 2014-02-21 14:57:17 UTC
Author: jason
Date: Fri Feb 21 14:56:46 2014
New Revision: 208001

URL: http://gcc.gnu.org/viewcvs?rev=208001&root=gcc&view=rev
Log:
	PR c++/60277
	* call.c (build_array_conv): Don't crash on VLA.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/vla13.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
Comment 3 Mikhail Maltsev 2015-05-08 04:13:22 UTC
I also wanted to report this bug (it reproduces on trunk), but found this report and an old duplicate: PR11067 which is resolved as WONTFIX.

IMHO it's not too difficult to fix, including the case "f->Foo::func();" (though I did not regtest the fix, so I can't say for sure).

The question is: should this warning be emitted or not? Clang does not produce such warning.
Comment 4 Drea Pinski 2021-12-03 05:45:43 UTC
Fixed in GCC 9.3.0+ and in GCC 10 by r10-5027-g99150b053e1 and r9-8069-ge3edafbca9f3553 (PR 92695). The patch includes exactly a testcase which is similar enough to this one.

So closing as fixed.