aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2018-06-11 17:49:36 -0400
committerJason Merrill <jason@gcc.gnu.org>2018-06-11 17:49:36 -0400
commitee7ae7ae1bf4271dd7e9c255c8a61a7adc188c7a (patch)
tree9c31f351156f06a9aaecfa81855cb40f603cadb2 /gcc
parentc7e2d7adf0822ea58ca3d6e86fdc06572088f986 (diff)
downloadgcc-ee7ae7ae1bf4271dd7e9c255c8a61a7adc188c7a.zip
gcc-ee7ae7ae1bf4271dd7e9c255c8a61a7adc188c7a.tar.gz
gcc-ee7ae7ae1bf4271dd7e9c255c8a61a7adc188c7a.tar.bz2
PR c++/85792 -Wctor-dtor-privacy and inherited constructor.
* class.c (maybe_warn_about_overly_private_class): Handle inherited constructors. From-SVN: r261459
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/class.c8
-rw-r--r--gcc/testsuite/g++.dg/warn/Wctor-dtor2.C11
3 files changed, 21 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 2424a3f..585f111 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2018-06-11 Jason Merrill <jason@redhat.com>
+ PR c++/85792 -Wctor-dtor-privacy and inherited constructor.
+ * class.c (maybe_warn_about_overly_private_class): Handle inherited
+ constructors.
+
PR c++/85963 - -Wunused-but-set with ?: in template.
* pt.c (tsubst_copy_and_build) [COND_EXPR]: Call mark_rvalue_use.
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index ab68b9b..fbf3903 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -2034,6 +2034,7 @@ maybe_warn_about_overly_private_class (tree t)
{
int has_member_fn = 0;
int has_nonprivate_method = 0;
+ bool nonprivate_ctor = false;
if (!warn_ctor_dtor_privacy
/* If the class has friends, those entities might create and
@@ -2064,7 +2065,11 @@ maybe_warn_about_overly_private_class (tree t)
non-private statics, we can't ever call any of the private member
functions.) */
for (tree fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
- if (!DECL_DECLARES_FUNCTION_P (fn))
+ if (TREE_CODE (fn) == USING_DECL
+ && DECL_NAME (fn) == ctor_identifier
+ && !TREE_PRIVATE (fn))
+ nonprivate_ctor = true;
+ else if (!DECL_DECLARES_FUNCTION_P (fn))
/* Not a function. */;
else if (DECL_ARTIFICIAL (fn))
/* We're not interested in compiler-generated methods; they don't
@@ -2126,7 +2131,6 @@ maybe_warn_about_overly_private_class (tree t)
/* Implicitly generated constructors are always public. */
&& !CLASSTYPE_LAZY_DEFAULT_CTOR (t))
{
- bool nonprivate_ctor = false;
tree copy_or_move = NULL_TREE;
/* If a non-template class does not define a copy
diff --git a/gcc/testsuite/g++.dg/warn/Wctor-dtor2.C b/gcc/testsuite/g++.dg/warn/Wctor-dtor2.C
new file mode 100644
index 0000000..4813785
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wctor-dtor2.C
@@ -0,0 +1,11 @@
+// PR c++/85792
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -Wctor-dtor-privacy }
+
+template<typename T> struct A { };
+
+template<typename T> struct B : A<T> {
+ using A<T>::A;
+
+ B(const B&) { }
+};