[C++ Patch] PR 57183

Paolo Carlini paolo.carlini@oracle.com
Mon May 6 13:01:00 GMT 2013


Hi,

the issue is that we -Wunused-variable warn for:

const auto PI_3 = 3.1415926F;

The reason is that TREE_READONLY is not set ("d" instead "r" in the .o). 
In turn, that's because the first and only time 
cp_apply_type_quals_to_decl is called, at the end of grokdeclarator, 
nothing happens because the type is not complete yet. It seems to me 
that we have to handle this case similarly to templates, thus call again 
cp_apply_type_quals_to_decl after do_auto_deduction.

The below passes testing on x86_64-linux. Ok for mainline and branch?

Thanks,
Paolo.

/////////////////////////
-------------- next part --------------
/cp
2013-05-06  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/57183
	* decl.c (cp_finish_decl): After do_auto_deduction copy the
	qualifers with cp_apply_type_quals_to_decl.

/testsuite
2013-05-06  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/57183
	* g++.dg/cpp0x/auto38.C: New.
-------------- next part --------------
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 198625)
+++ cp/decl.c	(working copy)
@@ -6147,6 +6147,7 @@ cp_finish_decl (tree decl, tree init, bool init_co
 						   auto_node);
       if (type == error_mark_node)
 	return;
+      cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
     }
 
   if (!ensure_literal_type_for_constexpr_object (decl))
Index: testsuite/g++.dg/cpp0x/auto38.C
===================================================================
--- testsuite/g++.dg/cpp0x/auto38.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/auto38.C	(working copy)
@@ -0,0 +1,8 @@
+// PR c++/57183
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wunused-variable" }
+
+constexpr float PI_0 = 3.1415926F;
+constexpr auto PI_1 = 3.1415926F;
+const float PI_2 = 3.1415926F;
+const auto PI_3 = 3.1415926F;


More information about the Gcc-patches mailing list