+2005-10-11 Ian Lance Taylor <ian@airs.com>
+
+ PR c++/8057
+ * cvt.c (convert_to_void): Don't warn about unused values when
+ processing a template declaration.
+
2005-10-11 Mark Mitchell <mark@codesourcery.com>
PR c++/21089
if (expr != error_mark_node && !VOID_TYPE_P (TREE_TYPE (expr)))
{
- if (implicit && warn_unused_value && !TREE_NO_WARNING (expr))
+ if (implicit
+ && warn_unused_value
+ && !TREE_NO_WARNING (expr)
+ && !processing_template_decl)
{
/* The middle end does not warn about expressions that have
been explicitly cast to void, so we must do so here. */
+2005-10-11 Ian Lance Taylor <ian@airs.com>
+
+ PR c++/8057
+ * g++.dg/warn/noeffect7.C: New test.
+ * g++.dg/warn/noeffect2.C: Instantiate templates.
+ * g++.dg/warn/noeffect4.C: Instantiate template. Add new error
+ and warning.
+
2005-10-11 Mark Mitchell <mark@codesourcery.com>
PR c++/21089
struct C {
C(){ FormatDisk(), 0; } // { dg-warning "right-hand operand of comma" "" }
};
+ template struct C<int>; // { dg-warning "instantiated" }
template <class T>
void f() { FormatDisk(), 0; } // { dg-warning "right-hand operand of comma" "" }
+ template void f<int> (); // { dg-warning "instantiated" }
void g() { FormatDisk(), 0; } // { dg-warning "right-hand operand of comma" "" }
x->m;
static_cast<int> (x);
dynamic_cast<Y &> (x);
- reinterpret_cast<int> (x.Foo ());
- const_cast<X &> (x.Foo ());
+ reinterpret_cast<int> (x.Foo ()); // { dg-error "invalid cast" }
+ const_cast<X &> (x.Foo ()); // { dg-warning "not used" }
reinterpret_cast<int *> (&x);// { dg-warning "no effect" "" }
const_cast<X &> (x); // { dg-warning "no effect" "" }
sizeof (x++); // { dg-warning "no effect" "" }
__alignof__ (x++); // { dg-warning "no effect" "" }
}
-
+template void Foo<4> (X&); // { dg-warning "instantiated" }
--- /dev/null
+// PR c++/8057
+// Don't give a "statement has no effect" warning when declaring a
+// template, only when instantiating it.
+// { dg-do compile }
+// { dg-options "-Wunused" }
+struct Y { static int i; };
+template <typename T> class X { X() { Y::i; }; };
+class Z { Z() { Y::i; }; }; // { dg-warning "no effect" }