diff mbox

C++ PATCH for c++/51151 (bogus -Woverflow)

Message ID 4EE26D01.8010904@redhat.com
State New
Headers show

Commit Message

Jason Merrill Dec. 9, 2011, 8:18 p.m. UTC
This was caused by my earlier kludge to build normal conversions between 
scalar types in templates; the instantiation code isn't prepared to deal 
with all the various tree forms that can occur that way.  So now I've 
limited it to the identity conversion, which shouldn't require any added 
trees at all.

The OMP change was necessary to avoid problems with some OMP tests 
complaining about IMPLICIT_CONV_EXPR in increment expressions.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 03cb051073127d8189fb1800bb1e72d2907937ac
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Dec 8 15:22:53 2011 -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.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index d8fc4f1..6528368 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -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
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 5952a0f..2985d76 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -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);
diff --git a/gcc/testsuite/g++.dg/warn/Woverflow-4.C b/gcc/testsuite/g++.dg/warn/Woverflow-4.C
new file mode 100644
index 0000000..1595bca
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Woverflow-4.C
@@ -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>;