/* Process declarations and variables for C++ compiler.
Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+ 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+ Free Software Foundation, Inc.
Contributed by Michael Tiemann (tiemann@cygnus.com)
This file is part of GCC.
template <class T> void S<T>::f(int);
- The `class T' maches the `S<T>', leaving no template headers
+ The `class T' matches the `S<T>', leaving no template headers
corresponding to the `f'. */
return tsk_none;
else if (n_template_parm_scopes > n_class_scopes + 1)
location_t location;
error ("label %q+D used but not defined", label);
-#ifdef USE_MAPPED_LOCATION
location = input_location; /* FIXME want (input_filename, (line)0) */
-#else
- location.file = input_filename;
- location.line = 0;
-#endif
/* Avoid crashing later. */
define_label (location, DECL_NAME (label));
}
itself, calling F for each. The DATA is passed to F as well. */
static int
-walk_namespaces_r (tree namespace, walk_namespaces_fn f, void* data)
+walk_namespaces_r (tree name_space, walk_namespaces_fn f, void* data)
{
int result = 0;
- tree current = NAMESPACE_LEVEL (namespace)->namespaces;
+ tree current = NAMESPACE_LEVEL (name_space)->namespaces;
- result |= (*f) (namespace, data);
+ result |= (*f) (name_space, data);
for (; current; current = TREE_CHAIN (current))
result |= walk_namespaces_r (current, f, data);
wrapup_global_declarations for this NAMESPACE. */
int
-wrapup_globals_for_namespace (tree namespace, void* data)
+wrapup_globals_for_namespace (tree name_space, void* data)
{
- struct cp_binding_level *level = NAMESPACE_LEVEL (namespace);
+ struct cp_binding_level *level = NAMESPACE_LEVEL (name_space);
VEC(tree,gc) *statics = level->static_decls;
tree *vec = VEC_address (tree, statics);
int len = VEC_length (tree, statics);
return;
name = DECL_ASSEMBLER_NAME (newdecl);
- pedwarn ("%qD was declared %<extern%> and later %<static%>", newdecl);
- pedwarn ("previous declaration of %q+D", olddecl);
+ permerror ("%qD was declared %<extern%> and later %<static%>", newdecl);
+ permerror ("previous declaration of %q+D", olddecl);
}
/* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
if (1 == simple_cst_equal (TREE_PURPOSE (t1),
TREE_PURPOSE (t2)))
{
- pedwarn ("default argument given for parameter %d of %q#D",
- i, newdecl);
- pedwarn ("after previous specification in %q+#D", olddecl);
+ permerror ("default argument given for parameter %d of %q#D",
+ i, newdecl);
+ permerror ("after previous specification in %q+#D", olddecl);
}
else
{
olddecl);
}
}
-
- if (DECL_DECLARED_INLINE_P (newdecl)
- && ! DECL_DECLARED_INLINE_P (olddecl)
- && TREE_ADDRESSABLE (olddecl) && warn_inline)
- {
- warning (0, "%q#D was used before it was declared inline", newdecl);
- warning (0, "%Jprevious non-inline declaration here", olddecl);
- }
}
}
warning (OPT_Wredundant_decls, "redundant redeclaration of %qD in same scope", newdecl);
warning (OPT_Wredundant_decls, "previous declaration of %q+D", olddecl);
}
+
+ if (DECL_DELETED_FN (newdecl))
+ {
+ error ("deleted definition of %qD", newdecl);
+ error ("after previous declaration %q+D", olddecl);
+ }
}
/* Deal with C++: must preserve virtual function table size. */
&& DECL_INITIAL (new_result))
{
if (DECL_INITIAL (old_result))
- {
- DECL_INLINE (old_result) = 0;
- DECL_UNINLINABLE (old_result) = 1;
- }
+ DECL_UNINLINABLE (old_result) = 1;
else
- {
- DECL_INLINE (old_result) = DECL_INLINE (new_result);
- DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
- }
+ DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
DECL_NOT_REALLY_EXTERN (old_result)
= DECL_NOT_REALLY_EXTERN (new_result);
= DECL_INTERFACE_KNOWN (new_result);
DECL_DECLARED_INLINE_P (old_result)
= DECL_DECLARED_INLINE_P (new_result);
+ DECL_DISREGARD_INLINE_LIMITS (old_result)
+ |= DECL_DISREGARD_INLINE_LIMITS (new_result);
+
}
else
{
- DECL_INLINE (old_result)
- |= DECL_INLINE (new_result);
DECL_DECLARED_INLINE_P (old_result)
|= DECL_DECLARED_INLINE_P (new_result);
+ DECL_DISREGARD_INLINE_LIMITS (old_result)
+ |= DECL_DISREGARD_INLINE_LIMITS (new_result);
check_redeclaration_exception_specification (newdecl, olddecl);
}
}
|= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
- TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
- DECL_IS_PURE (newdecl) |= DECL_IS_PURE (olddecl);
+ DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl);
+ DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
+ TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
+ DECL_LOOPING_CONST_OR_PURE_P (newdecl)
+ |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
/* Keep the old RTL. */
COPY_DECL_RTL (olddecl, newdecl);
}
}
else if (new_defines_function && DECL_INITIAL (olddecl))
{
- /* C++ is always in in unit-at-a-time mode, so we never
- inline re-defined extern inline functions. */
- DECL_INLINE (newdecl) = 0;
+ /* Never inline re-defined extern inline functions.
+ FIXME: this could be better handled by keeping both
+ function as separate declarations. */
DECL_UNINLINABLE (newdecl) = 1;
}
else
DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
- /* If either decl says `inline', this fn is inline, unless
- its definition was passed already. */
- if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
- DECL_INLINE (olddecl) = 1;
- DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
-
DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
= (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
ggc_free (DECL_LANG_SPECIFIC (olddecl));
}
+ /* Merge the USED information. */
+ if (TREE_USED (olddecl))
+ TREE_USED (newdecl) = 1;
+ else if (TREE_USED (newdecl))
+ TREE_USED (olddecl) = 1;
+
if (TREE_CODE (newdecl) == FUNCTION_DECL)
{
int function_size;
identify_goto (tree decl, const location_t *locus)
{
if (decl)
- pedwarn ("jump to label %qD", decl);
+ permerror ("jump to label %qD", decl);
else
- pedwarn ("jump to case label");
+ permerror ("jump to case label");
if (locus)
- pedwarn ("%H from here", locus);
+ permerror ("%H from here", locus);
}
/* Check that a single previously seen jump to a newly defined label
if (problem > 1)
error (" crosses initialization of %q+#D", new_decls);
else
- pedwarn (" enters scope of non-POD %q+#D", new_decls);
+ permerror (" enters scope of non-POD %q+#D", new_decls);
}
if (b == level)
if (ent->in_try_scope || ent->in_catch_scope
|| ent->in_omp_scope || ent->bad_decls)
{
- pedwarn ("jump to label %q+D", decl);
- pedwarn (" from here");
+ permerror ("jump to label %q+D", decl);
+ permerror (" from here");
identified = true;
}
else if (u > 1)
error (" skips initialization of %q+#D", b);
else
- pedwarn (" enters scope of non-POD %q+#D", b);
+ permerror (" enters scope of non-POD %q+#D", b);
}
if (ent->in_try_scope)
{
if (!identified)
{
- pedwarn ("jump to label %q+D", decl);
- pedwarn (" from here");
+ permerror ("jump to label %q+D", decl);
+ permerror (" from here");
identified = true;
}
error (" exits OpenMP structured block");
p->more_cleanups_ok = 0;
if (name == get_identifier ("wchar_t"))
- pedwarn ("label named wchar_t");
+ permerror ("label named wchar_t");
if (DECL_INITIAL (decl) != NULL_TREE)
{
else
{
/* Build the TYPENAME_TYPE. */
- t = make_aggr_type (TYPENAME_TYPE);
+ t = cxx_make_type (TYPENAME_TYPE);
TYPE_CONTEXT (t) = ti.scope;
TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
TYPENAME_IS_ENUM_P (t) = ti.enum_p;
if (dependent_type_p (context))
return build_typename_type (context, name, fullname, tag_type);
- if (!IS_AGGR_TYPE (context))
+ if (!MAYBE_CLASS_TYPE_P (context))
{
if (complain & tf_error)
error ("%q#T is not a class", context);
{
tree tmpl = NULL_TREE;
- if (IS_AGGR_TYPE (context))
+ if (MAYBE_CLASS_TYPE_P (context))
tmpl = lookup_field (context, name, 0, false);
if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl))
}
/* Build the UNBOUND_CLASS_TEMPLATE. */
- t = make_aggr_type (UNBOUND_CLASS_TEMPLATE);
+ t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
TYPE_CONTEXT (t) = FROB_CONTEXT (context);
TREE_TYPE (t) = NULL_TREE;
SET_TYPE_STRUCTURAL_EQUALITY (t);
TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
+ init_list_type_node = make_node (UNKNOWN_TYPE);
+ record_unknown_type (init_list_type_node, "init list");
+
{
/* Make sure we get a unique function type, so we can give
its pointer type a name. (This wins for gdb.) */
push_namespace (std_identifier);
bad_alloc_id = get_identifier ("bad_alloc");
- bad_alloc_type_node = make_aggr_type (RECORD_TYPE);
+ bad_alloc_type_node = make_class_type (RECORD_TYPE);
TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
bad_alloc_decl
= create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
We assume that such functions never throw; if this is incorrect,
callers should unset TREE_NOTHROW. */
-tree
+static tree
build_library_fn (tree name, tree type)
{
tree fn = build_library_fn_1 (name, ERROR_MARK, type);
}
/* Like build_library_fn, but also pushes the function so that we will
- be able to find it via IDENTIFIER_GLOBAL_VALUE. */
+ be able to find it via IDENTIFIER_GLOBAL_VALUE. Also, the function
+ may throw exceptions listed in RAISES. */
tree
-push_library_fn (tree name, tree type)
+push_library_fn (tree name, tree type, tree raises)
{
- tree fn = build_library_fn (name, type);
+ tree fn;
+
+ if (raises)
+ type = build_exception_variant (type, raises);
+
+ fn = build_library_fn (name, type);
pushdecl_top_level (fn);
return fn;
}
push_void_library_fn (tree name, tree parmtypes)
{
tree type = build_function_type (void_type_node, parmtypes);
- return push_library_fn (name, type);
+ return push_library_fn (name, type, NULL_TREE);
}
/* Like push_library_fn, but also note that this function throws
tree
push_throw_library_fn (tree name, tree type)
{
- tree fn = push_library_fn (name, type);
+ tree fn = push_library_fn (name, type, NULL_TREE);
TREE_THIS_VOLATILE (fn) = 1;
TREE_NOTHROW (fn) = 0;
return fn;
tree *q;
/* Wipe out memory of synthesized methods. */
- TYPE_HAS_CONSTRUCTOR (t) = 0;
+ TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
TYPE_HAS_INIT_REF (t) = 0;
TYPE_HAS_CONST_INIT_REF (t) = 0;
else if (declspecs->redefined_builtin_type)
{
if (!in_system_header)
- pedwarn ("redeclaration of C++ built-in type %qT",
- declspecs->redefined_builtin_type);
+ permerror ("redeclaration of C++ built-in type %qT",
+ declspecs->redefined_builtin_type);
return NULL_TREE;
}
if (declspecs->type
&& TYPE_P (declspecs->type)
&& ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
- && IS_AGGR_TYPE (declspecs->type))
+ && MAYBE_CLASS_TYPE_P (declspecs->type))
|| TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
declared_type = declspecs->type;
else if (declspecs->type == error_mark_node)
error_p = true;
if (declared_type == NULL_TREE && ! saw_friend && !error_p)
- pedwarn ("declaration does not declare anything");
+ permerror ("declaration does not declare anything");
/* Check for an anonymous union. */
- else if (declared_type && IS_AGGR_TYPE_CODE (TREE_CODE (declared_type))
+ else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
&& TYPE_ANONYMOUS_P (declared_type))
{
/* 7/3 In a simple-declaration, the optional init-declarator-list
/* Anonymous unions are objects, so they can have specifiers. */;
SET_ANON_AGGR_TYPE_P (declared_type);
- if (TREE_CODE (declared_type) != UNION_TYPE && pedantic
- && !in_system_header)
- pedwarn ("ISO C++ prohibits anonymous structs");
+ if (TREE_CODE (declared_type) != UNION_TYPE && !in_system_header)
+ pedwarn (OPT_pedantic, "ISO C++ prohibits anonymous structs");
}
else
attrs = type_specifiers->attributes;
type_specifiers->attributes = NULL_TREE;
type = grokdeclarator (declarator, type_specifiers, TYPENAME, 0, &attrs);
- if (attrs)
+ if (attrs && type != error_mark_node)
{
if (CLASS_TYPE_P (type))
- warning (OPT_Wattributes, "ignoring attributes applied to class type "
- "outside of definition");
+ warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
+ "outside of definition", type);
+ else if (MAYBE_CLASS_TYPE_P (type))
+ /* A template type parameter or other dependent type. */
+ warning (OPT_Wattributes, "ignoring attributes applied to dependent "
+ "type %qT without an associated declaration", type);
else
cplus_decl_attributes (&type, attrs, 0);
}
grokfield.) The DECL corresponding to the DECLARATOR is returned.
If an error occurs, the error_mark_node is returned instead.
- DECLSPECS are the decl-specifiers for the declaration. INITIALIZED
- is true if an explicit initializer is present, but false if this is
- a variable implicitly initialized via a default constructor.
- ATTRIBUTES and PREFIX_ATTRIBUTES are GNU attributes associated with
- this declaration. *PUSHED_SCOPE_P is set to the scope entered in
- this function, if any; if set, the caller is responsible for
- calling pop_scope. */
+ DECLSPECS are the decl-specifiers for the declaration. INITIALIZED is 1
+ if an explicit initializer is present, or 2 for an explicitly defaulted
+ function, or 3 for an explicitly deleted function, but 0 if this is a
+ variable implicitly initialized via a default constructor. ATTRIBUTES
+ and PREFIX_ATTRIBUTES are GNU attributes associated with this
+ declaration. *PUSHED_SCOPE_P is set to the scope entered in this
+ function, if any; if set, the caller is responsible for calling
+ pop_scope. */
tree
start_decl (const cp_declarator *declarator,
tree type;
tree context;
bool was_public;
+ int flags;
*pushed_scope_p = NULL_TREE;
switch (TREE_CODE (decl))
{
case TYPE_DECL:
- error ("typedef %qD is initialized (use __typeof__ instead)", decl);
+ error ("typedef %qD is initialized (use decltype instead)", decl);
return error_mark_node;
case FUNCTION_DECL:
- error ("function %q#D is initialized like a variable", decl);
- return error_mark_node;
+ if (initialized == 3)
+ /* We'll handle the rest of the semantics later, but we need to
+ set this now so it's visible to duplicate_decls. */
+ DECL_DELETED_FN (decl) = 1;
+ break;
default:
break;
TREE_STATIC (decl) = 1;
}
+ /* If this is a typedef that names the class for linkage purposes
+ (7.1.3p8), apply any attributes directly to the type. */
+ if (TREE_CODE (decl) == TYPE_DECL
+ && TAGGED_TYPE_P (TREE_TYPE (decl))
+ && decl == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl))))
+ flags = ATTR_FLAG_TYPE_IN_PLACE;
+ else
+ flags = 0;
+
/* Set attributes here so if duplicate decl, will have proper attributes. */
- cplus_decl_attributes (&decl, attributes, 0);
+ cplus_decl_attributes (&decl, attributes, flags);
/* Dllimported symbols cannot be defined. Static data members (which
can be initialized in-class and dllimported) go through grokfield,
if (DECL_CONTEXT (field) != context)
{
if (!same_type_p (DECL_CONTEXT (field), context))
- pedwarn ("ISO C++ does not permit %<%T::%D%> "
- "to be defined as %<%T::%D%>",
- DECL_CONTEXT (field), DECL_NAME (decl),
- context, DECL_NAME (decl));
+ permerror ("ISO C++ does not permit %<%T::%D%> "
+ "to be defined as %<%T::%D%>",
+ DECL_CONTEXT (field), DECL_NAME (decl),
+ context, DECL_NAME (decl));
DECL_CONTEXT (decl) = DECL_CONTEXT (field);
}
if (processing_specialization
}
if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl))
- pedwarn ("declaration of %q#D outside of class is not definition",
- decl);
+ permerror ("declaration of %q#D outside of class is not definition",
+ decl);
}
was_public = TREE_PUBLIC (decl);
type = TREE_TYPE (decl);
complete_p = COMPLETE_TYPE_P (type);
- aggregate_definition_p = IS_AGGR_TYPE (type) && !DECL_EXTERNAL (decl);
+ aggregate_definition_p = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
/* If an explicit initializer is present, or if this is a definition
of an aggregate, then we need a complete type at this point.
return NULL_TREE;
}
+/* Subroutine of check_initializer. We're initializing a DECL of
+ std::initializer_list<T> TYPE from a braced-init-list INIT, and need to
+ extend the lifetime of the underlying array to match that of the decl,
+ just like for reference initialization. CLEANUP is as for
+ grok_reference_init. */
+
+static tree
+build_init_list_var_init (tree decl, tree type, tree init, tree *cleanup)
+{
+ tree aggr_init, array, arrtype;
+ init = perform_implicit_conversion (type, init, tf_warning_or_error);
+ aggr_init = TARGET_EXPR_INITIAL (init);
+ init = build2 (INIT_EXPR, type, decl, init);
+
+ array = AGGR_INIT_EXPR_ARG (aggr_init, 1);
+ arrtype = TREE_TYPE (array);
+ STRIP_NOPS (array);
+ gcc_assert (TREE_CODE (array) == ADDR_EXPR);
+ array = TREE_OPERAND (array, 0);
+ /* If the array is constant, finish_compound_literal already made it a
+ static variable and we don't need to do anything here. */
+ if (decl && TREE_CODE (array) == TARGET_EXPR)
+ {
+ tree subinit;
+ tree var = set_up_extended_ref_temp (decl, array, cleanup, &subinit);
+ var = build_address (var);
+ var = convert (arrtype, var);
+ AGGR_INIT_EXPR_ARG (aggr_init, 1) = var;
+ init = build2 (COMPOUND_EXPR, TREE_TYPE (init), subinit, init);
+ }
+ return init;
+}
+
/* Designated initializers in arrays are not supported in GNU C++.
The parser cannot detect this error since it does not know whether
a given brace-enclosed initializer is for a class type or for an
if (ce->index)
{
/* The parser only allows identifiers as designated
- intializers. */
+ initializers. */
gcc_assert (TREE_CODE (ce->index) == IDENTIFIER_NODE);
error ("name %qD used in a GNU-style designated "
"initializer for an array", ce->index);
/* Keep this code around in case we later want to control debug info
based on whether a type is "used". (jason 1999-11-11) */
- else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
+ else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
/* Let debugger know it should output info for this type. */
note_debug_info_needed (ttype);
if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
constant_expression_warning (DECL_SIZE (decl));
else
- error ("storage size of %qD isn't constant", decl);
+ {
+ error ("storage size of %qD isn't constant", decl);
+ TREE_TYPE (decl) = error_mark_node;
+ }
}
}
unsigned HOST_WIDE_INT index;
/* The initializer for an array is always a CONSTRUCTOR. */
- new_init = build_constructor (NULL_TREE, NULL);
+ new_init = build_constructor (init_list_type_node, NULL);
if (sized_array_p)
{
gcc_assert (CLASS_TYPE_P (type));
/* The initializer for a class is always a CONSTRUCTOR. */
- new_init = build_constructor (NULL_TREE, NULL);
+ new_init = build_constructor (init_list_type_node, NULL);
field = next_initializable_field (TYPE_FIELDS (type));
if (!field)
if (!CP_AGGREGATE_TYPE_P (type))
{
/* It is invalid to initialize a non-aggregate type with a
- brace-enclosed initializer.
+ brace-enclosed initializer before C++0x.
We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
a CONSTRUCTOR (with a record type). */
if (TREE_CODE (init) == CONSTRUCTOR
&& BRACE_ENCLOSED_INITIALIZER_P (init)) /* p7626.C */
{
- error ("braces around scalar initializer for type %qT", type);
- init = error_mark_node;
+ if (SCALAR_TYPE_P (type))
+ {
+ error ("braces around scalar initializer for type %qT", type);
+ init = error_mark_node;
+ }
+ else
+ maybe_warn_cpp0x ("extended initializer lists");
}
d->cur++;
return new_init;
}
+/* Verify array initializer. Returns true if errors have been reported. */
+
+bool
+check_array_initializer (tree decl, tree type, tree init)
+{
+ tree element_type = TREE_TYPE (type);
+
+ /* The array type itself need not be complete, because the
+ initializer may tell us how many elements are in the array.
+ But, the elements of the array must be complete. */
+ if (!COMPLETE_TYPE_P (complete_type (element_type)))
+ {
+ if (decl)
+ error ("elements of array %q#D have incomplete type", decl);
+ else
+ error ("elements of array %q#T have incomplete type", type);
+ return true;
+ }
+ /* It is not valid to initialize a VLA. */
+ if (init
+ && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
+ || !TREE_CONSTANT (TYPE_SIZE (element_type))))
+ {
+ if (decl)
+ error ("variable-sized object %qD may not be initialized", decl);
+ else
+ error ("variable-sized compound literal");
+ return true;
+ }
+ return false;
+}
+
+/* Subroutine of check_initializer; args are passed down from that function.
+ Set stmts_are_full_exprs_p to 1 across a call to build_aggr_init. */
+
+static tree
+build_aggr_init_full_exprs (tree decl, tree init, int flags)
+
+{
+ int saved_stmts_are_full_exprs_p = 0;
+ if (building_stmt_tree ())
+ {
+ saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
+ current_stmt_tree ()->stmts_are_full_exprs_p = 1;
+ }
+ init = build_aggr_init (decl, init, flags, tf_warning_or_error);
+ if (building_stmt_tree ())
+ current_stmt_tree ()->stmts_are_full_exprs_p =
+ saved_stmts_are_full_exprs_p;
+ return init;
+}
+
/* Verify INIT (the initializer for DECL), and record the
initialization in DECL_INITIAL, if appropriate. CLEANUP is as for
grok_reference_init.
if (TREE_CODE (type) == ARRAY_TYPE)
{
- tree element_type = TREE_TYPE (type);
-
- /* The array type itself need not be complete, because the
- initializer may tell us how many elements are in the array.
- But, the elements of the array must be complete. */
- if (!COMPLETE_TYPE_P (complete_type (element_type)))
- {
- error ("elements of array %q#D have incomplete type", decl);
- return NULL_TREE;
- }
- /* It is not valid to initialize a VLA. */
- if (init
- && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
- || !TREE_CONSTANT (TYPE_SIZE (element_type))))
- {
- error ("variable-sized object %qD may not be initialized", decl);
- return NULL_TREE;
- }
+ if (check_array_initializer (decl, type, init))
+ return NULL_TREE;
}
else if (!COMPLETE_TYPE_P (type))
{
int init_len = VEC_length (constructor_elt, CONSTRUCTOR_ELTS (init));
if (SCALAR_TYPE_P (type))
{
- if (init_len != 1)
+ if (init_len == 0)
+ {
+ maybe_warn_cpp0x ("extended initializer lists");
+ init = build_zero_init (type, NULL_TREE, false);
+ }
+ else if (init_len != 1)
{
error ("scalar object %qD requires one element in initializer",
decl);
return NULL_TREE;
}
}
- else if ((cxx_dialect == cxx98) && !CP_AGGREGATE_TYPE_P (type))
- {
- /* A non-aggregate that is not a scalar cannot be initialized
- via an initializer-list in C++98. */
- error ("braces around initializer for non-aggregate type %qT",
- type);
- TREE_TYPE (decl) = error_mark_node;
- return NULL_TREE;
- }
}
if (TREE_CODE (decl) == CONST_DECL)
{
/* Do not reshape constructors of vectors (they don't need to be
reshaped. */
- if (TREE_CODE (init) == CONSTRUCTOR
- && !COMPOUND_LITERAL_P (init)
- && !TREE_TYPE (init)) /* ptrmemfunc */
+ if (BRACE_ENCLOSED_INITIALIZER_P (init))
{
- init = reshape_init (type, init);
-
- if ((*targetm.vector_opaque_p) (type))
+ if (is_std_init_list (type))
+ return build_init_list_var_init (decl, type, init, cleanup);
+ else if (TYPE_NON_AGGREGATE_CLASS (type))
+ {
+ /* Don't reshape if the class has constructors. */
+ if (cxx_dialect == cxx98)
+ error ("in C++98 %qD must be initialized by constructor, "
+ "not by %<{...}%>",
+ decl);
+ init = build_tree_list (NULL_TREE, init);
+ }
+ else if ((*targetm.vector_opaque_p) (type))
{
error ("opaque vector types cannot be initialized");
init = error_mark_node;
}
+ else
+ init = reshape_init (type, init);
}
/* If DECL has an array type without a specific bound, deduce the
if (type == error_mark_node)
return NULL_TREE;
- if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
- {
- if (TREE_CODE (type) == ARRAY_TYPE)
- goto initialize_aggr;
- else if (TREE_CODE (init) == CONSTRUCTOR)
- {
- if (TYPE_NON_AGGREGATE_CLASS (type))
- {
- error ("%qD must be initialized by constructor, "
- "not by %<{...}%>",
- decl);
- init = error_mark_node;
- }
- else
- goto dont_use_constructor;
- }
- else
- {
- int saved_stmts_are_full_exprs_p;
-
- initialize_aggr:
- saved_stmts_are_full_exprs_p = 0;
- if (building_stmt_tree ())
- {
- saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
- current_stmt_tree ()->stmts_are_full_exprs_p = 1;
- }
- init = build_aggr_init (decl, init, flags);
- if (building_stmt_tree ())
- current_stmt_tree ()->stmts_are_full_exprs_p =
- saved_stmts_are_full_exprs_p;
- return init;
- }
- }
- else
+ if (TYPE_NEEDS_CONSTRUCTING (type)
+ || (CLASS_TYPE_P (type)
+ && !BRACE_ENCLOSED_INITIALIZER_P (init)))
+ return build_aggr_init_full_exprs (decl, init, flags);
+ else if (TREE_CODE (init) != TREE_VEC)
{
- dont_use_constructor:
- if (TREE_CODE (init) != TREE_VEC)
- {
- init_code = store_init_value (decl, init);
- if (pedantic && TREE_CODE (type) == ARRAY_TYPE
- && DECL_INITIAL (decl)
- && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
- && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
- warning (0, "array %qD initialized by parenthesized string literal %qE",
- decl, DECL_INITIAL (decl));
- init = NULL;
- }
+ init_code = store_init_value (decl, init);
+ if (pedantic && TREE_CODE (type) == ARRAY_TYPE
+ && DECL_INITIAL (decl)
+ && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
+ && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
+ warning (0, "array %qD initialized by parenthesized string literal %qE",
+ decl, DECL_INITIAL (decl));
+ init = NULL;
}
}
else if (DECL_EXTERNAL (decl))
;
else if (TYPE_P (type) && TYPE_NEEDS_CONSTRUCTING (type))
- goto initialize_aggr;
- else if (IS_AGGR_TYPE (type))
+ return build_aggr_init_full_exprs (decl, init, flags);
+ else if (MAYBE_CLASS_TYPE_P (type))
{
tree core_type = strip_array_types (type);
tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
-
+ /* Tell honor_protect_cleanup_actions to handle this as a separate
+ cleanup. */
+ TRY_CATCH_IS_CLEANUP (tcleanup) = 1;
+
TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup;
}
/* We're initializing a local variable which has a cleanup GUARD. If there
are any temporaries used in the initializer INIT of this variable, we
need to wrap their cleanups with TRY_CATCH_EXPR (, GUARD) so that the
- variable will be cleaned up properly if one of them throws. */
+ variable will be cleaned up properly if one of them throws.
+
+ Unfortunately, there's no way to express this properly in terms of
+ nesting, as the regions for the temporaries overlap the region for the
+ variable itself; if there are two temporaries, the variable needs to be
+ the first thing destroyed if either of them throws. However, we only
+ want to run the variable's cleanup if it actually got constructed. So
+ we need to guard the temporary cleanups with the variable's cleanup if
+ they are run on the normal path, but not if they are run on the
+ exceptional path. We implement this by telling
+ honor_protect_cleanup_actions to strip the variable cleanup from the
+ exceptional path. */
static void
wrap_temporary_cleanups (tree init, tree guard)
{
gcc_assert (DECL_ARTIFICIAL (decl));
if (TREE_CODE (init) == TREE_LIST)
- init = build_constructor_from_list (NULL_TREE, init);
+ init = build_constructor_from_list (TREE_TYPE (decl), init);
gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
DECL_INITIAL (decl) = init;
DECL_INITIALIZED_P (decl) = 1;
type_dependent_p = dependent_type_p (type);
+ if (check_for_bare_parameter_packs (init))
+ {
+ init = NULL_TREE;
+ DECL_INITIAL (decl) = NULL_TREE;
+ }
+
if (init && init_const_expr_p)
{
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
if (TREE_CODE (decl) == TYPE_DECL)
{
if (type != error_mark_node
- && IS_AGGR_TYPE (type) && DECL_NAME (decl))
+ && MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
{
if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
warning (0, "shadowing previous type declaration of %q#D", decl);
is *not* defined. */
&& (!DECL_EXTERNAL (decl) || init))
{
- if (TYPE_FOR_JAVA (type) && IS_AGGR_TYPE (type))
+ if (TYPE_FOR_JAVA (type) && MAYBE_CLASS_TYPE_P (type))
{
tree jclass
= IDENTIFIER_GLOBAL_VALUE (get_identifier ("jclass"));
layout_type (type);
}
else if (TREE_CODE (decl) == FIELD_DECL
- && TYPE_FOR_JAVA (type) && IS_AGGR_TYPE (type))
+ && TYPE_FOR_JAVA (type) && MAYBE_CLASS_TYPE_P (type))
error ("non-static data member %qD has Java class type", decl);
/* Add this declaration to the statement-tree. This needs to happen
else
abstract_virtuals_error (decl, type);
- if (TREE_CODE (decl) == FUNCTION_DECL
- || TREE_TYPE (decl) == error_mark_node)
+ if (TREE_TYPE (decl) == error_mark_node)
/* No initialization required. */
;
+ else if (TREE_CODE (decl) == FUNCTION_DECL)
+ {
+ if (init)
+ {
+ if (init == ridpointers[(int)RID_DELETE])
+ {
+ /* fixme check this is 1st decl */
+ DECL_DELETED_FN (decl) = 1;
+ DECL_DECLARED_INLINE_P (decl) = 1;
+ DECL_INITIAL (decl) = error_mark_node;
+ }
+ else if (init == ridpointers[(int)RID_DEFAULT])
+ {
+ if (!defaultable_fn_p (decl))
+ error ("%qD cannot be defaulted", decl);
+ else
+ {
+ /* An out-of-class default definition is defined at
+ the point where it is explicitly defaulted. */
+ DECL_DEFAULTED_FN (decl) = 1;
+ if (DECL_INITIAL (decl) == error_mark_node)
+ synthesize_method (decl);
+ }
+ }
+ else
+ error ("function %q#D is initialized like a variable", decl);
+ }
+ /* else no initialization required. */
+ }
else if (DECL_EXTERNAL (decl)
&& ! (DECL_LANG_SPECIFIC (decl)
&& DECL_NOT_REALLY_EXTERN (decl)))
actually needed. It is unlikely that it will be inlined, since
it is only called via a function pointer, but we avoid unnecessary
emissions this way. */
- DECL_INLINE (fndecl) = 1;
- DECL_DECLARED_INLINE_P (fndecl) = 1;
DECL_INTERFACE_KNOWN (fndecl) = 1;
/* Build the parameter. */
if (use_cxa_atexit)
addr = build_address (decl);
/* The declared type of the parameter to "__cxa_atexit" is
"void *". For plain "T*", we could just let the
- machinery in build_function_call convert it -- but if the
+ machinery in cp_build_function_call convert it -- but if the
type is "cv-qualified T *", then we need to convert it
before passing it in, to avoid spurious errors. */
addr = build_nop (ptr_type_node, addr);
other value. */
addr = null_pointer_node;
args = tree_cons (NULL_TREE,
- build_unary_op (ADDR_EXPR, get_dso_handle_node (), 0),
+ cp_build_unary_op (ADDR_EXPR, get_dso_handle_node (), 0,
+ tf_warning_or_error),
NULL_TREE);
if (targetm.cxx.use_aeabi_atexit ())
{
}
else
args = tree_cons (NULL_TREE, cleanup, NULL_TREE);
- return build_function_call (get_atexit_node (), args);
+ return cp_build_function_call (get_atexit_node (), args,
+ tf_warning_or_error);
}
/* DECL is a VAR_DECL with static storage duration. INIT, if present,
void_list_node);
tree vfntype = build_function_type (void_type_node, argtypes);
acquire_fn = push_library_fn
- (acquire_fn, build_function_type (integer_type_node, argtypes));
- release_fn = push_library_fn (release_fn, vfntype);
- abort_fn = push_library_fn (abort_fn, vfntype);
+ (acquire_fn, build_function_type (integer_type_node, argtypes),
+ NULL_TREE);
+ release_fn = push_library_fn (release_fn, vfntype, NULL_TREE);
+ abort_fn = push_library_fn (abort_fn, vfntype, NULL_TREE);
}
else
{
The definition for a static data member shall appear in a
namespace scope enclosing the member's class definition. */
if (!is_ancestor (current_namespace, DECL_CONTEXT (decl)))
- pedwarn ("definition of %qD is not in namespace enclosing %qT",
- decl, DECL_CONTEXT (decl));
+ permerror ("definition of %qD is not in namespace enclosing %qT",
+ decl, DECL_CONTEXT (decl));
}
/* Build a PARM_DECL for the "this" parameter. TYPE is the
/* Allow this; it's pretty common in C. */;
else
{
- pedwarn ("non-local function %q#D uses anonymous type",
+ permerror ("non-local function %q#D uses anonymous type",
decl);
if (DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
- pedwarn ("%q+#D does not refer to the unqualified "
- "type, so it is not used for linkage",
- TYPE_NAME (t));
+ permerror ("%q+#D does not refer to the unqualified "
+ "type, so it is not used for linkage",
+ TYPE_NAME (t));
}
}
else
- pedwarn ("non-local function %q#D uses local type %qT", decl, t);
+ permerror ("non-local function %q#D uses local type %qT", decl, t);
}
}
/* If the declaration was declared inline, mark it as such. */
if (inlinep)
DECL_DECLARED_INLINE_P (decl) = 1;
- /* We inline functions that are explicitly declared inline, or, when
- the user explicitly asks us to, all functions. */
- if (DECL_DECLARED_INLINE_P (decl)
- || (flag_inline_trees == 2 && !DECL_INLINE (decl) && funcdef_flag))
- DECL_INLINE (decl) = 1;
DECL_EXTERNAL (decl) = 1;
if (quals && TREE_CODE (type) == FUNCTION_TYPE)
newtype = build_function_type (integer_type_node, oldtypeargs);
TREE_TYPE (decl) = newtype;
}
- check_main_parameter_types (decl);
+ if (warn_main)
+ check_main_parameter_types (decl);
}
if (ctype != NULL_TREE
unqualified_variant
= build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
- t = make_aggr_type (RECORD_TYPE);
+ t = make_class_type (RECORD_TYPE);
xref_basetypes (t, NULL_TREE);
/* Let the front end know this is a pointer to member function... */
TYPE_PTRMEMFUNC_FLAG (t) = 1;
- /* ... and not really an aggregate. */
- SET_IS_AGGR_TYPE (t, 0);
+ /* ... and not really a class type. */
+ SET_CLASS_TYPE_P (t, 0);
field = build_decl (FIELD_DECL, pfn_identifier, type);
fields = field;
TYPE_MAIN_VARIANT (t) = unqualified_variant;
TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (unqualified_variant);
TYPE_NEXT_VARIANT (unqualified_variant) = t;
+ TREE_TYPE (TYPE_BINFO (t)) = t;
}
/* Cache this pointer-to-member type so that we can find it again
later. */
TYPE_SET_PTRMEMFUNC_TYPE (type, t);
- /* Managing canonical types for the RECORD_TYPE behind a
- pointer-to-member function is a nightmare, so use structural
- equality for now. */
- SET_TYPE_STRUCTURAL_EQUALITY (t);
+ if (TYPE_STRUCTURAL_EQUALITY_P (type))
+ SET_TYPE_STRUCTURAL_EQUALITY (t);
+ else if (TYPE_CANONICAL (type) != type)
+ TYPE_CANONICAL (t) = build_ptrmemfunc_type (TYPE_CANONICAL (type));
return t;
}
error ("ISO C++ forbids in-class initialization of non-const "
"static member %qD",
decl);
- else if (pedantic && !INTEGRAL_TYPE_P (type))
- pedwarn ("ISO C++ forbids initialization of member constant "
+ else if (!INTEGRAL_TYPE_P (type))
+ pedwarn (OPT_pedantic, "ISO C++ forbids initialization of member constant "
"%qD of non-integral type %qT", decl, type);
return 0;
if (!abi_version_at_least (2) && processing_template_decl)
/* For abi-1, we handled all instances in templates the same way,
- even when they were non-dependent. This effects the manglings
+ even when they were non-dependent. This affects the manglings
produced. So, we do the normal checking for non-dependent
sizes, but at the end we'll return the same type that abi-1
would have, but with TYPE_CANONICAL set to the "right"
{
/* Check to see if the array bound overflowed. Make that an
error, no matter how generous we're being. */
- int old_flag_pedantic_errors = flag_pedantic_errors;
- int old_pedantic = pedantic;
- pedantic = flag_pedantic_errors = 1;
- constant_expression_warning (size);
- pedantic = old_pedantic;
- flag_pedantic_errors = old_flag_pedantic_errors;
+ constant_expression_error (size);
/* An array must have a positive number of elements. */
if (INT_CST_LT (size, integer_zero_node))
}
/* As an extension we allow zero-sized arrays. We always allow
them in system headers because glibc uses them. */
- else if (integer_zerop (size) && pedantic && !in_system_header)
+ else if (integer_zerop (size) && !in_system_header)
{
if (name)
- pedwarn ("ISO C++ forbids zero-size array %qD", name);
+ pedwarn (OPT_pedantic, "ISO C++ forbids zero-size array %qD", name);
else
- pedwarn ("ISO C++ forbids zero-size array");
+ pedwarn (OPT_pedantic, "ISO C++ forbids zero-size array");
}
}
else if (TREE_CONSTANT (size))
else if (pedantic && warn_vla != 0)
{
if (name)
- pedwarn ("ISO C++ forbids variable length array %qD", name);
+ pedwarn (OPT_Wvla, "ISO C++ forbids variable length array %qD", name);
else
- pedwarn ("ISO C++ forbids variable length array");
+ pedwarn (OPT_Wvla, "ISO C++ forbids variable length array");
}
else if (warn_vla > 0)
{
processing_template_decl = 0;
itype = cp_build_binary_op (MINUS_EXPR,
cp_convert (ssizetype, size),
- cp_convert (ssizetype, integer_one_node));
+ cp_convert (ssizetype, integer_one_node),
+ tf_warning_or_error);
itype = fold (itype);
processing_template_decl = saved_processing_template_decl;
Don't make a DECL node; just return the ..._TYPE node.
FIELD for a struct or union field; make a FIELD_DECL.
BITFIELD for a field with specified width.
- INITIALIZED is 1 if the decl has an initializer.
+ INITIALIZED is as for start_decl.
ATTRLIST is a pointer to the list of attributes, which may be NULL
if there are none; *ATTRLIST may be modified if attributes from inside
else if (decl_context == BITFIELD)
bitfield = 1, decl_context = FIELD;
+ if (initialized > 1)
+ funcdef_flag = true;
+
/* Look inside a declarator for the name being declared
and get it as a string, for an error message. */
for (id_declarator = declarator;
/* We've already issued an error, don't complain more. */;
else if (in_system_header || flag_ms_extensions)
/* Allow it, sigh. */;
- else if (pedantic || ! is_main)
- pedwarn ("ISO C++ forbids declaration of %qs with no type", name);
+ else if (! is_main)
+ permerror ("ISO C++ forbids declaration of %qs with no type", name);
+ else if (pedantic)
+ pedwarn (OPT_pedantic,
+ "ISO C++ forbids declaration of %qs with no type", name);
else
warning (OPT_Wreturn_type,
"ISO C++ forbids declaration of %qs with no type", name);
error ("%<long%> or %<short%> specified with char for %qs", name);
else if (long_p && short_p)
error ("%<long%> and %<short%> specified together for %qs", name);
+ else if (type == char16_type_node || type == char32_type_node)
+ {
+ if (signed_p || unsigned_p)
+ error ("%<signed%> or %<unsigned%> invalid for %qs", name);
+ else if (short_p || long_p)
+ error ("%<short%> or %<long%> invalid for %qs", name);
+ }
else
{
ok = 1;
if (!explicit_int && !defaulted_int && !explicit_char && pedantic)
{
- pedwarn ("long, short, signed or unsigned used invalidly for %qs",
+ pedwarn (OPT_pedantic,
+ "long, short, signed or unsigned used invalidly for %qs",
name);
if (flag_pedantic_errors)
ok = 0;
if (pedantic)
{
tree bad_type = build_qualified_type (type, type_quals);
- pedwarn ("ignoring %qV qualifiers added to function type %qT",
+ pedwarn (OPT_pedantic,
+ "ignoring %qV qualifiers added to function type %qT",
bad_type, type);
}
type_quals = TYPE_UNQUALIFIED;
if (virtualp
&& (current_class_name == NULL_TREE || decl_context != FIELD))
{
- error ("virtual outside class declaration");
+ error ("%<virtual%> outside class declaration");
virtualp = 0;
}
storage_class = sc_none;
}
}
- else if (storage_class == sc_extern && initialized
- && !funcdef_flag)
- {
- if (toplevel_bindings_p ())
- {
- /* It's common practice (and completely valid) to have a const
- be initialized and declared extern. */
- if (!(type_quals & TYPE_QUAL_CONST))
- warning (0, "%qs initialized and declared %<extern%>", name);
- }
- else
- error ("%qs has both %<extern%> and initializer", name);
- }
else if (storage_class == sc_extern && funcdef_flag
&& ! toplevel_bindings_p ())
error ("nested function %qs declared %<extern%>", name);
}
if (storage_class && friendp)
- error ("storage class specifiers invalid in friend function declarations");
+ {
+ error ("storage class specifiers invalid in friend function declarations");
+ storage_class = sc_none;
+ staticp = 0;
+ }
if (!id_declarator)
unqualified_id = NULL_TREE;
set_no_warning = true;
}
- /* Warn about some types functions can't return. */
+ /* Error about some types functions can't return. */
if (TREE_CODE (type) == FUNCTION_TYPE)
{
error ("%qs declared as function returning a function", name);
- type = integer_type_node;
+ return error_mark_node;
}
if (TREE_CODE (type) == ARRAY_TYPE)
{
error ("%qs declared as function returning an array", name);
- type = integer_type_node;
+ return error_mark_node;
}
/* Pick up type qualifiers which should be applied to `this'. */
explicitp = 2;
if (virtualp)
{
- pedwarn ("constructors cannot be declared virtual");
+ permerror ("constructors cannot be declared virtual");
virtualp = 0;
}
if (decl_context == FIELD
{
if (friendp)
{
- pedwarn ("member functions are implicitly friends of their class");
+ permerror ("member functions are implicitly friends of their class");
friendp = 0;
}
else
- pedwarn ("extra qualification %<%T::%> on member %qs",
- ctype, name);
+ permerror_at (declarator->id_loc,
+ "extra qualification %<%T::%> on member %qs",
+ ctype, name);
}
else if (/* If the qualifying type is already complete, then we
can skip the following checks. */
DECL_ABSTRACT (decl) = 1;
}
else if (constructor_name_p (unqualified_id, current_class_type))
- pedwarn ("ISO C++ forbids nested type %qD with same name "
- "as enclosing class",
- unqualified_id);
+ permerror ("ISO C++ forbids nested type %qD with same name "
+ "as enclosing class",
+ unqualified_id);
/* If the user declares "typedef struct {...} foo" then the
struct will have an anonymous name. Fill that name in now.
&& TYPE_NAME (type)
&& TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
&& TYPE_ANONYMOUS_P (type)
- /* Don't do this if there are attributes. */
- && (!attrlist || !*attrlist)
&& cp_type_quals (type) == TYPE_UNQUALIFIED)
{
tree oldname = TYPE_NAME (type);
{
/* Don't allow friend declaration without a class-key. */
if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
- pedwarn ("template parameters cannot be friends");
+ permerror ("template parameters cannot be friends");
else if (TREE_CODE (type) == TYPENAME_TYPE)
- pedwarn ("friend declaration requires class-key, "
- "i.e. %<friend class %T::%D%>",
- TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
+ permerror ("friend declaration requires class-key, "
+ "i.e. %<friend class %T::%D%>",
+ TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
else
- pedwarn ("friend declaration requires class-key, "
- "i.e. %<friend %#T%>",
- type);
+ permerror ("friend declaration requires class-key, "
+ "i.e. %<friend %#T%>",
+ type);
}
/* Only try to do this stuff if we didn't already give up. */
DECL_NONCONVERTING_P (decl) = 1;
else if (DECL_CONSTRUCTOR_P (decl))
{
- /* The constructor can be called with exactly one
- parameter if there is at least one parameter, and
- any subsequent parameters have default arguments.
+ /* A constructor with no parms is not a conversion.
Ignore any compiler-added parms. */
tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (decl);
- if (arg_types == void_list_node
- || (arg_types
- && TREE_CHAIN (arg_types)
- && TREE_CHAIN (arg_types) != void_list_node
- && !TREE_PURPOSE (TREE_CHAIN (arg_types))))
+ if (arg_types == void_list_node)
DECL_NONCONVERTING_P (decl) = 1;
}
}
{
/* Friends are treated specially. */
if (ctype == current_class_type)
- ; /* We already issued a pedwarn. */
+ ; /* We already issued a permerror. */
else if (decl && DECL_NAME (decl))
{
if (template_class_depth (current_class_type) == 0)
the rest of the compiler does not correctly
handle the initialization unless the member is
static so we make it static below. */
- pedwarn ("ISO C++ forbids initialization of member %qD",
- unqualified_id);
- pedwarn ("making %qD static", unqualified_id);
+ permerror ("ISO C++ forbids initialization of member %qD",
+ unqualified_id);
+ permerror ("making %qD static", unqualified_id);
staticp = 1;
}
&& pedantic)
{
if (storage_class == sc_static)
- pedwarn ("%<static%> specified invalid for function %qs "
+ pedwarn (OPT_pedantic,
+ "%<static%> specified invalid for function %qs "
"declared out of global scope", name);
else
- pedwarn ("%<inline%> specifier invalid for function %qs "
+ pedwarn (OPT_pedantic,
+ "%<inline%> specifier invalid for function %qs "
"declared out of global scope", name);
}
declaring main to be static. */
if (TREE_CODE (type) == METHOD_TYPE)
{
- pedwarn ("cannot declare member function %qD to have "
- "static linkage", decl);
+ permerror ("cannot declare member function %qD to have "
+ "static linkage", decl);
invalid_static = 1;
}
else if (current_function_decl)
DECL_CONTEXT (decl) = ctype;
if (staticp == 1)
{
- pedwarn ("%<static%> may not be used when defining "
- "(as opposed to declaring) a static data member");
+ permerror ("%<static%> may not be used when defining "
+ "(as opposed to declaring) a static data member");
staticp = 0;
storage_class = sc_none;
}
}
if (storage_class == sc_extern && pedantic)
{
- pedwarn ("cannot explicitly declare member %q#D to have "
- "extern linkage",
- decl);
+ pedwarn (OPT_pedantic,
+ "cannot explicitly declare member %q#D to have "
+ "extern linkage", decl);
storage_class = sc_none;
}
}
}
+ if (storage_class == sc_extern && initialized && !funcdef_flag)
+ {
+ if (toplevel_bindings_p ())
+ {
+ /* It's common practice (and completely valid) to have a const
+ be initialized and declared extern. */
+ if (!(type_quals & TYPE_QUAL_CONST))
+ warning (0, "%qs initialized and declared %<extern%>", name);
+ }
+ else
+ {
+ error ("%qs has both %<extern%> and initializer", name);
+ return error_mark_node;
+ }
+ }
+
/* Record `register' declaration for warnings on &
and in case doing stupid register allocation. */
if (type != error_mark_node
&& TYPE_FOR_JAVA (type)
- && IS_AGGR_TYPE (type))
+ && MAYBE_CLASS_TYPE_P (type))
{
error ("parameter %qD has Java class type", decl);
type = error_mark_node;
/* Remember any special properties of member function DECL. */
-void grok_special_member_properties (tree decl)
+void
+grok_special_member_properties (tree decl)
{
tree class_type;
{
int ctor = copy_fn_p (decl);
- TYPE_HAS_CONSTRUCTOR (class_type) = 1;
+ if (!DECL_ARTIFICIAL (decl))
+ TYPE_HAS_USER_CONSTRUCTOR (class_type) = 1;
if (ctor > 0)
{
are no other parameters or else all other parameters have
default arguments. */
TYPE_HAS_INIT_REF (class_type) = 1;
+ if (!DECL_DEFAULTED_FN (decl))
+ TYPE_HAS_COMPLEX_INIT_REF (class_type) = 1;
if (ctor > 1)
TYPE_HAS_CONST_INIT_REF (class_type) = 1;
}
else if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
+ else if (is_list_ctor (decl))
+ TYPE_HAS_LIST_CTOR (class_type) = 1;
}
else if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR)
{
if (assop)
{
TYPE_HAS_ASSIGN_REF (class_type) = 1;
+ if (!DECL_DEFAULTED_FN (decl))
+ TYPE_HAS_COMPLEX_ASSIGN_REF (class_type) = 1;
if (assop != 1)
TYPE_HAS_CONST_ASSIGN_REF (class_type) = 1;
}
gcc_unreachable ();
}
while (0);
- gcc_assert (operator_code != LAST_CPLUS_TREE_CODE);
+ gcc_assert (operator_code != MAX_TREE_CODES);
SET_OVERLOADED_OPERATOR_CODE (decl, operator_code);
if (class_type)
}
if (operator_code == NEW_EXPR || operator_code == VEC_NEW_EXPR)
- TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl));
+ {
+ TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl));
+ DECL_IS_OPERATOR_NEW (decl) = 1;
+ }
else if (operator_code == DELETE_EXPR || operator_code == VEC_DELETE_EXPR)
TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl));
else
if (arg == error_mark_node)
return false;
- /* IS_AGGR_TYPE, rather than CLASS_TYPE_P, is used
+ /* MAYBE_CLASS_TYPE_P, rather than CLASS_TYPE_P, is used
because these checks are performed even on
template functions. */
- if (IS_AGGR_TYPE (arg) || TREE_CODE (arg) == ENUMERAL_TYPE)
+ if (MAYBE_CLASS_TYPE_P (arg)
+ || TREE_CODE (arg) == ENUMERAL_TYPE)
break;
}
if (t == class_type)
what = "the same type";
/* Don't force t to be complete here. */
- else if (IS_AGGR_TYPE (t)
+ else if (MAYBE_CLASS_TYPE_P (t)
&& COMPLETE_TYPE_P (t)
&& DERIVED_FROM_P (t, class_type))
what = "a base class";
if (operator_code == POSTINCREMENT_EXPR
|| operator_code == POSTDECREMENT_EXPR)
{
- if (pedantic)
- pedwarn ("%qD cannot have default arguments", decl);
+ pedwarn (OPT_pedantic, "%qD cannot have default arguments",
+ decl);
}
else
{
}
else
{
- t = make_aggr_type (code);
+ t = make_class_type (code);
TYPE_CONTEXT (t) = context;
t = pushtag (name, t, scope);
}
}
else
{
- if (template_header_p && IS_AGGR_TYPE (t))
+ if (template_header_p && MAYBE_CLASS_TYPE_P (t))
{
if (!redeclare_class_template (t, current_template_parms))
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
basetype = PACK_EXPANSION_PATTERN (basetype);
if (TREE_CODE (basetype) == TYPE_DECL)
basetype = TREE_TYPE (basetype);
- if (TREE_CODE (basetype) != RECORD_TYPE
- && TREE_CODE (basetype) != TYPENAME_TYPE
- && TREE_CODE (basetype) != TEMPLATE_TYPE_PARM
- && TREE_CODE (basetype) != BOUND_TEMPLATE_TEMPLATE_PARM)
+ if (!MAYBE_CLASS_TYPE_P (basetype) || TREE_CODE (basetype) == UNION_TYPE)
{
error ("base type %qT fails to be a struct or class type",
basetype);
underlying_type = integer_types[itk_unsigned_long_long];
}
- /* Compute the minium and maximum values for the type.
+ /* Compute the minimum and maximum values for the type.
[dcl.enum]
saved_location = input_location;
input_location = DECL_SOURCE_LOCATION (decl);
value = perform_implicit_conversion (underlying_type,
- DECL_INITIAL (decl));
+ DECL_INITIAL (decl),
+ tf_warning_or_error);
input_location = saved_location;
/* Do not clobber shared ints. */
DECL_CONTEXT (decl) = FROB_CONTEXT (context);
TREE_CONSTANT (decl) = 1;
- TREE_INVARIANT (decl) = 1;
TREE_READONLY (decl) = 1;
DECL_INITIAL (decl) = value;
if (dependent_type_p (return_type))
return;
if (!COMPLETE_OR_VOID_TYPE_P (return_type)
- || (TYPE_FOR_JAVA (return_type) && IS_AGGR_TYPE (return_type)))
+ || (TYPE_FOR_JAVA (return_type) && MAYBE_CLASS_TYPE_P (return_type)))
{
tree args = TYPE_ARG_TYPES (fntype);
FIXME factor out the non-RTL stuff. */
bl = current_binding_level;
allocate_struct_function (decl1, processing_template_decl);
+
+ /* Initialize the language data structures. Whenever we start
+ a new function, we destroy temporaries in the usual way. */
+ cfun->language = GGC_CNEW (struct language_function);
+ current_stmt_tree ()->stmts_are_full_exprs_p = 1;
current_binding_level = bl;
/* Even though we're inside a function body, we still don't want to
call expand_expr to calculate the size of a variable-sized array.
We haven't necessarily assigned RTL to all variables yet, so it's
not safe to try to expand expressions involving them. */
- cfun->x_dont_save_pending_sizes_p = 1;
+ cfun->dont_save_pending_sizes_p = 1;
/* Start the statement-tree, start the tree now. */
DECL_SAVED_TREE (decl1) = push_stmt_list ();
gcc_assert (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE);
cp_function_chain->x_current_class_ref
- = build_indirect_ref (t, NULL);
+ = cp_build_indirect_ref (t, NULL, tf_warning_or_error);
cp_function_chain->x_current_class_ptr = t;
/* Constructors and destructors need to know whether they're "in
tree val;
tree exprstmt;
- if (targetm.cxx.cdtor_returns_this ())
+ if (targetm.cxx.cdtor_returns_this ()
+ && (! TYPE_FOR_JAVA (current_class_type)))
{
/* Any return from a constructor will end up here. */
add_stmt (build_stmt (LABEL_EXPR, cdtor_label));
of curly braces, skipping the artificial block created for constructor
initializers. */
-static tree
+tree
outer_curly_brace_block (tree fndecl)
{
tree block = BLOCK_SUBBLOCKS (DECL_INITIAL (fndecl));
/* Hack. We don't want the middle-end to warn that this
return is unreachable, so put the statement on the
special line 0. */
-#ifdef USE_MAPPED_LOCATION
{
location_t linezero = linemap_line_start (line_table, 0, 1);
SET_EXPR_LOCATION (stmt, linezero);
}
-#else
- annotate_with_file_line (stmt, input_filename, 0);
-#endif
}
if (use_eh_spec_block (current_function_decl))
/* Don't complain if we abort or throw. */
&& !current_function_returns_abnormally
&& !DECL_NAME (DECL_RESULT (fndecl))
- /* Normally, with -Wreturn-type, flow will complain. Unless we're an
- inline function, as we might never be compiled separately. */
- && (DECL_INLINE (fndecl) || processing_template_decl)
+ && !TREE_NO_WARNING (fndecl)
/* Structor return values (if any) are set by the compiler. */
&& !DECL_CONSTRUCTOR_P (fndecl)
&& !DECL_DESTRUCTOR_P (fndecl))
- warning (OPT_Wreturn_type, "no return statement in function returning non-void");
+ {
+ warning (OPT_Wreturn_type,
+ "no return statement in function returning non-void");
+ TREE_NO_WARNING (fndecl) = 1;
+ }
/* Store the end of the function, so that we get good line number
info for the epilogue. */
f->extern_decl_map = NULL;
/* Handle attribute((warn_unused_result)). Relies on gimple input. */
- c_warn_unused_result (&DECL_SAVED_TREE (fndecl));
+ c_warn_unused_result (gimple_body (fndecl));
}
/* Clear out the bits we don't need. */
local_names = NULL;
check_template_shadow (fndecl);
DECL_DECLARED_INLINE_P (fndecl) = 1;
- if (flag_default_inline)
- DECL_INLINE (fndecl) = 1;
/* We process method specializations in finish_struct_1. */
if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
}
/* Called when a class type (given by TYPE) is defined. If there are
- any existing VAR_DECLs whose type hsa been completed by this
+ any existing VAR_DECLs whose type has been completed by this
declaration, update them now. */
void
initial checks on the attribute. Note that those checks
include ensuring that the function found is not an overloaded
function, or an object with an overloaded call operator,
- etc.; we can rely on the fact that the functionfound is an
+ etc.; we can rely on the fact that the function found is an
ordinary FUNCTION_DECL. */
fn = lookup_name (id);
arg = build_address (decl);
mark_used (decl);
- cleanup = build_function_call (fn, build_tree_list (NULL_TREE,
- arg));
+ cleanup = cp_build_function_call (fn, build_tree_list (NULL_TREE,
+ arg),
+ tf_warning_or_error);
}
/* Handle ordinary C++ destructors. */
type = TREE_TYPE (decl);
DECL_STATIC_FUNCTION_P (decl) = 1;
}
-/* Initialize the variables used during compilation of a C++
- function. */
-
-void
-cxx_push_function_context (struct function * f)
-{
- struct language_function *p = GGC_CNEW (struct language_function);
- f->language = p;
-
- /* Whenever we start a new function, we destroy temporaries in the
- usual way. */
- current_stmt_tree ()->stmts_are_full_exprs_p = 1;
-
- if (f->decl)
- {
- tree fn = f->decl;
-
- if (DECL_SAVED_FUNCTION_DATA (fn))
- {
- /* If we already parsed this function, and we're just expanding it
- now, restore saved state. */
- *cp_function_chain = *DECL_SAVED_FUNCTION_DATA (fn);
-
- /* We don't need the saved data anymore. Unless this is an inline
- function; we need the named return value info for
- declare_return_variable. */
- if (! DECL_INLINE (fn))
- DECL_SAVED_FUNCTION_DATA (fn) = NULL;
- }
- }
-}
-
-/* Free the language-specific parts of F, now that we've finished
- compiling the function. */
-
-void
-cxx_pop_function_context (struct function * f)
-{
- f->language = 0;
-}
-
/* Return which tree structure is used by T, or TS_CP_GENERIC if T is
one of the language-independent trees. */