re PR c++/53159 (Missing narrowing check)
/cp 2014-07-11 Paolo Carlini <paolo.carlini@oracle.com> PR c++/53159 * call.c (build_user_type_conversion_1): Copy LOOKUP_NO_NARROWING into convflags. * decl.c (check_initializer): Don't call check_narrowing here, set LOOKUP_NO_NARROWING. * typeck2.c (digest_init_r): Likewise. /testsuite 2014-07-11 Paolo Carlini <paolo.carlini@oracle.com> PR c++/53159 * g++.dg/cpp0x/Wnarrowing1.C: New. From-SVN: r212469
This commit is contained in:
parent
54c61de798
commit
2410819b6d
@ -1,3 +1,12 @@
|
|||||||
|
2014-07-11 Paolo Carlini <paolo.carlini@oracle.com>
|
||||||
|
|
||||||
|
PR c++/53159
|
||||||
|
* call.c (build_user_type_conversion_1): Copy LOOKUP_NO_NARROWING
|
||||||
|
into convflags.
|
||||||
|
* decl.c (check_initializer): Don't call check_narrowing here,
|
||||||
|
set LOOKUP_NO_NARROWING.
|
||||||
|
* typeck2.c (digest_init_r): Likewise.
|
||||||
|
|
||||||
2014-07-10 Jason Merrill <jason@redhat.com>
|
2014-07-10 Jason Merrill <jason@redhat.com>
|
||||||
|
|
||||||
PR c++/61661
|
PR c++/61661
|
||||||
|
@ -3586,7 +3586,8 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags,
|
|||||||
|
|
||||||
/* It's OK to bind a temporary for converting constructor arguments, but
|
/* It's OK to bind a temporary for converting constructor arguments, but
|
||||||
not in converting the return value of a conversion operator. */
|
not in converting the return value of a conversion operator. */
|
||||||
convflags = ((flags & LOOKUP_NO_TEMP_BIND) | LOOKUP_NO_CONVERSION);
|
convflags = ((flags & LOOKUP_NO_TEMP_BIND) | LOOKUP_NO_CONVERSION
|
||||||
|
| (flags & LOOKUP_NO_NARROWING));
|
||||||
flags &= ~LOOKUP_NO_TEMP_BIND;
|
flags &= ~LOOKUP_NO_TEMP_BIND;
|
||||||
|
|
||||||
if (ctors)
|
if (ctors)
|
||||||
|
@ -5756,8 +5756,7 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
init = reshape_init (type, init, tf_warning_or_error);
|
init = reshape_init (type, init, tf_warning_or_error);
|
||||||
if (SCALAR_TYPE_P (type))
|
flags |= LOOKUP_NO_NARROWING;
|
||||||
check_narrowing (type, init);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (TREE_CODE (init) == TREE_LIST
|
else if (TREE_CODE (init) == TREE_LIST
|
||||||
|
@ -1027,7 +1027,7 @@ digest_init_r (tree type, tree init, bool nested, int flags,
|
|||||||
tree *exp;
|
tree *exp;
|
||||||
|
|
||||||
if (nested)
|
if (nested)
|
||||||
check_narrowing (type, init);
|
flags |= LOOKUP_NO_NARROWING;
|
||||||
init = convert_for_initialization (0, type, init, flags,
|
init = convert_for_initialization (0, type, init, flags,
|
||||||
ICR_INIT, NULL_TREE, 0,
|
ICR_INIT, NULL_TREE, 0,
|
||||||
complain);
|
complain);
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
2014-07-11 Paolo Carlini <paolo.carlini@oracle.com>
|
||||||
|
|
||||||
|
PR c++/53159
|
||||||
|
* g++.dg/cpp0x/Wnarrowing1.C: New.
|
||||||
|
|
||||||
2014-07-11 Andreas Schwab <schwab@linux-m68k.org>
|
2014-07-11 Andreas Schwab <schwab@linux-m68k.org>
|
||||||
|
|
||||||
PR preprocessor/61389
|
PR preprocessor/61389
|
||||||
|
18
gcc/testsuite/g++.dg/cpp0x/Wnarrowing1.C
Normal file
18
gcc/testsuite/g++.dg/cpp0x/Wnarrowing1.C
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// PR c++/53159
|
||||||
|
// { dg-do compile { target c++11 } }
|
||||||
|
// { dg-options "-Wnarrowing -Wno-overflow" }
|
||||||
|
|
||||||
|
struct X
|
||||||
|
{
|
||||||
|
constexpr operator int() { return __INT_MAX__; }
|
||||||
|
};
|
||||||
|
|
||||||
|
int f() { return __INT_MAX__; }
|
||||||
|
|
||||||
|
signed char a { __INT_MAX__ }; // { dg-warning "narrowing conversion" }
|
||||||
|
signed char b { f() }; // { dg-warning "narrowing conversion" }
|
||||||
|
signed char c { X{} }; // { dg-warning "narrowing conversion" }
|
||||||
|
|
||||||
|
signed char ar[] { __INT_MAX__ }; // { dg-warning "narrowing conversion" }
|
||||||
|
signed char br[] { f() }; // { dg-warning "narrowing conversion" }
|
||||||
|
signed char cr[] { X{} }; // { dg-warning "narrowing conversion" }
|
Loading…
Reference in New Issue
Block a user