---
Bootstrapped and tested on x86_64-pc-linux-gnu (Debian 13).
No new regressions compared with the unmodified baseline.
gcc/cp/typeck2.cc | 16 ++---
gcc/testsuite/c-c++-common/gomp/allocate-5.c | 2 +-
gcc/testsuite/g++.dg/cpp/embed-7.C | 2 +-
gcc/testsuite/g++.dg/cpp0x/Wnarrowing17.C | 6 +-
gcc/testsuite/g++.dg/cpp0x/initlist5.C | 2 +-
.../g++.dg/cpp1z/direct-enum-init1.C | 60 +++++++++----------
gcc/testsuite/g++.dg/cpp26/aggr-init2.C | 2 +-
gcc/testsuite/g++.dg/cpp26/pack-indexing2.C | 2 +-
.../diagnostic/narrowing-pr69864-constexpr.C | 27 +++++++++
.../diagnostic/narrowing-pr69864-cxx98.C | 19 ++++++
.../g++.dg/diagnostic/narrowing-pr69864.C | 47 +++++++++++++++
gcc/testsuite/g++.dg/ext/char8_t-limits-1.C | 2 +-
.../aarch64/sve/acle/general/cops_bool.c | 2 +-
13 files changed, 142 insertions(+), 47 deletions(-)
create mode 100644
gcc/testsuite/g++.dg/diagnostic/narrowing-pr69864-constexpr.C
create mode 100644 gcc/testsuite/g++.dg/diagnostic/narrowing-pr69864-cxx98.C
create mode 100644 gcc/testsuite/g++.dg/diagnostic/narrowing-pr69864.C
diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc
index c7ebd080edc..376e98b7596 100644
--- a/gcc/cp/typeck2.cc
+++ b/gcc/cp/typeck2.cc
@@ -1345,9 +1345,10 @@ check_narrowing (tree type, tree init, tsubst_flags_t
complain,
if (cxx_dialect == cxx98)
{
if (complain & tf_warning)
- warning_at (loc, OPT_Wnarrowing, "narrowing conversion of %qE "
- "from %qH to %qI is ill-formed in C++11",
- init, ftype, type);
+ warning_at (loc, OPT_Wnarrowing,
+ "narrowing conversion from %qH to %qI "
+ "is ill-formed in C++11",
+ ftype, type);
ok = true;
}
else if (!CONSTANT_CLASS_P (init))
@@ -1357,8 +1358,8 @@ check_narrowing (tree type, tree init, tsubst_flags_t
complain,
auto_diagnostic_group d;
if ((!almost_ok || pedantic)
&& pedwarn (loc, OPT_Wnarrowing,
- "narrowing conversion of %qE from %qH to %qI",
- init, ftype, type)
+ "narrowing conversion from %qH to %qI",
+ ftype, type)
&& almost_ok)
inform (loc, " the expression has a constant value but is not "
"a C++ constant-expression");
@@ -1369,8 +1370,9 @@ check_narrowing (tree type, tree init, tsubst_flags_t
complain,
{
int savederrorcount = errorcount;
permerror_opt (loc, OPT_Wnarrowing,
- "narrowing conversion of %qE from %qH to %qI",
- init, ftype, type);
+ "narrowing conversion of constant expression "
+ "from %qH to %qI",
+ ftype, type);
if (errorcount == savederrorcount)
ok = true;
}
diff --git a/gcc/testsuite/c-c++-common/gomp/allocate-5.c
b/gcc/testsuite/c-c++-common/gomp/allocate-5.c
index b34f9ea9227..431e2bc51a3 100644
--- a/gcc/testsuite/c-c++-common/gomp/allocate-5.c
+++ b/gcc/testsuite/c-c++-common/gomp/allocate-5.c
@@ -72,5 +72,5 @@ align_test2 ()
/* { dg-error "'align' clause argument needs to be positive constant power of two integer
expression" "" { target *-*-* } .-3 } */
#pragma omp allocate(i2) align ( 31 ) /* { dg-error "'align' clause argument
needs to be positive constant power of two integer expression" } */
#pragma omp allocate(i3) align ( -32 ) /* { dg-error "'align' clause argument
needs to be positive constant power of two integer expression" } */
- /* { dg-bogus "narrowing conversion of '-32' from" "" { target c++ xfail
c++11 } .-1 } */
+ /* { dg-bogus "narrowing conversion of constant expression from" "" { target
c++ xfail c++11 } .-1 } */
}
diff --git a/gcc/testsuite/g++.dg/cpp/embed-7.C
b/gcc/testsuite/g++.dg/cpp/embed-7.C
index ac88b827747..4a18325e93a 100644
--- a/gcc/testsuite/g++.dg/cpp/embed-7.C
+++ b/gcc/testsuite/g++.dg/cpp/embed-7.C
@@ -4,4 +4,4 @@
const signed char a[] = {
#embed __FILE__
-}; // { dg-error "narrowing conversion of '\[12]\[0-9]\[0-9]' from 'int' to
'const signed char'" }
+}; // { dg-error "narrowing conversion of constant expression from 'int' to
'const signed char'" }
diff --git a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing17.C
b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing17.C
index 064de531cb3..cef4e6bb91b 100644
--- a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing17.C
+++ b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing17.C
@@ -5,8 +5,8 @@ void f(int i, char c, unsigned u)
{
switch (i)
{
- case 2149056512u:; // { dg-error "narrowing conversion of .2149056512. from
.unsigned int. to .int." }
- case (long long int) 1e10:; // { dg-error "narrowing conversion of
.10000000000. from .long long int. to .int." }
+ case 2149056512u:; // { dg-error "narrowing conversion of constant expression
from .unsigned int. to .int." }
+ case (long long int) 1e10:; // { dg-error "narrowing conversion of constant
expression from .long long int. to .int." }
// { dg-warning "overflow in conversion" "overflow" { target *-*-* } .-1 }
}
@@ -15,5 +15,5 @@ void f(int i, char c, unsigned u)
case 300:; // { dg-warning "exceeds maximum value for type" }
switch (u)
- case -42:; // { dg-error "narrowing conversion of .-42. from .int. to .unsigned
int." }
+ case -42:; // { dg-error "narrowing conversion of constant expression from
.int. to .unsigned int." }
}
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist5.C
b/gcc/testsuite/g++.dg/cpp0x/initlist5.C
index 5f128582014..ec7247dc38f 100644
--- a/gcc/testsuite/g++.dg/cpp0x/initlist5.C
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist5.C
@@ -22,7 +22,7 @@ int k {}; // initialize to 0
// PR c++/36963
double d = 1.1;
-float fa[] = { d, 1.1 }; // { dg-error "narrowing conversion of 'd'" }
+float fa[] = { d, 1.1 }; // { dg-error "narrowing conversion from 'double' to
'float'" }
constexpr double d2 = 1.1;
float fa2[] = { d2, 1.1 };
diff --git a/gcc/testsuite/g++.dg/cpp1z/direct-enum-init1.C
b/gcc/testsuite/g++.dg/cpp1z/direct-enum-init1.C
index 027bd5e2083..b1be58876a0 100644
--- a/gcc/testsuite/g++.dg/cpp1z/direct-enum-init1.C
+++ b/gcc/testsuite/g++.dg/cpp1z/direct-enum-init1.C
@@ -29,34 +29,34 @@ foo ()
D d6 { G }; // { dg-error "cannot convert 'A' to 'D' in initialization"
"" { target c++14_down } }
E e1 { 5 }; // { dg-error "cannot convert 'int' to 'E' in initialization"
"" { target c++14_down } }
E e2 { -1 }; // { dg-error "cannot convert 'int' to 'E' in initialization"
"" { target c++14_down } }
- // { dg-error "narrowing conversion of '-1' from 'int' to 'unsigned
char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from 'int'
to 'unsigned char'" "" { target c++17 } .-1 }
E e3 { 5.0 }; // { dg-error "cannot convert 'double' to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '5.0e.0' from 'double' to
'unsigned char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'double' to 'unsigned char'" "" { target c++17 } .-1 }
E e4 { 5.2 }; // { dg-error "cannot convert 'double' to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '5.\[0-9]*e.0' from 'double' to
'unsigned char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'double' to 'unsigned char'" "" { target c++17 } .-1 }
B b2 = { 7 }; // { dg-error "invalid conversion from 'int' to
'B'" }
C c2 = { C { 8 } }; // { dg-error "cannot convert 'int' to 'C' in initialization"
"" { target c++14_down } }
D *d7 = new D { 9 }; // { dg-error "cannot convert \[^\n\r]* to 'D' in
initialization" "" { target c++14_down } }
E *e5 = new E { -4 }; // { dg-error "cannot convert \[^\n\r]* to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '-4' from 'int' to 'unsigned
char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from 'int'
to 'unsigned char'" "" { target c++17 } .-1 }
bar ({ 10 }); // { dg-error "cannot convert \[^\n\r]* to
'E'" }
bar (E { 9 }); // { dg-error "cannot convert 'int' to 'E' in initialization"
"" { target c++14_down } }
V v1 = { { 11 } }; // { dg-error "cannot convert '<brace-enclosed initializer
list>' to 'E' in initialization" }
V v2 = { E { 12 } }; // { dg-error "cannot convert 'int' to 'E' in initialization"
"" { target c++14_down } }
V v3 = { E { 5.0 } }; // { dg-error "cannot convert 'double' to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '5.0e.0' from 'double' to
'unsigned char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'double' to 'unsigned char'" "" { target c++17 } .-1 }
V v4 = { 13 }; // { dg-error "cannot convert 'int' to 'E' in
initialization" }
if (B b3 { 5 }) // { dg-error "invalid conversion from 'int' to 'B'"
"" { target c++14_down } }
;
if (B b4 { 4.0 }) // { dg-error "cannot convert 'double' to 'B' in initialization"
"" { target c++14_down } }
- ; // { dg-error "narrowing conversion of '4.0e.0' from 'double' to
'short int'" "" { target c++17 } .-1 }
+ ; // { dg-error "narrowing conversion of constant expression from
'double' to 'short int'" "" { target c++17 } .-1 }
C c3 { 8L }; // { dg-error "cannot convert 'long int' to 'C' in
initialization" "" { target c++14_down } }
B b4 {short (c + 5)}; // { dg-error "invalid conversion from 'short int' to
'B'" "" { target c++14_down } }
B b5 {c + 5}; // { dg-error "invalid conversion from 'int' to 'B'"
"" { target c++14_down } }
- // { dg-error "narrowing conversion of \[^\n\r]* from 'int' to 'short
int'" "" { target { c++17 && { ! short_eq_int } } } .-1 }
+ // { dg-error "narrowing conversion from 'int' to 'short int'"
"" { target { c++17 && { ! short_eq_int } } } .-1 }
C c4 { ll }; // { dg-error "cannot convert 'long long int' to 'C' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of 'll' from 'long long int' to
'int'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion from 'long long int' to
'int'" "" { target c++17 } .-1 }
C c5 {short (c + 5)}; // { dg-error "cannot convert 'short int' to 'C' in
initialization" "" { target c++14_down } }
C c6 {c + 5}; // { dg-error "cannot convert 'int' to 'C' in
initialization" "" { target c++14_down } }
}
@@ -65,7 +65,7 @@ struct U
{
U () : e { 5 } {} // { dg-error "cannot convert \[^\n\r]* to 'E' in
initialization" "" { target c++14_down } }
U (int) : e { 5.0 } {}// { dg-error "cannot convert \[^\n\r]* to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '5.0e.0' from 'double' to
'unsigned char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'double' to 'unsigned char'" "" { target c++17 } .-1 }
U (float) : e({ 6 }) {}// { dg-error "list-initializer for non-class type must
not be parenthesized" }
// { dg-error "cannot convert \[^\n\r]* to 'E' in
initialization" "" { target *-*-* } .-1 }
E e;
@@ -76,7 +76,7 @@ struct W
A a { 5 }; // { dg-error "invalid conversion from 'int' to 'A'" }
B b { 6 }; // { dg-error "invalid conversion from 'int' to 'B'"
"" { target c++14_down } }
C c { 3.0f }; // { dg-error "cannot convert \[^\n\r]* to 'C' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '3.0e.0f' from 'float' to
'int'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'float' to 'int'" "" { target c++17 } .-1 }
D d = { 7 }; // { dg-error "cannot convert \[^\n\r]* to 'D' in
initialization" }
};
@@ -96,33 +96,33 @@ foo2 ()
D d6 { G }; // { dg-error "cannot convert 'A' to 'D' in initialization"
"" { target c++14_down } }
E e1 { 5 }; // { dg-error "cannot convert 'int' to 'E' in initialization"
"" { target c++14_down } }
E e2 { -1 }; // { dg-error "cannot convert 'int' to 'E' in initialization"
"" { target c++14_down } }
- // { dg-error "narrowing conversion of '-1' from 'int' to 'unsigned
char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from 'int'
to 'unsigned char'" "" { target c++17 } .-1 }
E e3 { 5.0 }; // { dg-error "cannot convert 'double' to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '5.0e.0' from 'double' to
'unsigned char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'double' to 'unsigned char'" "" { target c++17 } .-1 }
E e4 { 5.2 }; // { dg-error "cannot convert 'double' to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '5.\[0-9]*e.0' from 'double' to
'unsigned char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'double' to 'unsigned char'" "" { target c++17 } .-1 }
B b2 = { 7 }; // { dg-error "invalid conversion from 'int' to
'B'" }
C c2 = { C { 8 } }; // { dg-error "cannot convert 'int' to 'C' in initialization"
"" { target c++14_down } }
D *d7 = new D { 9 }; // { dg-error "cannot convert \[^\n\r]* to 'D' in
initialization" "" { target c++14_down } }
E *e5 = new E { -4 }; // { dg-error "cannot convert \[^\n\r]* to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '-4' from 'int' to 'unsigned
char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from 'int'
to 'unsigned char'" "" { target c++17 } .-1 }
bar ({ 10 }); // { dg-error "cannot convert \[^\n\r]* to
'E'" }
bar (E { 9 }); // { dg-error "cannot convert 'int' to 'E' in initialization"
"" { target c++14_down } }
V v1 = { { 11 } }; // { dg-error "cannot convert '<brace-enclosed initializer
list>' to 'E' in initialization" }
V v2 = { E { 12 } }; // { dg-error "cannot convert 'int' to 'E' in initialization"
"" { target c++14_down } }
V v3 = { E { 5.0 } }; // { dg-error "cannot convert 'double' to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '5.0e.0' from 'double' to
'unsigned char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'double' to 'unsigned char'" "" { target c++17 } .-1 }
V v4 = { 13 }; // { dg-error "cannot convert 'int' to 'E' in
initialization" }
if (B b3 { 5 }) // { dg-error "invalid conversion from 'int' to 'B'"
"" { target c++14_down } }
;
if (B b4 { 4.0 }) // { dg-error "cannot convert 'double' to 'B' in initialization"
"" { target c++14_down } }
- ; // { dg-error "narrowing conversion of '4.0e.0' from 'double' to
'short int'" "" { target c++17 } .-1 }
+ ; // { dg-error "narrowing conversion of constant expression from
'double' to 'short int'" "" { target c++17 } .-1 }
C c3 { 8L }; // { dg-error "cannot convert 'long int' to 'C' in
initialization" "" { target c++14_down } }
B b4 {short (c + 5)}; // { dg-error "invalid conversion from 'short int' to
'B'" "" { target c++14_down } }
B b5 {c + 5}; // { dg-error "invalid conversion from 'int' to 'B'"
"" { target c++14_down } }
- // { dg-error "narrowing conversion of \[^\n\r]* from 'int' to 'short
int'" "" { target { c++17 && { ! short_eq_int } } } .-1 }
+ // { dg-error "narrowing conversion from 'int' to 'short int'"
"" { target { c++17 && { ! short_eq_int } } } .-1 }
C c4 { ll }; // { dg-error "cannot convert 'long long int' to 'C' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of 'll' from 'long long int' to
'int'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion from 'long long int' to
'int'" "" { target c++17 } .-1 }
C c5 {short (c + 5)}; // { dg-error "cannot convert 'short int' to 'C' in
initialization" "" { target c++14_down } }
C c6 {c + 5}; // { dg-error "cannot convert 'int' to 'C' in
initialization" "" { target c++14_down } }
}
@@ -132,7 +132,7 @@ struct U2
{
U2 () : e { 5 } {} // { dg-error "cannot convert \[^\n\r]* to 'E' in
initialization" "" { target c++14_down } }
U2 (int) : e { 5.0 } {}// { dg-error "cannot convert \[^\n\r]* to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '5.0e.0' from 'double' to
'unsigned char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'double' to 'unsigned char'" "" { target c++17 } .-1 }
U2 (float) : e({ 6 }) {}
E e;
};
@@ -143,7 +143,7 @@ struct W2
A a { 5 }; // { dg-error "invalid conversion from 'int' to 'A'"
"" { target *-*-* } }
B b { 6 }; // { dg-error "invalid conversion from 'int' to 'B'"
"" { target c++14_down } }
C c { 3.0f }; // { dg-error "cannot convert \[^\n\r]* to 'C' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '3.0e.0f' from 'float' to
'int'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'float' to 'int'" "" { target c++17 } .-1 }
D d = { 7 }; // { dg-error "cannot convert \[^\n\r]* to 'D' in
initialization" "" { target *-*-* } }
};
@@ -164,33 +164,33 @@ foo3 ()
K d6 { G }; // { dg-error "cannot convert 'A' to 'D' in initialization"
"" { target c++14_down } }
L e1 { 5 }; // { dg-error "cannot convert 'int' to 'E' in initialization"
"" { target c++14_down } }
L e2 { -1 }; // { dg-error "cannot convert 'int' to 'E' in initialization"
"" { target c++14_down } }
- // { dg-error "narrowing conversion of '-1' from 'int' to 'unsigned
char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from 'int'
to 'unsigned char'" "" { target c++17 } .-1 }
L e3 { 5.0 }; // { dg-error "cannot convert 'double' to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '5.0e.0' from 'double' to
'unsigned char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'double' to 'unsigned char'" "" { target c++17 } .-1 }
L e4 { 5.2 }; // { dg-error "cannot convert 'double' to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '5.\[0-9]*e.0' from 'double' to
'unsigned char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'double' to 'unsigned char'" "" { target c++17 } .-1 }
I b2 = { 7 }; // { dg-error "invalid conversion from 'int' to
'B'" }
J c2 = { J { 8 } }; // { dg-error "cannot convert 'int' to 'C' in initialization"
"" { target c++14_down } }
K *d7 = new K { 9 }; // { dg-error "cannot convert \[^\n\r]* to 'D' in
initialization" "" { target c++14_down } }
L *e5 = new L { -4 }; // { dg-error "cannot convert \[^\n\r]* to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '-4' from 'int' to 'unsigned
char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from 'int'
to 'unsigned char'" "" { target c++17 } .-1 }
bar3 ({ 10 }); // { dg-error "cannot convert \[^\n\r]* to 'E'" }
bar3 (E { 9 }); // { dg-error "cannot convert 'int' to 'E' in initialization"
"" { target c++14_down } }
M v1 = { { 11 } }; // { dg-error "cannot convert '<brace-enclosed initializer
list>' to 'E' in initialization" }
M v2 = { L { 12 } }; // { dg-error "cannot convert 'int' to 'E' in initialization"
"" { target c++14_down } }
M v3 = { L { 5.0 } }; // { dg-error "cannot convert 'double' to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '5.0e.0' from 'double' to
'unsigned char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'double' to 'unsigned char'" "" { target c++17 } .-1 }
M v4 = { 13 }; // { dg-error "cannot convert 'int' to 'E' in
initialization" }
if (I b3 { 5 }) // { dg-error "invalid conversion from 'int' to 'B'"
"" { target c++14_down } }
;
if (I b4 { 4.0 }) // { dg-error "cannot convert 'double' to 'B' in initialization"
"" { target c++14_down } }
- ; // { dg-error "narrowing conversion of '4.0e.0' from 'double' to
'short int'" "" { target c++17 } .-1 }
+ ; // { dg-error "narrowing conversion of constant expression from
'double' to 'short int'" "" { target c++17 } .-1 }
J c3 { 8L }; // { dg-error "cannot convert 'long int' to 'C' in
initialization" "" { target c++14_down } }
I b4 {short (c + 5)}; // { dg-error "invalid conversion from 'short int' to
'B'" "" { target c++14_down } }
I b5 {c + 5}; // { dg-error "invalid conversion from 'int' to 'B'"
"" { target c++14_down } }
- // { dg-error "narrowing conversion of \[^\n\r]* from 'int' to 'short
int'" "" { target { c++17 && { ! short_eq_int } } } .-1 }
+ // { dg-error "narrowing conversion from 'int' to 'short int'"
"" { target { c++17 && { ! short_eq_int } } } .-1 }
J c4 { ll }; // { dg-error "cannot convert 'long long int' to 'C' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of 'll' from 'long long int' to
'int'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion from 'long long int' to
'int'" "" { target c++17 } .-1 }
J c5 {short (c + 5)}; // { dg-error "cannot convert 'short int' to 'C' in
initialization" "" { target c++14_down } }
J c6 {c + 5}; // { dg-error "cannot convert 'int' to 'C' in
initialization" "" { target c++14_down } }
}
@@ -200,7 +200,7 @@ struct U3
{
U3 () : e { 5 } {} // { dg-error "cannot convert \[^\n\r]* to 'E' in
initialization" "" { target c++14_down } }
U3 (int) : e { 5.0 } {}// { dg-error "cannot convert \[^\n\r]* to 'E' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '5.0e.0' from 'double' to
'unsigned char'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'double' to 'unsigned char'" "" { target c++17 } .-1 }
U3 (float) : e({ 6 }) {}
L e;
};
@@ -211,7 +211,7 @@ struct W3
H a { 5 }; // { dg-error "invalid conversion from 'int' to 'A'"
"" { target *-*-* } }
I b { 6 }; // { dg-error "invalid conversion from 'int' to 'B'"
"" { target c++14_down } }
J c { 3.0f }; // { dg-error "cannot convert \[^\n\r]* to 'C' in
initialization" "" { target c++14_down } }
- // { dg-error "narrowing conversion of '3.0e.0f' from 'float' to
'int'" "" { target c++17 } .-1 }
+ // { dg-error "narrowing conversion of constant expression from
'float' to 'int'" "" { target c++17 } .-1 }
K d = { 7 }; // { dg-error "cannot convert \[^\n\r]* to 'D' in
initialization" "" { target *-*-* } }
};
diff --git a/gcc/testsuite/g++.dg/cpp26/aggr-init2.C
b/gcc/testsuite/g++.dg/cpp26/aggr-init2.C
index fa3ef39d33f..54162912ab0 100644
--- a/gcc/testsuite/g++.dg/cpp26/aggr-init2.C
+++ b/gcc/testsuite/g++.dg/cpp26/aggr-init2.C
@@ -11,7 +11,7 @@ namespace N1 {
};
int x;
};
- constexpr C c2 = { .a = 42.0, .x = 3 }; // { dg-error "narrowing conversion of
'4.2e\\\+1' from 'double' to 'int'" "" { target c++20 } }
+ constexpr C c2 = { .a = 42.0, .x = 3 }; // { dg-error "narrowing conversion of
constant expression from 'double' to 'int'" "" { target c++20 } }
#endif
}
diff --git a/gcc/testsuite/g++.dg/cpp26/pack-indexing2.C
b/gcc/testsuite/g++.dg/cpp26/pack-indexing2.C
index a1dea4f5bfc..1734358fcea 100644
--- a/gcc/testsuite/g++.dg/cpp26/pack-indexing2.C
+++ b/gcc/testsuite/g++.dg/cpp26/pack-indexing2.C
@@ -77,7 +77,7 @@ template<auto N, typename... Ts>
void
badtype4 ()
{
- Ts...[N] t; // { dg-error "narrowing conversion of '-1' from 'int' to" }
+ Ts...[N] t; // { dg-error "narrowing conversion of constant expression from 'int'
to" }
}
int nonconst () { return 42; }
diff --git a/gcc/testsuite/g++.dg/diagnostic/narrowing-pr69864-constexpr.C
b/gcc/testsuite/g++.dg/diagnostic/narrowing-pr69864-constexpr.C
new file mode 100644
index 00000000000..20a7ddd2353
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/narrowing-pr69864-constexpr.C
@@ -0,0 +1,27 @@
+// PR c++/69864
+// { dg-do compile }
+// { dg-options "-std=c++20" }
+
+// Verify that constant and non-constant expressions produce
+// distinct narrowing diagnostics.
+
+const double a = 3.5;
+constexpr double b = 3.5;
+
+double f ()
+{
+ return 3.5;
+}
+
+constexpr double g ()
+{
+ return 3.5;
+}
+
+void test ()
+{
+ int x{a}; // { dg-warning "narrowing conversion from 'double' to 'int'" }
+ int y{b}; // { dg-error "narrowing conversion of constant expression" }
+ int z{f ()}; // { dg-warning "narrowing conversion from 'double' to 'int'" }
+ int w{g ()}; // { dg-error "narrowing conversion of constant expression" }
+}
diff --git a/gcc/testsuite/g++.dg/diagnostic/narrowing-pr69864-cxx98.C
b/gcc/testsuite/g++.dg/diagnostic/narrowing-pr69864-cxx98.C
new file mode 100644
index 00000000000..f97e69f3bd6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/narrowing-pr69864-cxx98.C
@@ -0,0 +1,19 @@
+// PR c++/69864
+// { dg-do compile }
+// { dg-options "-std=c++98 -Wnarrowing -fdiagnostics-show-caret
-fno-diagnostics-show-line-numbers" }
+
+// Verify narrowing diagnostics in C++98 mode.
+
+double x = 3.5;
+
+int a[] = {3.5}; // { dg-warning "narrowing conversion from 'double' to 'int' is
ill-formed in C\\+\\+11" }
+/* { dg-begin-multiline-output "" }
+ int a[] = {3.5};
+ ^~~
+ { dg-end-multiline-output "" } */
+
+int b[] = {x}; // { dg-warning "narrowing conversion from 'double' to 'int' is
ill-formed in C\\+\\+11" }
+/* { dg-begin-multiline-output "" }
+ int b[] = {x};
+ ^
+ { dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/g++.dg/diagnostic/narrowing-pr69864.C
b/gcc/testsuite/g++.dg/diagnostic/narrowing-pr69864.C
new file mode 100644
index 00000000000..13ad6f3e727
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/narrowing-pr69864.C
@@ -0,0 +1,47 @@
+// PR c++/69864
+// { dg-do compile }
+// { dg-options "-std=c++20 -fdiagnostics-show-caret
-fno-diagnostics-show-line-numbers" }
+
+// Verify that narrowing diagnostics highlight the original source
+// expression rather than its folded value.
+
+constexpr double x = 3.5;
+
+constexpr double f ()
+{
+ return x + 0.5;
+}
+
+int a{x + 0.5};
+// { dg-error "narrowing conversion of constant expression from 'double' to 'int'"
"" { target *-*-* } .-1 }
+/* { dg-begin-multiline-output "" }
+ int a{x + 0.5};
+ ~~^~~~~
+ { dg-end-multiline-output "" } */
+
+int b{f() + 1.0};
+// { dg-error "narrowing conversion of constant expression from 'double' to 'int'"
"" { target *-*-* } .-1 }
+/* { dg-begin-multiline-output "" }
+ int b{f() + 1.0};
+ ~~~~^~~~~
+ { dg-end-multiline-output "" } */
+
+template <typename T>
+void g (T v)
+{
+ int e{v + 0.5};
+ // { dg-warning "narrowing conversion from 'double' to 'int'" "" { target
*-*-* } .-1 }
+ /* { dg-begin-multiline-output "" }
+ int e{v + 0.5};
+ ~~^~~~~
+ { dg-end-multiline-output "" } */
+}
+
+void h ()
+{
+ g (3.5);
+ /* { dg-begin-multiline-output "" }
+ g (3.5);
+ ~~^~~~~
+ { dg-end-multiline-output "" } */
+}
diff --git a/gcc/testsuite/g++.dg/ext/char8_t-limits-1.C
b/gcc/testsuite/g++.dg/ext/char8_t-limits-1.C
index 0d6df34d23f..288c545b391 100644
--- a/gcc/testsuite/g++.dg/ext/char8_t-limits-1.C
+++ b/gcc/testsuite/g++.dg/ext/char8_t-limits-1.C
@@ -6,4 +6,4 @@
static_assert(u8'\xFF' == 0xFF, "Error");
static_assert(u8"\xFF"[0] == 0xFF, "Error");
static_assert(char8_t(-1) >= 0, "Error");
-static_assert(char8_t{-1} >= 0, "Error"); // { dg-error "narrowing conversion of .-1. from
.int. to .char8_t." "char8_t" }
+static_assert(char8_t{-1} >= 0, "Error"); // { dg-error "narrowing conversion of constant
expression from .int. to .char8_t." "char8_t" }
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/cops_bool.c
b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/cops_bool.c
index 53017ca9fa2..78502a8e0e9 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/cops_bool.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/cops_bool.c
@@ -48,7 +48,7 @@
#define VECT_CST { -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1 } /* { dg-warning
"overflow in conversion from" "" { target c } } */
#define VECT_CSTN { -1, t (), 0, -1, 0, f (), 0, 0, 0, -1, 0, -1, 0, -1, 0, -1 } /* { dg-warning
"overflow in conversion from" "" { target c } } */
- /* { dg-warning "narrowing conversion of" "" { target c++ } .-1 } */
+ /* { dg-warning "narrowing conversion from" "" { target c++ } .-1 } */
#define DECL_FUNC_INIT() \
svbool_t __attribute__ ((noipa)) \
--
2.47.3