From: Jason Merrill Date: Thu, 7 Mar 2019 15:10:22 +0000 (-0500) Subject: PR c++/80916 - spurious "static but not defined" warning. X-Git-Tag: upstream/12.2.0~25803 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d4babd373b9634c6964cad53423470ac8f38addf;p=platform%2Fupstream%2Fgcc.git PR c++/80916 - spurious "static but not defined" warning. Nothing can refer to an internal decl with no definition, so we shouldn't treat such a decl as a possible devirtualization target. * gimple-fold.c (can_refer_decl_in_current_unit_p): Return false for an internal symbol with DECL_EXTERNAL. From-SVN: r269459 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b5a7387..507c8e1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-01-25 Jason Merrill + + PR c++/80916 - spurious "static but not defined" warning. + * gimple-fold.c (can_refer_decl_in_current_unit_p): Return false + for an internal symbol with DECL_EXTERNAL. + 2019-04-07 Richard Biener PR middle-end/89618 diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 7ef5004..62d2e0a 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -121,9 +121,12 @@ can_refer_decl_in_current_unit_p (tree decl, tree from_decl) || !VAR_OR_FUNCTION_DECL_P (decl)) return true; - /* Static objects can be referred only if they was not optimized out yet. */ - if (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl)) + /* Static objects can be referred only if they are defined and not optimized + out yet. */ + if (!TREE_PUBLIC (decl)) { + if (DECL_EXTERNAL (decl)) + return false; /* Before we start optimizing unreachable code we can be sure all static objects are defined. */ if (symtab->function_flags_ready) diff --git a/gcc/testsuite/g++.dg/warn/unused-fn1.C b/gcc/testsuite/g++.dg/warn/unused-fn1.C new file mode 100644 index 0000000..aabc01b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/unused-fn1.C @@ -0,0 +1,16 @@ +// PR c++/80916 +// { dg-options "-Os -Wunused" } + +struct j { + virtual void dispatch(void *) {} +}; +template +struct i : j { + void dispatch(void *) {} // warning: 'void i< >::dispatch(void*) [with = {anonymous}::l]' declared 'static' but never defined [-Wunused-function] +}; +namespace { + struct l : i {}; +} +void f(j *k) { + k->dispatch(0); +}