Commit d4babd37 by Jason Merrill Committed by Jason Merrill

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
parent 5161ffa4
2019-01-25 Jason Merrill <jason@redhat.com>
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 <rguenther@suse.de> 2019-04-07 Richard Biener <rguenther@suse.de>
PR middle-end/89618 PR middle-end/89618
......
...@@ -121,9 +121,12 @@ can_refer_decl_in_current_unit_p (tree decl, tree from_decl) ...@@ -121,9 +121,12 @@ can_refer_decl_in_current_unit_p (tree decl, tree from_decl)
|| !VAR_OR_FUNCTION_DECL_P (decl)) || !VAR_OR_FUNCTION_DECL_P (decl))
return true; return true;
/* Static objects can be referred only if they was not optimized out yet. */ /* Static objects can be referred only if they are defined and not optimized
if (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl)) out yet. */
if (!TREE_PUBLIC (decl))
{ {
if (DECL_EXTERNAL (decl))
return false;
/* Before we start optimizing unreachable code we can be sure all /* Before we start optimizing unreachable code we can be sure all
static objects are defined. */ static objects are defined. */
if (symtab->function_flags_ready) if (symtab->function_flags_ready)
......
// PR c++/80916
// { dg-options "-Os -Wunused" }
struct j {
virtual void dispatch(void *) {}
};
template <typename>
struct i : j {
void dispatch(void *) {} // warning: 'void i< <template-parameter-1-1> >::dispatch(void*) [with <template-parameter-1-1> = {anonymous}::l]' declared 'static' but never defined [-Wunused-function]
};
namespace {
struct l : i<l> {};
}
void f(j *k) {
k->dispatch(0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment