diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2015-09-22 15:34:49 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2015-09-22 15:34:49 +0000 |
commit | 6b333269be81396c4ed6b700bf8bd3e0adeb50dc (patch) | |
tree | bcb65e277ee9e4c184bb3b1253a5dc833a787791 /gcc | |
parent | a75f15742ab04d48fb599c9b6523ffbe8f5d837c (diff) | |
download | gcc-6b333269be81396c4ed6b700bf8bd3e0adeb50dc.zip gcc-6b333269be81396c4ed6b700bf8bd3e0adeb50dc.tar.gz gcc-6b333269be81396c4ed6b700bf8bd3e0adeb50dc.tar.bz2 |
c.opt (Wmultiple-inheritance, [...]): New C++ warnings.
c-family/
* c.opt (Wmultiple-inheritance, Wvirtual-inheritance, Wtemplates,
Wnamespaces): New C++ warnings.
cp/
* decl.c (xref_basetypes): Check virtual and/or multiple
inheritance warning.
* parser.c (cp_parser_namespace_definition): Check namespaces
warning.
* pt.c (push_template_decl_real): Check templates warning.
* doc/invoke.texi (-Wmultiple-inheritance, -Wvirtual-inheritance,
-Wtemplates, -Wnamespaces): Document.
testsuite/
* g++.dg/diagostic/disable.C: New.
From-SVN: r228019
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-family/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-family/c.opt | 16 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/decl.c | 10 | ||||
-rw-r--r-- | gcc/cp/parser.c | 2 | ||||
-rw-r--r-- | gcc/cp/pt.c | 2 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 38 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/diagnostic/disable.C | 27 |
10 files changed, 113 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 95db047..cf31527 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-09-22 Nathan Sidwell <nathan@codesourcery.com> + + * doc/invoke.texi (-Wmultiple-inheritance, -Wvirtual-inheritance, + -Wtemplates, -Wnamespaces): Document. + 2015-09-22 Tom de Vries <tom@codesourcery.com> PR tree-optimization/67671 diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index bccbbfa..381cb92 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2015-09-22 Nathan Sidwell <nathan@codesourcery.com> + + * c.opt (Wmultiple-inheritance, Wvirtual-inheritance, Wtemplates, + Wnamespaces): New C++ warnings. + 2015-09-22 Jason Merrill <jason@redhat.com> * c-common.h (abi_compat_version_crosses): New. diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 47ba070..3d7d502 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -573,6 +573,14 @@ Wmissing-field-initializers C ObjC C++ ObjC++ Var(warn_missing_field_initializers) Warning EnabledBy(Wextra) Warn about missing fields in struct initializers +Wmultiple-inheritance +C++ ObjC++ Var(warn_multiple_inheritance) Warning +Warn on direct multiple inheritance + +Wnamespaces +C++ ObjC++ Var(warn_namespaces) Warning +Warn on namespace definition + Wsized-deallocation C++ ObjC++ Var(warn_sized_deallocation) Warning EnabledBy(Wextra) Warn about missing sized deallocation functions @@ -610,6 +618,10 @@ Wswitch-bool C ObjC C++ ObjC++ Var(warn_switch_bool) Warning Init(1) Warn about switches with boolean controlling expression +Wtemplates +C++ ObjC++ Var(warn_templates) Warning +Warn on primary template declaration + Wmissing-format-attribute C ObjC C++ ObjC++ Alias(Wsuggest-attribute=format) ; @@ -936,6 +948,10 @@ Wvolatile-register-var C ObjC C++ ObjC++ Var(warn_volatile_register_var) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall) Warn when a register variable is declared volatile +Wvirtual-inheritance +C++ ObjC++ Var(warn_virtual_inheritance) Warning +Warn on direct virtual inheritance + Wvirtual-move-assign C++ ObjC++ Var(warn_virtual_move_assign) Warning Init(1) Warn if a virtual base has a non-trivial move assignment operator diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e9a21f4..49f131e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2015-09-22 Nathan Sidwell <nathan@codesourcery.com> + + * decl.c (xref_basetypes): Check virtual and/or multiple + inheritance warning. + * parser.c (cp_parser_namespace_definition): Check namespaces + warning. + * pt.c (push_template_decl_real): Check templates warning. + 2015-09-22 Jason Merrill <jason@redhat.com> * mangle.c (abi_warn_or_compat_version_crosses): New. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 96d735a..2be7d2f 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -12729,6 +12729,7 @@ xref_basetypes (tree ref, tree base_list) tree binfo, base_binfo; unsigned max_vbases = 0; /* Maximum direct & indirect virtual bases. */ unsigned max_bases = 0; /* Maximum direct bases. */ + unsigned max_dvbases = 0; /* Maximum direct virtual bases. */ int i; tree default_access; tree igo_prev; /* Track Inheritance Graph Order. */ @@ -12766,12 +12767,13 @@ xref_basetypes (tree ref, tree base_list) { max_bases++; if (TREE_TYPE (*basep)) - max_vbases++; + max_dvbases++; if (CLASS_TYPE_P (basetype)) max_vbases += vec_safe_length (CLASSTYPE_VBASECLASSES (basetype)); basep = &TREE_CHAIN (*basep); } } + max_vbases += max_dvbases; TYPE_MARKED_P (ref) = 1; @@ -12814,6 +12816,9 @@ xref_basetypes (tree ref, tree base_list) error ("Java class %qT cannot have multiple bases", ref); return false; } + else + warning (OPT_Wmultiple_inheritance, + "%qT defined with multiple direct bases", ref); } if (max_vbases) @@ -12825,6 +12830,9 @@ xref_basetypes (tree ref, tree base_list) error ("Java class %qT cannot have virtual bases", ref); return false; } + else if (max_dvbases) + warning (OPT_Wvirtual_inheritance, + "%qT defined with direct virtual base", ref); } for (igo_prev = binfo; base_list; base_list = TREE_CHAIN (base_list)) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 0134189..cc920926e 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -17043,6 +17043,8 @@ cp_parser_namespace_definition (cp_parser* parser) has_visibility = handle_namespace_attrs (current_namespace, attribs); + warning (OPT_Wnamespaces, "namepace %qD entered", current_namespace); + /* Parse the body of the namespace. */ cp_parser_namespace_body (parser); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 10a12ea..db947cc 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -5088,6 +5088,8 @@ push_template_decl_real (tree decl, bool is_friend) if (is_primary) { + warning (OPT_Wtemplates, "template %qD declared", decl); + if (DECL_CLASS_SCOPE_P (decl)) member_template_p = true; if (TREE_CODE (decl) == TYPE_DECL diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index f0b7cc4..09c58ee 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -198,12 +198,13 @@ in the following sections. -fvisibility-ms-compat @gol -fext-numeric-literals @gol -Wabi=@var{n} -Wabi-tag -Wconversion-null -Wctor-dtor-privacy @gol --Wdelete-non-virtual-dtor -Wliteral-suffix -Wnarrowing @gol +-Wdelete-non-virtual-dtor -Wliteral-suffix -Wmultiple-inheritance @gol +-Wnamespaces -Wnarrowing @gol -Wnoexcept -Wnon-virtual-dtor -Wreorder @gol --Weffc++ -Wstrict-null-sentinel @gol +-Weffc++ -Wstrict-null-sentinel -Wtemplates @gol -Wno-non-template-friend -Wold-style-cast @gol -Woverloaded-virtual -Wno-pmf-conversions @gol --Wsign-promo} +-Wsign-promo -Wvirtual-inheritance} @item Objective-C and Objective-C++ Language Options @xref{Objective-C and Objective-C++ Dialect Options,,Options Controlling @@ -2934,6 +2935,37 @@ enumerated type to a signed type, over a conversion to an unsigned type of the same size. Previous versions of G++ tried to preserve unsignedness, but the standard mandates the current behavior. +@item -Wtemplates @r{(C++ and Objective-C++ only)} +@opindex Wtemplates +Warn when a primary template declaration is encountered. Some coding +rules disallow templates, and this may be used to enforce that rule. +The warning is inactive inside a system header file, such as the STL, so +one can still use the STL. One may also instantiate or specialize +templates. + +@item -Wmultiple-inheritance @r{(C++ and Objective-C++ only)} +@opindex Wmultiple-inheritance +Warn when a class is defined with multiple direct base classes. Some +coding rules disallow multiple inheritance, and this may be used to +enforce that rule. The warning is inactive inside a system header file, +such as the STL, so one can still use the STL. One may also define +classes that indirectly use multiple inheritance. + +@item -Wvirtual-inheritance +@opindex Wvirtual-inheritance +Warn when a class is defined with a virtual direct base classe. Some +coding rules disallow multiple inheritance, and this may be used to +enforce that rule. The warning is inactive inside a system header file, +such as the STL, so one can still use the STL. One may also define +classes that indirectly use virtual inheritance. + +@item -Wnamespaces +@opindex Wnamespaces +Warn when a namespace definition is opened. Some coding rules disallow +namespaces, and this may be used to enforce that rule. The warning is +inactive inside a system header file, such as the STL, so one can still +use the STL. One may also use using directives and qualified names. + @item -Wno-terminate @r{(C++ and Objective-C++ only)} @opindex Wterminate @opindex Wno-terminate diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bcd04a0..68eb33e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-09-22 Nathan Sidwell <nathan@codesourcery.com> + + * g++.dg/diagostic/disable.C: New. + 2015-09-22 Tom de Vries <tom@codesourcery.com> PR tree-optimization/67671 diff --git a/gcc/testsuite/g++.dg/diagnostic/disable.C b/gcc/testsuite/g++.dg/diagnostic/disable.C new file mode 100644 index 0000000..a69033d --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/disable.C @@ -0,0 +1,27 @@ +// { dg-options "-Wtemplates -Wmultiple-inheritance -Wvirtual-inheritance -Wnamespaces" } + +#include <iostream> +#include <algorithm> + +namespace foo { } // { dg-warning "namepace" } + +template <typename X> X Foo (); // { dg-warning "template" } + +struct B1 {}; +struct B2 {}; +struct V {}; + +struct D : B1, B2 {}; // { dg-warning "multiple" } + +struct E : virtual V {}; // { dg-warning "virtual" } + +struct F1 : E {}; + +struct F2 : D {}; + +void Baz (int a, int b) +{ + std::swap (a, b); +} + + |