We've been stripping cv-quals from scalar prvalues in other situations,
but missed this one.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 8f1186d00e9f78a8b64f678cc322332568bbec59
Author: Jason Merrill <ja...@redhat.com>
Date: Wed Jun 22 16:34:53 2011 -0400
PR c++/49395
* init.c (build_zero_init_1): Strip cv-quals from scalar types.
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 3c347a4..62b68f2 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -176,7 +176,7 @@ build_zero_init_1 (tree type, tree nelts, bool static_storage_p,
initialized are initialized to zero. */
;
else if (SCALAR_TYPE_P (type))
- init = convert (type, integer_zero_node);
+ init = convert (cv_unqualified (type), integer_zero_node);
else if (CLASS_TYPE_P (type))
{
tree field;
diff --git a/gcc/testsuite/g++.dg/init/ref18.C b/gcc/testsuite/g++.dg/init/ref18.C
new file mode 100644
index 0000000..e704077
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/ref18.C
@@ -0,0 +1,12 @@
+// PR c++/49395
+
+volatile int foo();
+struct A { volatile int i; };
+typedef volatile int vi;
+
+volatile int i;
+
+const int& ir1 = foo();
+//const int& ir2 = A().i; // line 8
+const int& ir3 = static_cast<volatile int>(i);
+const int& ir4 = vi(); // line 10