diff mbox

[C++] PR 58888

Message ID 526E8E77.504@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 28, 2013, 4:19 p.m. UTC
Hi,

here we reject the declaration of b with the invalid use of ‘auto’ 
error. The reason is that, at the beginning of grokfield, init != 
NULL_TREE, processing_template_decl is false (in fact, a "templatized" 
version of the testcase is accepted) and we get to:

if (TREE_CODE (init) == CONSTRUCTOR)
init = digest_init (TREE_TYPE (value), init, tf_warning_or_error);

then, at the beginning of digest_init_r, complete_type_or_maybe_complain 
finds the auto type incomplete. It seems to me that in grokfield, in the 
non-template case too, we should just process the declaration later, in 
the final switch, thus forward to finish_static_data_member_decl (then 
the only difference with the "templatized" case that we already handle 
correctly, is that we don't call push_template_decl in the middle)

Tested x86_64-linux.

Thanks,
Paolo.

////////////////////
/cp
2013-10-28  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/58888
	* decl2.c (grokfield): Handle auto like NSDMI.

/testsuite
2013-10-28  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/58888
	* g++.dg/cpp0x/auto40.C: New.

Comments

Jason Merrill Oct. 28, 2013, 6:05 p.m. UTC | #1
My question is, why do we need that whole block for massaging VAR_DECL 
initializers?  That all ought to be handled properly by cp_finish_decl. 
  Does removing everything after

>       else if (!VAR_P (value))
>         gcc_unreachable ();

work?

Jason
diff mbox

Patch

Index: cp/decl2.c
===================================================================
--- cp/decl2.c	(revision 204133)
+++ cp/decl2.c	(working copy)
@@ -953,6 +953,8 @@  grokfield (const cp_declarator *declarator,
 	}
       else if (TREE_CODE (value) == FIELD_DECL)
 	/* C++11 NSDMI, keep going.  */;
+      else if (is_auto (TREE_TYPE (value)))
+	/* C++11 auto, keep going.  */;
       else if (!VAR_P (value))
 	gcc_unreachable ();
       else if (!processing_template_decl)
Index: testsuite/g++.dg/cpp0x/auto40.C
===================================================================
--- testsuite/g++.dg/cpp0x/auto40.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/auto40.C	(working copy)
@@ -0,0 +1,11 @@ 
+// PR c++/58888
+// { dg-do compile { target c++11 } }
+
+#include <initializer_list>
+
+struct A
+{
+  static constexpr auto b{1.0};
+};
+
+constexpr decltype(A::b) A::b;