aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2019-08-23 19:26:04 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2019-08-23 19:26:04 +0000
commit5f9f1ffebe2a3c86d2835118e28714d4a8c878c9 (patch)
treebd6fa4ce6d6076c561105f9833b7b21f8d727bff /gcc
parent7d35d2bf5a15e38122083ddd198d1d20548d0ffa (diff)
downloadgcc-5f9f1ffebe2a3c86d2835118e28714d4a8c878c9.zip
gcc-5f9f1ffebe2a3c86d2835118e28714d4a8c878c9.tar.gz
gcc-5f9f1ffebe2a3c86d2835118e28714d4a8c878c9.tar.bz2
[C++ PATCH] vfunc overrider simplification
https://gcc.gnu.org/ml/gcc-patches/2019-08/msg01674.html * class.c (check_for_override): Checking IDENTIFIER_VIRTUAL_P is sufficient, reorder DECL_OVERRIDE_P check. From-SVN: r274867
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/class.c35
2 files changed, 26 insertions, 14 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f014423..c416082 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2019-08-23 Nathan Sidwell <nathan@acm.org>
+
+ * class.c (check_for_override): Checking IDENTIFIER_VIRTUAL_P is
+ sufficient, reorder DECL_OVERRIDE_P check.
+
2019-08-23 Iain Sandoe <iain@sandoe.co.uk>
PR pch/61250
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index cc53b15..99332f4 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -2802,31 +2802,34 @@ get_basefndecls (tree name, tree t, vec<tree> *base_fndecls)
}
}
-/* If this declaration supersedes the declaration of
- a method declared virtual in the base class, then
- mark this field as being virtual as well. */
+/* If this method overrides a virtual method from a base, then mark
+ this member function as being virtual as well. Do 'final' and
+ 'override' checks too. */
void
check_for_override (tree decl, tree ctype)
{
- bool overrides_found = false;
if (TREE_CODE (decl) == TEMPLATE_DECL)
/* In [temp.mem] we have:
A specialization of a member function template does not
override a virtual function from a base class. */
return;
- if ((DECL_DESTRUCTOR_P (decl)
- || IDENTIFIER_VIRTUAL_P (DECL_NAME (decl))
- || DECL_CONV_FN_P (decl))
+
+ /* IDENTIFIER_VIRTUAL_P indicates whether the name has ever been
+ used for a vfunc. That avoids the expensive
+ look_for_overrides call that when we know there's nothing to
+ find. */
+ if (IDENTIFIER_VIRTUAL_P (DECL_NAME (decl))
&& look_for_overrides (ctype, decl)
+ /* Check staticness after we've checked if we 'override'. */
&& !DECL_STATIC_FUNCTION_P (decl))
- /* Set DECL_VINDEX to a value that is neither an INTEGER_CST nor
- the error_mark_node so that we know it is an overriding
- function. */
{
+ /* Set DECL_VINDEX to a value that is neither an INTEGER_CST nor
+ the error_mark_node so that we know it is an overriding
+ function. */
DECL_VINDEX (decl) = decl;
- overrides_found = true;
+
if (warn_override
&& !DECL_OVERRIDE_P (decl)
&& !DECL_FINAL_P (decl)
@@ -2834,19 +2837,23 @@ check_for_override (tree decl, tree ctype)
warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wsuggest_override,
"%qD can be marked override", decl);
}
+ else if (DECL_OVERRIDE_P (decl))
+ error ("%q+#D marked %<override%>, but does not override", decl);
if (DECL_VIRTUAL_P (decl))
{
+ /* Remember this identifier is virtual name. */
+ IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = true;
+
if (!DECL_VINDEX (decl))
+ /* It's a new vfunc. */
DECL_VINDEX (decl) = error_mark_node;
- IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
+
if (DECL_DESTRUCTOR_P (decl))
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
}
else if (DECL_FINAL_P (decl))
error ("%q+#D marked %<final%>, but is not virtual", decl);
- if (DECL_OVERRIDE_P (decl) && !overrides_found)
- error ("%q+#D marked %<override%>, but does not override", decl);
}
/* Warn about hidden virtual functions that are not overridden in t.