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.carl...@oracle.com>
PR c++/58888
* decl2.c (grokfield): Handle auto like NSDMI.
/testsuite
2013-10-28 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/58888
* g++.dg/cpp0x/auto40.C: New.
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;