re PR c++/51151 (Invalid -Woverflow warning in C++ frontend)
authorJason Merrill <jason@redhat.com>
Fri, 9 Dec 2011 20:18:22 +0000 (15:18 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 9 Dec 2011 20:18:22 +0000 (15:18 -0500)
PR c++/51151
* call.c (perform_implicit_conversion_flags): Remove earlier kludge.
* parser.c (cp_parser_omp_for_loop): Use cp_parser_omp_for_incr
in templates even if decl isn't type-dependent.

From-SVN: r182175

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Woverflow-4.C [new file with mode: 0644]

index 3698349c1dd90fe041f1837efe02bd9a9bfd546f..80900305319042368fcbaab741b91853ba4665cd 100644 (file)
@@ -1,3 +1,10 @@
+2011-12-09  Jason Merrill  <jason@redhat.com>
+
+       PR c++/51151
+       * call.c (perform_implicit_conversion_flags): Remove earlier kludge.
+       * parser.c (cp_parser_omp_for_loop): Use cp_parser_omp_for_incr
+       in templates even if decl isn't type-dependent.
+
 2011-12-09  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/51289
index d8fc4f1d2d57f7adf84c1917ac1c7d28e737bb9a..65283685a398ba737296aa9fbb6c0b0cbb4a46a3 100644 (file)
@@ -8437,10 +8437,7 @@ perform_implicit_conversion_flags (tree type, tree expr, tsubst_flags_t complain
        }
       expr = error_mark_node;
     }
-  else if (processing_template_decl
-          /* As a kludge, we always perform conversions between scalar
-             types, as IMPLICIT_CONV_EXPR confuses c_finish_omp_for.  */
-          && !(SCALAR_TYPE_P (type) && SCALAR_TYPE_P (TREE_TYPE (expr))))
+  else if (processing_template_decl && conv->kind != ck_identity)
     {
       /* In a template, we are only concerned about determining the
         type of non-dependent expressions, so we do not have to
index 5952a0f67f3fdca1528df2846f2407b3c36823c8..2985d765a9f3ed70f11df3f23213f0ba2c08e57c 100644 (file)
@@ -26305,7 +26305,7 @@ cp_parser_omp_for_loop (cp_parser *parser, tree clauses, tree *par_clauses)
          /* If decl is an iterator, preserve the operator on decl
             until finish_omp_for.  */
          if (decl
-             && ((type_dependent_expression_p (decl)
+             && ((processing_template_decl
                   && !POINTER_TYPE_P (TREE_TYPE (decl)))
                  || CLASS_TYPE_P (TREE_TYPE (decl))))
            incr = cp_parser_omp_for_incr (parser, decl);
index 2430c7f273d4b602f1455c310633b2fa7751893a..5c3e51baa99ff3c5d95fa1ae148dbe0606c24948 100644 (file)
@@ -1,3 +1,8 @@
+2011-12-09  Jason Merrill  <jason@redhat.com>
+
+       PR c++/51151
+       * g++.dg/warn/Woverflow-4.C: New.
+
 2011-12-09  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/51289
diff --git a/gcc/testsuite/g++.dg/warn/Woverflow-4.C b/gcc/testsuite/g++.dg/warn/Woverflow-4.C
new file mode 100644 (file)
index 0000000..1595bca
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/51151
+// { dg-options "-Wshadow" }
+
+template<typename T> class C {
+public:
+  void f() {
+    m = c2 + 1;
+  }
+  static const long unsigned int c1 = 7;
+  static const int c2 = c1 - 1;
+  int m;
+};
+template class C<int>;