Commit eb026338 by Jason Merrill Committed by Jason Merrill

Handle deferred parsing of NSDMIs.

	* parser.h (cp_unparsed_functions_entry): Add nsdmis field.
	* parser.c (unparsed_nsdmis, cp_parser_save_nsdmi): New.
	(cp_parser_late_parse_one_default_arg): Split out from
	cp_parser_late_parsing_default_args.
	(cp_parser_late_parsing_nsdmi): New.
	(push_unparsed_function_queues): Set it.
	(cp_parser_parameter_declaration): Save the '=' token.
	(cp_parser_template_parameter): Likewise.
	(cp_parser_default_argument): Call cp_parser_initializer
	rather than cp_parser_initializer_clause.
	(cp_parser_class_specifier_1): Parse unparsed_nsdmis.
	(cp_parser_member_declaration): Handle nsdmis.
	* decl2.c (grokfield): Handle DEFAULT_ARG for a function.

From-SVN: r179156
parent 0e5f8a59
2011-09-24 Jason Merrill <jason@redhat.com> 2011-09-24 Jason Merrill <jason@redhat.com>
Handle deferred parsing of NSDMIs.
* parser.h (cp_unparsed_functions_entry): Add nsdmis field.
* parser.c (unparsed_nsdmis, cp_parser_save_nsdmi): New.
(cp_parser_late_parse_one_default_arg): Split out from
cp_parser_late_parsing_default_args.
(cp_parser_late_parsing_nsdmi): New.
(push_unparsed_function_queues): Set it.
(cp_parser_parameter_declaration): Save the '=' token.
(cp_parser_template_parameter): Likewise.
(cp_parser_default_argument): Call cp_parser_initializer
rather than cp_parser_initializer_clause.
(cp_parser_class_specifier_1): Parse unparsed_nsdmis.
(cp_parser_member_declaration): Handle nsdmis.
* decl2.c (grokfield): Handle DEFAULT_ARG for a function.
Implement C++11 non-static data member initializers. Implement C++11 non-static data member initializers.
* cp-tree.h (enum cpp_warn_str): Add CPP0X_NSDMI. * cp-tree.h (enum cpp_warn_str): Add CPP0X_NSDMI.
* error.c (maybe_warn_cpp0x): Handle it. * error.c (maybe_warn_cpp0x): Handle it.
......
...@@ -6077,7 +6077,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, ...@@ -6077,7 +6077,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
/* Just store non-static data member initializers for later. */ /* Just store non-static data member initializers for later. */
if (init && TREE_CODE (decl) == FIELD_DECL) if (init && TREE_CODE (decl) == FIELD_DECL)
DECL_INITIAL (decl) = digest_init_flags (TREE_TYPE (decl), init, flags); DECL_INITIAL (decl) = init;
/* Take care of TYPE_DECLs up front. */ /* Take care of TYPE_DECLs up front. */
if (TREE_CODE (decl) == TYPE_DECL) if (TREE_CODE (decl) == TYPE_DECL)
......
...@@ -902,6 +902,8 @@ grokfield (const cp_declarator *declarator, ...@@ -902,6 +902,8 @@ grokfield (const cp_declarator *declarator,
DECL_DECLARED_INLINE_P (value) = 1; DECL_DECLARED_INLINE_P (value) = 1;
} }
} }
else if (TREE_CODE (init) == DEFAULT_ARG)
error ("invalid initializer for member function %qD", value);
else if (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE) else if (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE)
{ {
if (integer_zerop (init)) if (integer_zerop (init))
......
...@@ -169,6 +169,10 @@ typedef struct GTY(()) cp_unparsed_functions_entry_d { ...@@ -169,6 +169,10 @@ typedef struct GTY(()) cp_unparsed_functions_entry_d {
/* Functions with defintions that require post-processing. Functions /* Functions with defintions that require post-processing. Functions
appear in this list in declaration order. */ appear in this list in declaration order. */
VEC(tree,gc) *funs_with_definitions; VEC(tree,gc) *funs_with_definitions;
/* Non-static data members with initializers that require post-processing.
FIELD_DECLs appear in this list in declaration order. */
VEC(tree,gc) *nsdmis;
} cp_unparsed_functions_entry; } cp_unparsed_functions_entry;
DEF_VEC_O(cp_unparsed_functions_entry); DEF_VEC_O(cp_unparsed_functions_entry);
......
2011-09-24 Jason Merrill <jason@redhat.com> 2011-09-24 Jason Merrill <jason@redhat.com>
* g++.dg/cpp0x/nsdmi-defer1.C: New.
* g++.dg/cpp0x/nsdmi-defer2.C: New.
* g++.dg/cpp0x/nsdmi1.C: New. * g++.dg/cpp0x/nsdmi1.C: New.
* g++.dg/cpp0x/nsdmi2.C: New. * g++.dg/cpp0x/nsdmi2.C: New.
* g++.dg/cpp0x/nsdmi3.C: New. * g++.dg/cpp0x/nsdmi3.C: New.
......
// { dg-options -std=c++0x }
#define SA(X) static_assert(X,#X)
struct A
{
int i = f();
int j { f() };
static constexpr int f() { return 42; }
};
constexpr A a;
SA(a.i == 42);
SA(a.j == 42);
// { dg-options -std=c++0x }
struct A
{
int i = f();
static int f(int i = 42) { return i; }
};
A a;
...@@ -3,17 +3,17 @@ ...@@ -3,17 +3,17 @@
struct A struct A
{ {
A(void* i=); // { dg-error "with|specification" } A(void* i=); // { dg-error "with|specification|primary-expression" }
A(void* i=); // { dg-error "overloaded" } A(void* i=); // { dg-error "overloaded|primary-expression" }
A(void* i=); // { dg-error "overloaded" } A(void* i=); // { dg-error "overloaded|primary-expression" }
void operator+ (void* i=); // { dg-error "arguments" } void operator+ (void* i=); // { dg-error "arguments" }
virtual void foo1(=); // { dg-error "identifier" } virtual void foo1(=); // { dg-error "identifier|primary-expression" }
void foo2(=); // { dg-error "identifier" } void foo2(=); // { dg-error "identifier|primary-expression" }
void foo3(=); // { dg-error "identifier" } void foo3(=); // { dg-error "identifier|primary-expression" }
void foo4(=); // { dg-error "identifier" } void foo4(=); // { dg-error "identifier|primary-expression" }
void foo5(=); // { dg-error "identifier" } void foo5(=); // { dg-error "identifier|primary-expression" }
}; // { dg-error "primary-expression" } };
A::A (void* i=) {} // { dg-error "primary-expression|argument" } A::A (void* i=) {} // { dg-error "primary-expression|argument" }
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
struct A struct A
{ {
typedef void (F)(); typedef void (F)();
F f = []{}; /* { dg-error "invalid initializer" } */ F f = []{}; /* { dg-error "invalid pure" } */
}; };
struct B struct B
{ {
typedef void (F)(); typedef void (F)();
F f = 1; /* { dg-error "invalid initializer" } */ F f = 1; /* { dg-error "invalid pure" } */
virtual F f2 = 2; /* { dg-error "invalid initializer" } */ virtual F f2 = 2; /* { dg-error "invalid pure" } */
F f3 = 3; /* { dg-error "invalid initializer" } */ F f3 = 3; /* { dg-error "invalid pure" } */
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment