typeck.c (build_binary_op): Do not warn about signed vs.
authorMark Mitchell <mark@codesourcery.com>
Fri, 11 Jul 2003 08:13:58 +0000 (08:13 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Fri, 11 Jul 2003 08:13:58 +0000 (08:13 +0000)
* typeck.c (build_binary_op): Do not warn about signed
vs. unsigned comparisons in the bodies of templates.

* g++.dg/warn/Wsign-compare-1.C: New test.

From-SVN: r69222

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wsign-compare-1.C [new file with mode: 0644]

index 1d64a22e497aab7421becfbb936c80a384ab63fb..5722e9f3d5386452d42f2c262bc742bc5fed568e 100644 (file)
@@ -1,5 +1,8 @@
 2003-07-10  Mark Mitchell  <mark@codesourcery.com>
 
+       * typeck.c (build_binary_op): Do not warn about signed
+       vs. unsigned comparisons in the bodies of templates.
+
        PR c++/9411
        * parser.c (cp_parser_postfix_expression): Check dependency of
        functions.
index 58055eca08b5155dd593e42fa9dae014af99e435..8e1e0df8b7814bf2e6c7c220ac19227b0bd910ca 100644 (file)
@@ -3443,7 +3443,10 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
        }
 
       if ((short_compare || code == MIN_EXPR || code == MAX_EXPR)
-         && warn_sign_compare)
+         && warn_sign_compare
+         /* Do not warn until the template is instantiated; we cannot
+            bound the ranges of the arguments until that point.  */
+         && !processing_template_decl)
        {
          int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
          int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
index f7b1551cca27d7880d28bb79087575dc4915a64c..968a056df178affc4cf41b1be7cd86b8c27de7bf 100644 (file)
@@ -1,3 +1,7 @@
+2003-07-11  Mark Mitchell  <mark@codesourcery.com>
+
+       * g++.dg/warn/Wsign-compare-1.C: New test.
+
 2003-07-10  Kazu Hirata  <kazu@cs.umass.edu>
 
        * gcc.dg/20021018-1.c: Disable if the sizeof (int) < 4.
diff --git a/gcc/testsuite/g++.dg/warn/Wsign-compare-1.C b/gcc/testsuite/g++.dg/warn/Wsign-compare-1.C
new file mode 100644 (file)
index 0000000..495bb99
--- /dev/null
@@ -0,0 +1,6 @@
+// { dg-options "-Wsign-compare" }
+
+extern unsigned u;
+
+template<class F>
+int f() { return u > 1; }