]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
invoke.texi ([Wnarrowing]): Update for non-constants in C++11.
authorPaolo Carlini <paolo@gcc.gnu.org>
Sat, 9 Aug 2014 08:58:33 +0000 (08:58 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sat, 9 Aug 2014 08:58:33 +0000 (08:58 +0000)
2014-08-09  Paolo Carlini  <paolo.carlini@oracle.com>

* doc/invoke.texi ([Wnarrowing]): Update for non-constants in C++11.

gcc/cp
2014-08-09  Paolo Carlini  <paolo.carlini@oracle.com>

* typeck2.c (check_narrowing): Add tsubst_flags_t parameter, change
return type to bool; in C++11 for constants give errors, not pedwarns.
* cp-tree.h (check_narrowing): Adjust declaration.
* call.c (convert_like_real): Update calls.
* semantics.c (finish_compound_literal): Likewise.

gcc/testsuite
2014-08-09  Paolo Carlini  <paolo.carlini@oracle.com>

* g++.dg/cpp0x/Wnarrowing1.C: Adjust for errors.
* g++.dg/cpp0x/enum29.C: Adjust.

/libstdc++-v3
2014-08-09  Paolo Carlini  <paolo.carlini@oracle.com>

* include/ext/pod_char_traits.h (char_traits<__gnu_cxx::
character<_Value, _Int, _St> >::eof): Fix vs narrowing conversion.

From-SVN: r213776

12 files changed:
gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/semantics.c
gcc/cp/typeck2.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/Wnarrowing1.C
gcc/testsuite/g++.dg/cpp0x/enum29.C
libstdc++-v3/ChangeLog
libstdc++-v3/include/ext/pod_char_traits.h

index c58827ed9ceac3129d153b1ad586f49be620032c..2aa721c9ce26d82c82c79d04ed7ead7ff6ab4c1c 100644 (file)
@@ -1,3 +1,7 @@
+2014-08-09  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * doc/invoke.texi ([Wnarrowing]): Update for non-constants in C++11.
+
 2014-08-09  Roman Gareev  <gareevroman@gmail.com>
 
        * graphite-isl-ast-to-gimple.c:
@@ -20,7 +24,6 @@
 
        * predict.c (expr_expected_value_1): Remove the redundant assignment.
 
-
 2014-08-08  Richard Biener  <rguenther@suse.de>
 
        * lto-streamer.h (struct lto_input_block): Make it a class
 
 2014-08-07  Marek Polacek  <polacek@redhat.com>
 
-       * fold-const.c (fold_binary_loc): Add folding of 
+       * fold-const.c (fold_binary_loc): Add folding of
        (PTR0 - (PTR1 p+ A) -> (PTR0 - PTR1) - A.
 
 2013-08-07  Ilya Enkovich  <ilya.enkovich@intel.com>
 2014-08-05  Roman Gareev  <gareevroman@gmail.com>
 
        * graphite-isl-ast-to-gimple.c: Add a new struct ast_build_info.
-       (translate_isl_ast_for_loop): Add checking of the 
+       (translate_isl_ast_for_loop): Add checking of the
        flag_loop_parallelize_all.
        (ast_build_before_for): New function.
-       (scop_to_isl_ast): Add checking of the 
+       (scop_to_isl_ast): Add checking of the
        flag_loop_parallelize_all.
        * graphite-dependences.c: Move the defenition of the
        scop_get_dependences from graphite-optimize-isl.c to this file.
 
 2014-08-01  Jan Hubicka  <hubicka@ucw.cz>
 
-       * doc/invoke.texi (Wsuggest-final-types, Wsuggest-final-methods): Document.
+       * doc/invoke.texi (Wsuggest-final-types, Wsuggest-final-methods):
+       Document.
        * ipa-devirt.c: Include hash-map.h
        (struct polymorphic_call_target_d): Add type_warning and decl_warning.
        (clear_speculation): Break out of ...
        (odr_type_warn_count, decl_warn_count): New structures.
        (final_warning_record): New structure.
        (final_warning_records): New static variable.
-       (possible_polymorphic_call_targets): Cleanup handling of speculative info;
-       do not build speculation when user do not care; record info about warnings
-       when asked for.
+       (possible_polymorphic_call_targets): Cleanup handling of
+       speculative info; do not build speculation when user do not care;
+       record info about warnings when asked for.
        (add_decl_warning): New function.
        (type_warning_cmp): New function.
        (decl_warning_cmp): New function.
        (ipa_devirt): Handle -Wsuggest-final-methods and -Wsuggest-final-types.
        (gate): Enable pass when warnings are requested.
-       * common.opt (Wsuggest-final-types, Wsuggest-final-methods): New options.
+       * common.opt (Wsuggest-final-types, Wsuggest-final-methods): New
+       options.
 
 2014-08-02  Trevor Saunders  <tsaunders@mozilla.com>
 
index 6d3eda2651ffc4d5e819b8227a366a90042f3eba..47621ca0e868e0f93ae0b1b4a4843480d27a6c16 100644 (file)
@@ -1,3 +1,11 @@
+2014-08-09  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * typeck2.c (check_narrowing): Add tsubst_flags_t parameter, change
+       return type to bool; in C++11 for constants give errors, not pedwarns.
+       * cp-tree.h (check_narrowing): Adjust declaration.
+       * call.c (convert_like_real): Update calls.
+       * semantics.c (finish_compound_literal): Likewise.
+
 2014-08-08  Jason Merrill  <jason@redhat.com>
 
        * pt.c (lookup_template_class_1): Copy abi_tag.
index 4d37c65209febef405477e1452cc6958bac2cf68..64cab453ae0725db632094dd157a385fb02ab252 100644 (file)
@@ -6251,8 +6251,9 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
                                          1, false, false, complain);
            if (sub == error_mark_node)
              return sub;
-           if (!BRACE_ENCLOSED_INITIALIZER_P (val))
-             check_narrowing (TREE_TYPE (sub), val);
+           if (!BRACE_ENCLOSED_INITIALIZER_P (val)
+               && !check_narrowing (TREE_TYPE (sub), val, complain))
+             return error_mark_node;
            CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_ctor), NULL_TREE, sub);
            if (!TREE_CONSTANT (sub))
              TREE_CONSTANT (new_ctor) = false;
