This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Don't ICE on auto decl with no initializer (PR c++/37965)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 31 Oct 2008 13:58:33 +0100
- Subject: [C++ PATCH] Don't ICE on auto decl with no initializer (PR c++/37965)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
If processing_template_decl, start_decl_1 isn't called and thus
nothing reports an error for auto typed variable with no initializer.
Fixed thusly, tested with check-g++ RUNTESTFLAGS=cpp0x/*.C, full
bootstrap/regtest pending. Ok for trunk if it succeeds?
2008-10-31 Jakub Jelinek <jakub@redhat.com>
PR c++/37965
* decl.c (cp_finish_decl): Diagnose type_uses_auto type with
no initializer.
* g++.dg/cpp0x/auto7.C: New test.
--- gcc/cp/decl.c.jj 2008-10-23 13:21:09.000000000 +0200
+++ gcc/cp/decl.c 2008-10-31 13:19:36.000000000 +0100
@@ -5488,11 +5488,20 @@ cp_finish_decl (tree decl, tree init, bo
DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
auto_node = type_uses_auto (type);
- if (auto_node && !type_dependent_expression_p (init))
+ if (auto_node)
{
- type = TREE_TYPE (decl) = do_auto_deduction (type, init, auto_node);
- if (type == error_mark_node)
- return;
+ if (init == NULL_TREE)
+ {
+ error ("declaration of %q#D has no initializer", decl);
+ TREE_TYPE (decl) = error_mark_node;
+ return;
+ }
+ else if (!type_dependent_expression_p (init))
+ {
+ type = TREE_TYPE (decl) = do_auto_deduction (type, init, auto_node);
+ if (type == error_mark_node)
+ return;
+ }
}
if (processing_template_decl)
--- gcc/testsuite/g++.dg/cpp0x/auto7.C.jj 2008-10-31 13:42:02.000000000 +0100
+++ gcc/testsuite/g++.dg/cpp0x/auto7.C 2008-10-31 13:45:42.000000000 +0100
@@ -0,0 +1,13 @@
+// PR c++/37965
+// Negative test for auto
+// { dg-options "-std=c++0x" }
+
+auto i = 6;
+auto j; // { dg-error "has no initializer" }
+
+template<int> struct A
+{
+ static auto k = 7;
+ static auto l; // { dg-error "has no initializer" }
+ auto m; // { dg-error "has no initializer" }
+};
Jakub