./: * 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
+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.
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
+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
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
{
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
+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.
--- /dev/null
+// { 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>() { }