aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2014-01-27 23:31:01 -0500
committerJason Merrill <jason@gcc.gnu.org>2014-01-27 23:31:01 -0500
commit110740003a153d13ad8c1ea73aa909d9827d0f15 (patch)
tree9438ff743a38c5681b50f3cd6f4fd753a2d54127
parentf235ad118fed420d99d985b116a3c6a1d054d398 (diff)
downloadgcc-110740003a153d13ad8c1ea73aa909d9827d0f15.zip
gcc-110740003a153d13ad8c1ea73aa909d9827d0f15.tar.gz
gcc-110740003a153d13ad8c1ea73aa909d9827d0f15.tar.bz2
re PR c++/58812 (ICE initializing an r-value reference with an initializer list)
PR c++/58812 * call.c (convert_like_real): Give helpful error about excess braces for ck_rvalue of scalar type. From-SVN: r207165
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/call.c19
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist76.C5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist77.C10
4 files changed, 34 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 707032f..fdd9bca 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,10 @@
2014-01-27 Jason Merrill <jason@redhat.com>
+ PR c++/58812
+ PR c++/58651
+ * call.c (convert_like_real): Give helpful error about excess braces
+ for ck_rvalue of scalar type.
+
Core DR 1288
* call.c (reference_binding): Only elide braces if the single
element is reference-related.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 7d6e621..b72f2d4 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -5879,9 +5879,11 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
&& convs->kind != ck_ambig
&& (convs->kind != ck_ref_bind
|| convs->user_conv_p)
- && convs->kind != ck_rvalue
+ && (convs->kind != ck_rvalue
+ || SCALAR_TYPE_P (totype))
&& convs->kind != ck_base)
{
+ bool complained = false;
conversion *t = convs;
/* Give a helpful error if this is bad because of excess braces. */
@@ -5889,7 +5891,13 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
&& SCALAR_TYPE_P (totype)
&& CONSTRUCTOR_NELTS (expr) > 0
&& BRACE_ENCLOSED_INITIALIZER_P (CONSTRUCTOR_ELT (expr, 0)->value))
- permerror (loc, "too many braces around initializer for %qT", totype);
+ {
+ complained = permerror (loc, "too many braces around initializer "
+ "for %qT", totype);
+ while (BRACE_ENCLOSED_INITIALIZER_P (expr)
+ && CONSTRUCTOR_NELTS (expr) == 1)
+ expr = CONSTRUCTOR_ELT (expr, 0)->value;
+ }
for (; t ; t = next_conversion (t))
{
@@ -5925,9 +5933,10 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
else if (t->kind == ck_identity)
break;
}
- if (permerror (loc, "invalid conversion from %qT to %qT",
- TREE_TYPE (expr), totype)
- && fn)
+ if (!complained)
+ complained = permerror (loc, "invalid conversion from %qT to %qT",
+ TREE_TYPE (expr), totype);
+ if (complained && fn)
inform (DECL_SOURCE_LOCATION (fn),
"initializing argument %P of %qD", argnum, fn);
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist76.C b/gcc/testsuite/g++.dg/cpp0x/initlist76.C
new file mode 100644
index 0000000..ac419dd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist76.C
@@ -0,0 +1,5 @@
+// PR c++/58812
+// { dg-require-effective-target c++11 }
+
+int i;
+int&& j{{ i }}; // { dg-error "too many braces" }
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist77.C b/gcc/testsuite/g++.dg/cpp0x/initlist77.C
new file mode 100644
index 0000000..49b9079
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist77.C
@@ -0,0 +1,10 @@
+// PR c++/58651
+// { dg-require-effective-target c++11 }
+
+struct A
+{
+ int i;
+ A(int j) : i{{j}} {} // { dg-error "too many braces" }
+};
+
+A a(0);