cp/
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 11 Oct 2005 23:30:57 +0000 (23:30 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 11 Oct 2005 23:30:57 +0000 (23:30 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@105273 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/cvt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/noeffect2.C
gcc/testsuite/g++.dg/warn/noeffect4.C
gcc/testsuite/g++.dg/warn/noeffect7.C [new file with mode: 0644]

index 99ea5ec..a544cfa 100644 (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
index ac24e0a..ea3c496 100644 (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.  */
index b626cdd..39ea01a 100644 (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
index 7bd2925..69adf39 100644 (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" "" }
 
index a4c46da..7b051dd 100644 (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" }
diff --git a/gcc/testsuite/g++.dg/warn/noeffect7.C b/gcc/testsuite/g++.dg/warn/noeffect7.C
new file mode 100644 (file)
index 0000000..4aca249
--- /dev/null
@@ -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" }