inline static void f1(void); void g1(void) { if (0) { f1(); } } violates the requirement that "An inline function shall be defined in every translation unit in which it is used." [basic.odr] paragraph 3, so should be diagnosed ("used" having a specific definition which covers this case). The diagnostic should be a pedwarn rather than the existing warning for inline functions that aren't defined. Much the same code would probably also facilitate diagnosing the simple ODR violation, no diagnostic required, where "inline" is removed from the declaration of f1.
Subject: Re: New: undefined but used static or inline functions should be diagnosed The code that does this in the case where an inline function is truly used lives in cp/decl2.c, just under the comment /* All used inline functions must have a definition at this point. */ However, it checks TREE_USED, which may not be the right thing.
Confirmed, a regression on all open branches and mainline. Geoff: the decl is marked with TREE_USED, but the predicate DECL_REALLY_EXTERN holds true for it. Any idea why?
(In reply to comment #2) > Geoff: the decl is marked with TREE_USED, but the predicate DECL_REALLY_EXTERN > holds true for it. Sorry, I meant that DECL_REALLY_EXTERN is *false* for the decl, so the diagnostic is not emitted.
Adjust milestone
This is fixed at least on the mainline.
This broke again on the mainline (before the branch of 4.0.0 and even before 3.5.0 was changed to 4.0.0).
Shouldn't TREE_STATIC be checked on the FUNCTION_DECL to see if it has been defined?
Moving to 4.0.2 pre Mark.
Hmm, this works correctly with the C front-end.
Created attachment 9962 [details] treat nonmember static functions like inline functions
Created attachment 9963 [details] testcase This patch also changes the error in: static void f(); void g() { f(); } into a warning.
Leaving as P2; we should try to fix this, but it's not a showstopper.
A regression hunt showed that "warning: inline function `void f1()' used but never defined" disappeared with this patch to make the C++ front end always work in unit-at-a-time mode: r85309 | mmitchel | 2004-07-29 17:59:31 +0000 (Thu, 29 Jul 2004) | 124 lines http://gcc.gnu.org/viewcvs?view=rev&rev=85309 Sometime in 2004-09-09 - 2004-09-24 it got "error: 'void f1()' used but never defined", which went away sometime in 2004-10-08 - 2004-10-27. I can run regression hunts on either or both of those if the information would be useful. The patch in comment #10 has never been submitted, so this PR doesn't have the "patch" keyword.
Subject: Bug 17256 Author: jason Date: Mon Nov 7 06:17:47 2005 New Revision: 106581 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106581 Log: PR c++/17256 * decl2.c (cp_finish_file): Fix conditions for undefined warning. Set TREE_NO_WARNING instead of TREE_PUBLIC. * pt.c (instantiate_pending_templates): Set DECL_INITIAL to avoid a warning on a function we didn't instantiate because of excessive recursion. Added: trunk/gcc/testsuite/g++.dg/warn/undefined1.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl2.c trunk/gcc/cp/pt.c
Fixed at least on the mainline.
The patch breaks the 4.0 branch compiler, and I don't think this is a serious enough bug to put more work into coming up with a different fix for older releases.