aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMatthew Beliveau <mbelivea@redhat.com>2019-06-11 15:03:21 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2019-06-11 15:03:21 +0000
commitd3786ebbb06f501be93cceaf087339986e4829c7 (patch)
treee9d8906df0f5a198c89227bd39ecdfc5ca01878a /gcc
parentda10c178007d4edea4ad97f49041c6a6a8c5b02d (diff)
downloadgcc-d3786ebbb06f501be93cceaf087339986e4829c7.zip
gcc-d3786ebbb06f501be93cceaf087339986e4829c7.tar.gz
gcc-d3786ebbb06f501be93cceaf087339986e4829c7.tar.bz2
PR c++/90449 - add -Winaccessible-base option.
* doc/invoke.texi (Winaccessible-base): Document. * c.opt (Winaccessible-base): Added new option. * class.c (warn_about_ambiguous_bases): Changed name to: maybe_warn_about_inaccessible_bases. (maybe_warn_about_inaccessible_bases): Implemented new Winaccessible-base warning option for both direct and virtual base warnings. (layout_class_type): Call to warn_about_ambiguous_bases changed to fit new name. * g++.dg/warn/Winaccessible-base-1.C: New file. * g++.dg/warn/Winaccessible-base-2.C: New file. * g++.dg/warn/Winaccessible-virtual-base-1.C: New file. * g++.dg/warn/Winaccessible-virtual-base-2.C: New file. From-SVN: r272157
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-family/ChangeLog5
-rw-r--r--gcc/c-family/c.opt4
-rw-r--r--gcc/cp/ChangeLog11
-rw-r--r--gcc/cp/class.c18
-rw-r--r--gcc/doc/invoke.texi17
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/g++.dg/warn/Winaccessible-base-1.C7
-rw-r--r--gcc/testsuite/g++.dg/warn/Winaccessible-base-2.C8
-rw-r--r--gcc/testsuite/g++.dg/warn/Winaccessible-virtual-base-1.C10
-rw-r--r--gcc/testsuite/g++.dg/warn/Winaccessible-virtual-base-2.C10
11 files changed, 96 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 211a55d..0c5cf70 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2019-06-11 Matthew Beliveau <mbelivea@redhat.com>
+
+ PR c++/90449 - add -Winaccessible-base option.
+ * doc/invoke.texi (Winaccessible-base): Document.
+
2019-06-11 Marc Glisse <marc.glisse@inria.fr>
PR tree-optimization/62041
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 589e4a1..4224718 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+2019-06-11 Matthew Beliveau <mbelivea@redhat.com>
+
+ PR c++/90449 - add -Winaccessible-base option.
+ * c.opt (Winaccessible-base): New option.
+
2019-06-10 Jakub Jelinek <jakub@redhat.com>
* c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_SCAN.
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 6c24777..572cf18 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -625,6 +625,10 @@ Wignored-attributes
C C++ Var(warn_ignored_attributes) Init(1) Warning
Warn whenever attributes are ignored.
+Winaccessible-base
+C++ ObjC++ Var(warn_inaccessible_base) Init(1) Warning
+Warn when a base is inaccessible in derived due to ambiguity.
+
Wincompatible-pointer-types
C ObjC Var(warn_incompatible_pointer_types) Init(1) Warning
Warn when there is a conversion between pointers that have incompatible types.
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index e067ff7..5e8fd69 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,14 @@
+2019-06-11 Matthew Beliveau <mbelivea@redhat.com>
+
+ PR c++/90449 - add -Winaccessible-base option.
+ * class.c (warn_about_ambiguous_bases): Changed name to:
+ maybe_warn_about_inaccessible_bases.
+ (maybe_warn_about_inaccessible_bases): Implemented new
+ Winaccessible-base warning option for both direct and virtual
+ base warnings.
+ (layout_class_type): Call to warn_about_ambiguous_bases changed to fit
+ new name.
+
2019-06-11 Richard Biener <rguenther@suse.de>
PR c++/90801
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index d6ac6ce..4fdb0f3 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -199,7 +199,7 @@ static int walk_subobject_offsets (tree, subobject_offset_fn,
static int layout_conflict_p (tree, tree, splay_tree, int);
static int splay_tree_compare_integer_csts (splay_tree_key k1,
splay_tree_key k2);
-static void warn_about_ambiguous_bases (tree);
+static void maybe_warn_about_inaccessible_bases (tree);
static bool type_requires_array_cookie (tree);
static bool base_derived_from (tree, tree);
static int empty_base_at_nonzero_offset_p (tree, tree, splay_tree);
@@ -6018,7 +6018,7 @@ end_of_class (tree t, bool include_virtuals_p)
subobjects of U. */
static void
-warn_about_ambiguous_bases (tree t)
+maybe_warn_about_inaccessible_bases (tree t)
{
int i;
vec<tree, va_gc> *vbases;
@@ -6026,6 +6026,10 @@ warn_about_ambiguous_bases (tree t)
tree binfo;
tree base_binfo;
+ /* If not checking for warning then return early. */
+ if (!warn_inaccessible_base)
+ return;
+
/* If there are no repeated bases, nothing can be ambiguous. */
if (!CLASSTYPE_REPEATED_BASE_P (t))
return;
@@ -6037,8 +6041,8 @@ warn_about_ambiguous_bases (tree t)
basetype = BINFO_TYPE (base_binfo);
if (!uniquely_derived_from_p (basetype, t))
- warning (0, "direct base %qT inaccessible in %qT due to ambiguity",
- basetype, t);
+ warning (OPT_Winaccessible_base, "direct base %qT inaccessible "
+ "in %qT due to ambiguity", basetype, t);
}
/* Check for ambiguous virtual bases. */
@@ -6049,8 +6053,8 @@ warn_about_ambiguous_bases (tree t)
basetype = BINFO_TYPE (binfo);
if (!uniquely_derived_from_p (basetype, t))
- warning (OPT_Wextra, "virtual base %qT inaccessible in %qT due "
- "to ambiguity", basetype, t);
+ warning (OPT_Winaccessible_base, "virtual base %qT inaccessible in "
+ "%qT due to ambiguity", basetype, t);
}
}
@@ -6456,7 +6460,7 @@ layout_class_type (tree t, tree *virtuals_p)
error ("size of type %qT is too large (%qE bytes)", t, TYPE_SIZE_UNIT (t));
/* Warn about bases that can't be talked about due to ambiguity. */
- warn_about_ambiguous_bases (t);
+ maybe_warn_about_inaccessible_bases (t);
/* Now that we're done with layout, give the base fields the real types. */
for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index f18d225..1520b2c 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -317,6 +317,7 @@ Objective-C and Objective-C++ Dialects}.
-Wignored-qualifiers -Wignored-attributes -Wincompatible-pointer-types @gol
-Wimplicit -Wimplicit-fallthrough -Wimplicit-fallthrough=@var{n} @gol
-Wimplicit-function-declaration -Wimplicit-int @gol
+-Winaccessible-base @gol
-Winit-self -Winline -Wno-int-conversion -Wint-in-bool-context @gol
-Wno-int-to-pointer-cast -Winvalid-memory-model -Wno-invalid-offsetof @gol
-Winvalid-pch -Wlarger-than=@var{byte-size} @gol
@@ -4800,6 +4801,22 @@ is only active when @option{-fdelete-null-pointer-checks} is active,
which is enabled by optimizations in most targets. The precision of
the warnings depends on the optimization options used.
+@item -Winaccessible-base @r{(C++, Objective-C++ only)}
+@opindex Winaccessible-base
+@opindex Wno-inaccessible-base
+Warn when a base class is inaccessible in a class derived from it due to
+ambiguity. The warning is enabled by default. Note the warning for virtual
+bases is enabled by the @option{-Wextra} option.
+@smallexample
+@group
+struct A @{ int a; @};
+
+struct B : A @{ @};
+
+struct C : B, A @{ @};
+@end group
+@end smallexample
+
@item -Winit-self @r{(C, C++, Objective-C and Objective-C++ only)}
@opindex Winit-self
@opindex Wno-init-self
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index beecd96..21b5d83 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2019-06-11 Matthew Beliveau <mbelivea@redhat.com>
+
+ PR c++/90449 - add -Winaccessible-base option.
+ * g++.dg/warn/Winaccessible-base-1.C: New file.
+ * g++.dg/warn/Winaccessible-base-2.C: New file.
+ * g++.dg/warn/Winaccessible-virtual-base-1.C: New file.
+ * g++.dg/warn/Winaccessible-virtual-base-2.C: New file.
+
2019-06-11 Jakub Jelinek <jakub@redhat.com>
PR c++/90810
diff --git a/gcc/testsuite/g++.dg/warn/Winaccessible-base-1.C b/gcc/testsuite/g++.dg/warn/Winaccessible-base-1.C
new file mode 100644
index 0000000..2e32b0b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Winaccessible-base-1.C
@@ -0,0 +1,7 @@
+// PR c++/90449
+
+struct A { int a; };
+
+struct B : A { };
+
+struct C : B, A { }; // { dg-warning "direct base 'A' inaccessible in 'C' due to ambiguity" }
diff --git a/gcc/testsuite/g++.dg/warn/Winaccessible-base-2.C b/gcc/testsuite/g++.dg/warn/Winaccessible-base-2.C
new file mode 100644
index 0000000..67bd740
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Winaccessible-base-2.C
@@ -0,0 +1,8 @@
+// PR c++/90449
+// { dg-options -Wno-inaccessible-base }
+
+struct A { int a; };
+
+struct B : A { };
+
+struct C : B, A { }; // { dg-bogus "direct base 'A' inaccessible in 'C' due to ambiguity" }
diff --git a/gcc/testsuite/g++.dg/warn/Winaccessible-virtual-base-1.C b/gcc/testsuite/g++.dg/warn/Winaccessible-virtual-base-1.C
new file mode 100644
index 0000000..051fcc6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Winaccessible-virtual-base-1.C
@@ -0,0 +1,10 @@
+// PR c++/90449
+// { dg-options -Wextra }
+
+struct A { };
+
+struct B : virtual A { };
+
+struct C : A { };
+
+struct D : B, C { }; // { dg-warning "virtual base 'A' inaccessible in 'D' due to ambiguity" }
diff --git a/gcc/testsuite/g++.dg/warn/Winaccessible-virtual-base-2.C b/gcc/testsuite/g++.dg/warn/Winaccessible-virtual-base-2.C
new file mode 100644
index 0000000..eab9ec0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Winaccessible-virtual-base-2.C
@@ -0,0 +1,10 @@
+// PR c++/90449
+// { dg-options "-Wextra -Wno-inaccessible-base" }
+
+struct A { };
+
+struct B : virtual A { };
+
+struct C : A { };
+
+struct D : B, C { }; // { dg-bogus "virtual base 'A' inaccessible in 'D' due to ambiguity" }