aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/init.c
diff options
context:
space:
mode:
authorGabriel Dos Reis <gdr@cs.tamu.edu>2010-10-27 15:31:33 -0400
committerJason Merrill <jason@gcc.gnu.org>2010-10-27 15:31:33 -0400
commit91ea6df357db9c986090683aa22cfa1ea2547213 (patch)
tree935f90ff364485ab5facda1e86039d079df9a040 /gcc/cp/init.c
parent3b49d762b5d6845f6c09926a0a6b2d5e0471a755 (diff)
downloadgcc-91ea6df357db9c986090683aa22cfa1ea2547213.zip
gcc-91ea6df357db9c986090683aa22cfa1ea2547213.tar.gz
gcc-91ea6df357db9c986090683aa22cfa1ea2547213.tar.bz2
parser.c (cp_parser_ctor_initializer_opt_and_function_body): Make sure a constexpr ctor has an empty body.
* parser.c (cp_parser_ctor_initializer_opt_and_function_body): Make sure a constexpr ctor has an empty body. * class.c (type_has_constexpr_default_constructor): New. * cp-tree.h: Declare it. * init.c (perform_member_init): Complain about uninitialized member in constexpr ctor. (emit_mem_initializers): And uninitialized base. * decl.c (check_tag_decl): Fix typo. * semantics.c (valid_type_in_constexpr_fundecl_p): New fn. (is_valid_constexpr_fn): New fn. (validate_constexpr_fundecl): Use it. * decl.c (validate_constexpr_redeclaration): New. (duplicate_decls): Use it. (cp_finish_decl): Call validate_constexpr_fundecl and ensure_literal_type_for_constexpr_object here. (start_decl): Not here. Don't ICE on constexpr reference. (check_for_uninitialized_const_var): Don't handle constexpr specially. (grokfndecl): Set DECL_DECLARED_CONSTEXPR_P. (check_static_variable_definition): Give friendly message about missing constexpr. (grokdeclarator): Complain about typedef and volatile with constexpr. Reorganize. Give sorry about non-static data members in C++0x mode. (start_preparsed_function): Check validate_constexpr_fundecl here. (check_function_type): Not here. * decl2.c (finish_static_data_member_decl): Don't complain about in-class init. * parser.c (CP_PARSER_FLAGS_ONLY_TYPE_OR_CONSTEXPR): New. (cp_parser_condition): Pass it to cp_parser_decl_specifier_seq. (cp_parser_decl_specifier_seq): Handle it. (cp_parser_explicit_instantiation): Diagnose inline and constexpr. Co-Authored-By: Jason Merrill <jason@redhat.com> From-SVN: r166013
Diffstat (limited to 'gcc/cp/init.c')
-rw-r--r--gcc/cp/init.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 9c2afba..3a6e2e7 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -533,6 +533,15 @@ perform_member_init (tree member, tree init)
"uninitialized member %qD with %<const%> type %qT",
member, type);
+ if (DECL_DECLARED_CONSTEXPR_P (current_function_decl)
+ && !type_has_constexpr_default_constructor (type))
+ {
+ if (!DECL_TEMPLATE_INSTANTIATION (current_function_decl))
+ error ("uninitialized member %qD in %<constexpr%> constructor",
+ member);
+ DECL_DECLARED_CONSTEXPR_P (current_function_decl) = false;
+ }
+
core_type = strip_array_types (type);
if (CLASS_TYPE_P (core_type)
&& (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
@@ -864,17 +873,30 @@ emit_mem_initializers (tree mem_inits)
tree subobject = TREE_PURPOSE (mem_inits);
tree arguments = TREE_VALUE (mem_inits);
- /* If these initializations are taking place in a copy constructor,
- the base class should probably be explicitly initialized if there
- is a user-defined constructor in the base class (other than the
- default constructor, which will be called anyway). */
- if (extra_warnings && !arguments
- && DECL_COPY_CONSTRUCTOR_P (current_function_decl)
- && type_has_user_nondefault_constructor (BINFO_TYPE (subobject)))
- warning_at (DECL_SOURCE_LOCATION (current_function_decl), OPT_Wextra,
- "base class %q#T should be explicitly initialized in the "
- "copy constructor",
- BINFO_TYPE (subobject));
+ if (arguments == NULL_TREE)
+ {
+ /* If these initializations are taking place in a copy constructor,
+ the base class should probably be explicitly initialized if there
+ is a user-defined constructor in the base class (other than the
+ default constructor, which will be called anyway). */
+ if (extra_warnings
+ && DECL_COPY_CONSTRUCTOR_P (current_function_decl)
+ && type_has_user_nondefault_constructor (BINFO_TYPE (subobject)))
+ warning_at (DECL_SOURCE_LOCATION (current_function_decl),
+ OPT_Wextra, "base class %q#T should be explicitly "
+ "initialized in the copy constructor",
+ BINFO_TYPE (subobject));
+
+ if (DECL_DECLARED_CONSTEXPR_P (current_function_decl)
+ && !(type_has_constexpr_default_constructor
+ (BINFO_TYPE (subobject))))
+ {
+ if (!DECL_TEMPLATE_INSTANTIATION (current_function_decl))
+ error ("uninitialized base %qT in %<constexpr%> constructor",
+ BINFO_TYPE (subobject));
+ DECL_DECLARED_CONSTEXPR_P (current_function_decl) = false;
+ }
+ }
/* Initialize the base. */
if (BINFO_VIRTUAL_P (subobject))