@@ -6480,8 +6481,9 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
       break;
     }
 
-  if (convs->check_narrowing)
-    check_narrowing (totype, expr);
+  if (convs->check_narrowing
+      && !check_narrowing (totype, expr, complain))
+    return error_mark_node;
 
   if (issue_conversion_warnings)
     expr = cp_convert_and_check (totype, expr, complain);
index ec79c232ec6d0acadb0f83b72e6009b2855c325b..64049c403d2b0ca6747c518e866c029725f11e85 100644 (file)
@@ -6214,7 +6214,7 @@ extern int abstract_virtuals_error_sfinae (tree, tree, tsubst_flags_t);
 extern int abstract_virtuals_error_sfinae      (abstract_class_use, tree, tsubst_flags_t);
 
 extern tree store_init_value                   (tree, tree, vec<tree, va_gc>**, int);
-extern void check_narrowing                    (tree, tree);
+extern bool check_narrowing                    (tree, tree, tsubst_flags_t);
 extern tree digest_init                                (tree, tree, tsubst_flags_t);
 extern tree digest_init_flags                  (tree, tree, int);
 extern tree digest_nsdmi_init                  (tree, tree);
index 63365c70e1abe2db2bbf993746255e5dc8f09a9e..531927e3bcaafb7d6d612bda4a254cec09679b1d 100644 (file)
@@ -2597,8 +2597,8 @@ finish_compound_literal (tree type, tree compound_literal,
   compound_literal = reshape_init (type, compound_literal, complain);
   if (SCALAR_TYPE_P (type)
       && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
-      && (complain & tf_warning_or_error))
-    check_narrowing (type, compound_literal);
+      && !check_narrowing (type, compound_literal, complain))
+    return error_mark_node;
   if (TREE_CODE (type) == ARRAY_TYPE
       && TYPE_DOMAIN (type) == NULL_TREE)
     {
index 20523faf09b406bf053a8e61135767fdef5bcb30..c985a4bf92c069494867daaabba6e99b00993879 100644 (file)
@@ -842,27 +842,31 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
 }
 
 \f
-/* Give errors about narrowing conversions within { }.  */
+/* Give diagnostic about narrowing conversions within { }.  */
 
-void
-check_narrowing (tree type, tree init)
+bool
+check_narrowing (tree type, tree init, tsubst_flags_t complain)
 {
   tree ftype = unlowered_expr_type (init);
   bool ok = true;
   REAL_VALUE_TYPE d;
 
-  if (!warn_narrowing || !ARITHMETIC_TYPE_P (type))
-    return;
+  if (((!warn_narrowing || !(complain & tf_warning))
+       && cxx_dialect == cxx98)
+      || !ARITHMETIC_TYPE_P (type))
+    return ok;
 
   if (BRACE_ENCLOSED_INITIALIZER_P (init)
       && TREE_CODE (type) == COMPLEX_TYPE)
     {
       tree elttype = TREE_TYPE (type);
       if (CONSTRUCTOR_NELTS (init) > 0)
-        check_narrowing (elttype, CONSTRUCTOR_ELT (init, 0)->value);
+        ok &= check_narrowing (elttype, CONSTRUCTOR_ELT (init, 0)->value,
+                              complain);
       if (CONSTRUCTOR_NELTS (init) > 1)
-       check_narrowing (elttype, CONSTRUCTOR_ELT (init, 1)->value);
-      return;
+       ok &= check_narrowing (elttype, CONSTRUCTOR_ELT (init, 1)->value,
+                              complain);
+      return ok;
     }
 
   init = maybe_constant_value (fold_non_dependent_expr_sfinae (init, tf_none));
@@ -917,15 +921,27 @@ check_narrowing (tree type, tree init)
 
   if (!ok)
     {
-      if (cxx_dialect >= cxx11)
-       pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
-                "narrowing conversion of %qE from %qT to %qT inside { }",
-                init, ftype, type);
-      else
+      if (cxx_dialect == cxx98)
        warning_at (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
                    "narrowing conversion of %qE from %qT to %qT inside { } "
                    "is ill-formed in C++11", init, ftype, type);
+      else if (!TREE_CONSTANT (init))
+       {
+         if (complain & tf_warning_or_error)
+           {
+             pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing,
+                      "narrowing conversion of %qE from %qT to %qT inside { }",
+                      init, ftype, type);
+             ok = true;
+           }
+       }
+      else if (complain & tf_error)
+       error_at (EXPR_LOC_OR_LOC (init, input_location),
+                 "narrowing conversion of %qE from %qT to %qT inside { }",
+                 init, ftype, type);
     }
