Bug 17256 - [3.4/4.0 Regression] undefined but used static or inline functions should be diagnosed
Summary: [3.4/4.0 Regression] undefined but used static or inline functions should be ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.3
Assignee: Jason Merrill
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2004-09-01 00:06 UTC by Joseph S. Myers
Modified: 2005-11-10 18:32 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 2.95.3 4.1.0
Known to fail: 3.3.4 3.4.0 4.0.0
Last reconfirmed: 2005-10-29 01:50:21


Attachments
treat nonmember static functions like inline functions (1.08 KB, patch)
2005-10-11 06:41 UTC, James A. Morrison
Details | Diff
testcase (140 bytes, text/plain)
2005-10-11 06:42 UTC, James A. Morrison
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph S. Myers 2004-09-01 00:06:14 UTC
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.
Comment 1 Geoff Keating 2004-09-01 00:51:41 UTC
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.
Comment 2 Giovanni Bajo 2004-09-01 04:19:48 UTC
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?
Comment 3 Giovanni Bajo 2004-09-01 04:20:41 UTC
(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.


Comment 4 Gabriel Dos Reis 2004-09-28 13:39:20 UTC
Adjust milestone
Comment 5 Andrew Pinski 2004-12-08 20:52:08 UTC
This is fixed at least on the mainline.
Comment 6 Andrew Pinski 2005-03-09 04:49:39 UTC
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).
Comment 7 James A. Morrison 2005-06-13 13:52:31 UTC
Shouldn't TREE_STATIC be checked on the FUNCTION_DECL to see if it has been defined?
Comment 8 Andrew Pinski 2005-07-22 21:12:55 UTC
Moving to 4.0.2 pre Mark.
Comment 9 Andrew Pinski 2005-09-07 19:11:12 UTC
Hmm, this works correctly with the C front-end.
Comment 10 James A. Morrison 2005-10-11 06:41:19 UTC
Created attachment 9962 [details]
treat nonmember static functions like inline functions
Comment 11 James A. Morrison 2005-10-11 06:42:54 UTC
Created attachment 9963 [details]
testcase

This patch also changes the error in:
static void f();
void g() { f(); }
into a warning.
Comment 12 Mark Mitchell 2005-10-30 22:51:35 UTC
Leaving as P2; we should try to fix this, but it's not a showstopper.
Comment 13 Janis Johnson 2005-11-03 22:12:02 UTC
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.

Comment 14 Jason Merrill 2005-11-07 06:17:51 UTC
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

Comment 15 Andrew Pinski 2005-11-07 13:17:46 UTC
Fixed at least on the mainline.
Comment 16 Jason Merrill 2005-11-10 18:32:22 UTC
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.