re PR c++/45378 ([C++0x] Narrowing error not detected)
authorJason Merrill <jason@redhat.com>
Thu, 16 Jun 2011 22:09:20 +0000 (18:09 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 16 Jun 2011 22:09:20 +0000 (18:09 -0400)
PR c++/45378
* decl.c (check_initializer): Check narrowing.

From-SVN: r175122

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/initlist52.C [new file with mode: 0644]

index 000a78149a4198cea161129174a939320adc1c86..36393023df03d34c48248975797e96a8419f6b7d 100644 (file)
@@ -1,5 +1,8 @@
 2011-06-16  Jason Merrill  <jason@redhat.com>
 
+       PR c++/45378
+       * decl.c (check_initializer): Check narrowing.
+
        PR c++/49229
        * pt.c (tsubst_decl) [FUNCTION_DECL]: Handle substitution failure.
 
index 29edbe3865c463fed1f26891442e8fd5ad90153a..0584cd8f6f71fe7188ad7c10c54c94fc009e390a 100644 (file)
@@ -5464,7 +5464,11 @@ check_initializer (tree decl, tree init, int flags, tree *cleanup)
              init = error_mark_node;
            }
          else
-           init = reshape_init (type, init, tf_warning_or_error);          
+           {
+             init = reshape_init (type, init, tf_warning_or_error);
+             if (cxx_dialect >= cxx0x && SCALAR_TYPE_P (type))
+               check_narrowing (type, init);
+           }
        }
 
       /* If DECL has an array type without a specific bound, deduce the
index 0da84e5642dfb46a9812069ba63f6438e70c4d7f..f8b82beb24de89613057dfb420a5c63c8cd60794 100644 (file)
@@ -1,5 +1,8 @@
 2011-06-16  Jason Merrill  <jason@redhat.com>
 
+       PR c++/45378
+       * g++.dg/cpp0x/initlist52.C New.
+
        PR c++/45399
        * c-c++-common/raw-string-12.c: New.
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist52.C b/gcc/testsuite/g++.dg/cpp0x/initlist52.C
new file mode 100644 (file)
index 0000000..22bc287
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/45378
+// { dg-options -std=c++0x }
+
+int main()
+{
+   int x { 22.2 };             // { dg-error "narrowing" }
+}