+
+  return cxx_dialect == cxx98 || ok; 
 }
 
 /* Process the initializer INIT for a variable of type TYPE, emitting
index 4f327df69ebe8ec153ae1db248c8a83b77182f74..35820350d6cb721f49b923969e5a7363a9113739 100644 (file)
@@ -2622,10 +2622,10 @@ int i = @{ 2.2 @}; // error: narrowing from double to int
 
 This flag is included in @option{-Wall} and @option{-Wc++11-compat}.
 
-With @option{-std=c++11}, @option{-Wno-narrowing} suppresses the diagnostic
-required by the standard.  Note that this does not affect the meaning
-of well-formed code; narrowing conversions are still considered
-ill-formed in SFINAE context.
+With @option{-std=c++11}, @option{-Wno-narrowing} suppresses for
+non-constants the diagnostic required by the standard.  Note that this
+does not affect the meaning of well-formed code; narrowing conversions
+are still considered ill-formed in SFINAE context.
 
 @item -Wnoexcept @r{(C++ and Objective-C++ only)}
 @opindex Wnoexcept
index bd881d33d47de3ad91542621783793b69dacb643..073f83780b871f5958f5b9cf0b1ad850cd1ba63b 100644 (file)
@@ -1,3 +1,8 @@
+2014-08-09  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * g++.dg/cpp0x/Wnarrowing1.C: Adjust for errors.
+       * g++.dg/cpp0x/enum29.C: Adjust.
+
 2014-08-08  Richard Biener  <rguenther@suse.de>
 
        * gcc.dg/strlenopt-8.c: Remove XFAIL.
index 634c4c377d0b0ad81c5dd57e7351358fe2ec7f68..4df30255474c465a889025e9643860b8a4570140 100644 (file)
@@ -9,10 +9,10 @@ struct X
 
 int f() { return __INT_MAX__; }
 
-signed char a { __INT_MAX__ };     // { dg-warning "narrowing conversion" }
+signed char a { __INT_MAX__ };     // { dg-error "narrowing conversion" }
 signed char b { f() };             // { dg-warning "narrowing conversion" }
-signed char c { X{} };             // { dg-warning "narrowing conversion" }
+signed char c { X{} };             // { dg-error "narrowing conversion" }
 
-signed char ar[] { __INT_MAX__ };  // { dg-warning "narrowing conversion" }
+signed char ar[] { __INT_MAX__ };  // { dg-error "narrowing conversion" }
 signed char br[] { f() };          // { dg-warning "narrowing conversion" }
-signed char cr[] { X{} };          // { dg-warning "narrowing conversion" }
+signed char cr[] { X{} };          // { dg-error "narrowing conversion" }
index 43a99aee67367a052287de28da6eae656d8a0aae..f24a6a2a958eef774b18356d58d573060c47bdbd 100644 (file)
@@ -51,8 +51,6 @@ enum F5 : int { f5 = X5() };
 enum G0 : signed char { g0 = X0() };
 enum G1 : signed char { g1 = X1() };
 enum G2 : signed char { g2 = X2() };  // { dg-error "narrowing" }
-// { dg-warning "overflow" "" { target *-*-* } 53 }
 enum G3 : signed char { g3 = X3() };  // { dg-error "narrowing" }
-// { dg-warning "overflow" "" { target *-*-* } 55 }
 enum G4 : signed char { g4 = X4() };  // { dg-error "narrowing" }
 enum G5 : signed char { g5 = X5() };  // { dg-error "ambiguous" }
index bd8677ec4736195f8caa648a0a4714090ad5e418..821dfe5c87419633f2f66e2e4be7cb35296d30e5 100644 (file)
@@ -1,3 +1,8 @@
+2014-08-08  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * include/ext/pod_char_traits.h (char_traits<__gnu_cxx::
+       character<_Value, _Int, _St> >::eof): Fix vs narrowing conversion.
+
 2014-08-09  François Dumont  <fdumont@gcc.gnu.org>
 
        PR libstdc++/61667
index e027585e704f32138dafec9bd61ecb354cf41cd3..d6de298a90f43b9e0a86ee6e75eea0d5e8432418 100644 (file)
@@ -177,7 +177,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       static int_type
       eof() 
       {
-       int_type __r = { -1 };
+       int_type __r = { static_cast<typename __gnu_cxx::__conditional_type
+                        <std::__is_integer<int_type>::__value,
+                        int_type, int>::__type>(-1) };
        return __r;
       }