re PR c++/8057 (Templates/non-templates and warnings about statements without effects)

cp/
	PR c++/8057
	* cvt.c (convert_to_void): Don't warn about unused values when
	processing a template declaration.
testsuite/
	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.

From-SVN: r105273
This commit is contained in:
Ian Lance Taylor 2005-10-11 23:30:57 +00:00 committed by Ian Lance Taylor
parent 0257e3837e
commit 55792875db
6 changed files with 31 additions and 4 deletions

View File

@ -1,3 +1,9 @@
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

View File

@ -910,7 +910,10 @@ convert_to_void (tree expr, const char *implicit)
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. */

View File

@ -1,3 +1,11 @@
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

View File

@ -12,7 +12,9 @@ extern "C" void FormatDisk();
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" "" }

View File

@ -76,13 +76,13 @@ template<int I> void Foo (X &x)
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" }

View File

@ -0,0 +1,8 @@
// 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" }