diff options
author | Ian Lance Taylor <iant@google.com> | 2006-12-18 19:56:58 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2006-12-18 19:56:58 +0000 |
commit | dfdec7a7054a692dbd50543daf5d74a1c1b92472 (patch) | |
tree | 9efc1768f6967aa34cd07b16cba198db0459ecf0 /gcc | |
parent | ecc54e6eab98f1275218af1e7ed2c3aaa81ed456 (diff) | |
download | gcc-dfdec7a7054a692dbd50543daf5d74a1c1b92472.zip gcc-dfdec7a7054a692dbd50543daf5d74a1c1b92472.tar.gz gcc-dfdec7a7054a692dbd50543daf5d74a1c1b92472.tar.bz2 |
c.opt (Wmissing-declarations): Add C++ and ObjC++.
./: * c.opt (Wmissing-declarations): Add C++ and ObjC++.
* doc/invoke.texi (Warning Options): -Wmissing-declarations now
works for C++.
cp/:
* decl.c (start_preparsed_function): Add support for
-Wmissing-declarations.
testsuite:
* g++.dg/warn/Wmissing-declarations-1.C: New test.
From-SVN: r120012
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c.opt | 2 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/decl.c | 33 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 5 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wmissing-declarations-1.C | 45 |
7 files changed, 94 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e9a397e..6e812d4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2006-12-18 Ian Lance Taylor <iant@google.com> + + * c.opt (Wmissing-declarations): Add C++ and ObjC++. + * doc/invoke.texi (Warning Options): -Wmissing-declarations now + works for C++. + 2006-12-18 Andrew MacLeod <amacleod@redhat.com> * tree-ssa-operands.h (struct vdef_optype_d): Rename to voptype_d. @@ -264,7 +264,7 @@ C ObjC C++ ObjC++ Var(warn_missing_braces) Warn about possibly missing braces around initializers Wmissing-declarations -C ObjC Var(warn_missing_declarations) +C ObjC C++ ObjC++ Var(warn_missing_declarations) Warn about global functions without previous declarations Wmissing-field-initializers diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b51ebc0..2eac776 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2006-12-18 Ian Lance Taylor <iant@google.com> + + * decl.c (start_preparsed_function): Add support for + -Wmissing-declarations. + 2006-12-16 Simon Martin <simartin@users.sourceforge.net> PR c++/29475 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 2e6ace3..f23fd48 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10570,9 +10570,36 @@ start_preparsed_function (tree decl1, tree attrs, int flags) parsing the body of the function. */ ; else - /* Otherwise, OLDDECL is either a previous declaration of - the same function or DECL1 itself. */ - decl1 = olddecl; + { + /* Otherwise, OLDDECL is either a previous declaration + of the same function or DECL1 itself. */ + + if (warn_missing_declarations + && olddecl == decl1 + && !DECL_MAIN_P (decl1) + && TREE_PUBLIC (decl1) + && !DECL_DECLARED_INLINE_P (decl1)) + { + tree context; + + /* Check whether DECL1 is in an anonymous + namespace. */ + for (context = DECL_CONTEXT (decl1); + context; + context = DECL_CONTEXT (context)) + { + if (TREE_CODE (context) == NAMESPACE_DECL + && DECL_NAME (context) == NULL_TREE) + break; + } + + if (context == NULL) + warning (OPT_Wmissing_declarations, + "no previous declaration for %q+D", decl1); + } + + decl1 = olddecl; + } } else { diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 52b1daa..290dad0 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -3221,12 +3221,13 @@ declaration. This warning is issued even if the definition itself provides a prototype. The aim is to detect global functions that fail to be declared in header files. -@item -Wmissing-declarations @r{(C only)} +@item -Wmissing-declarations @r{(C and C++ only)} @opindex Wmissing-declarations Warn if a global function is defined without a previous declaration. Do so even if the definition itself provides a prototype. Use this option to detect global functions that are not declared in -header files. +header files. In C++, no warnings are issued for function templates, +or for inline functions, or for functions in anonymous namespaces. @item -Wmissing-field-initializers @opindex Wmissing-field-initializers diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 56331b7..1737efd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2006-12-18 Ian Lance Taylor <iant@google.com> + + * g++.dg/warn/Wmissing-declarations-1.C: New test. + 2006-12-17 Eric Botcazou <ebotcazou@libertysurf.fr> * gcc.c-torture/compile/pr27528.c: Use empty templates. diff --git a/gcc/testsuite/g++.dg/warn/Wmissing-declarations-1.C b/gcc/testsuite/g++.dg/warn/Wmissing-declarations-1.C new file mode 100644 index 0000000..8944325 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wmissing-declarations-1.C @@ -0,0 +1,45 @@ +// { dg-options "-Wmissing-declarations" } + +void fn1() { } // { dg-warning "no previous declaration" } +namespace ns { + void fn2() { } // { dg-warning "no previous declaration" } +} +namespace { + void fn3() { } +} +static void fn4() { } + +void fn5(); +namespace ns { + void fn6(); +} + +void fn5() { } +namespace ns { + void fn6() { } +} + +inline void fn7() { } + +class c { + void cfn1() { } + static void cfn2() { } + void cfn3(); + static void cfn4(); +}; + +void c::cfn3() { } +void c::cfn4() { } + +static struct { + void sfn1() { } + static void sfn2() { } +} s; + +template<typename C> +void tfn1() { } + +template void tfn1<c>(); + +class d { }; +template<> void tfn1<d>() { } |