aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2008-08-30 01:14:54 -0400
committerJason Merrill <jason@gcc.gnu.org>2008-08-30 01:14:54 -0400
commit86a09a9e99fd73423b6b00b1083abfb0d8ac862d (patch)
treee0bd80b1274106f983a05d33d9c48ec65a2d8085 /gcc/cp/decl.c
parentb3914aa38f56986ba8ff512ded75608e875436e2 (diff)
downloadgcc-86a09a9e99fd73423b6b00b1083abfb0d8ac862d.zip
gcc-86a09a9e99fd73423b6b00b1083abfb0d8ac862d.tar.gz
gcc-86a09a9e99fd73423b6b00b1083abfb0d8ac862d.tar.bz2
Implement C++0x 'auto' semantics.
* decl.c (start_decl_1): Don't complain about auto being incomplete. (cp_finish_decl): Deduce auto. * init.c (build_new): Handle 'new auto'. * typeck2.c (cxx_incomplete_type_diagnostic): Give a different message for auto than for normal template type parms. * pt.c (type_dependent_expression_p): Handle { }. (make_auto): New function. (listify_autos): New function. (do_auto_deduction): New function. (is_auto): New function. (type_uses_auto): New function. * cp-tree.h: Declare them. * parser.c (cp_parser_decl_specifier_seq): In C++0x mode, don't treat auto as a declspec. (cp_parser_simple_type_specifier): It's a type-specifier. From-SVN: r139798
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r--gcc/cp/decl.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c3d63bb..0d4dced 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -4203,6 +4203,8 @@ start_decl_1 (tree decl, bool initialized)
arrays which might be completed by the initialization. */
if (complete_p)
; /* A complete type is ok. */
+ else if (type_uses_auto (type))
+ ; /* An auto type is ok. */
else if (TREE_CODE (type) != ARRAY_TYPE)
{
error ("variable %q#D has initializer but incomplete type", decl);
@@ -4217,8 +4219,11 @@ start_decl_1 (tree decl, bool initialized)
}
else if (aggregate_definition_p && !complete_p)
{
- error ("aggregate %q#D has incomplete type and cannot be defined",
- decl);
+ if (type_uses_auto (type))
+ error ("declaration of %q#D has no initializer", decl);
+ else
+ error ("aggregate %q#D has incomplete type and cannot be defined",
+ decl);
/* Change the type so that assemble_variable will give
DECL an rtl we can live with: (mem (const_int 0)). */
type = TREE_TYPE (decl) = error_mark_node;
@@ -5406,6 +5411,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
int was_readonly = 0;
bool var_definition_p = false;
int saved_processing_template_decl;
+ tree auto_node;
if (decl == error_mark_node)
return;
@@ -5440,6 +5446,14 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
&& (DECL_INITIAL (decl) || init))
DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
+ auto_node = type_uses_auto (type);
+ if (auto_node && !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)
{
bool type_dependent_p;