static void record_unknown_type (tree, const char *);
static tree builtin_function_1 (tree, tree, bool);
static int member_function_or_else (tree, tree, enum overload_flags);
-static void check_for_uninitialized_const_var (tree);
static tree local_variable_p_walkfn (tree *, int *, void *);
static const char *tag_name (enum tag_types);
static tree lookup_and_check_tag (enum tag_types, tree, tag_scope, bool);
}
}
-/* Issue an error message if DECL is an uninitialized const variable. */
+/* Issue an error message if DECL is an uninitialized const variable.
+ CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
+ context from potential_constant_expression. Returns true if all is well,
+ false otherwise. */
-static void
-check_for_uninitialized_const_var (tree decl)
+bool
+check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
+ tsubst_flags_t complain)
{
tree type = strip_array_types (TREE_TYPE (decl));
7.1.6 */
if (VAR_P (decl)
&& TREE_CODE (type) != REFERENCE_TYPE
- && (CP_TYPE_CONST_P (type) || var_in_constexpr_fn (decl))
- && !DECL_INITIAL (decl))
+ && (constexpr_context_p
+ || CP_TYPE_CONST_P (type) || var_in_constexpr_fn (decl))
+ && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
{
tree field = default_init_uninitialized_part (type);
if (!field)
- return;
+ return true;
- if (CP_TYPE_CONST_P (type))
- permerror (DECL_SOURCE_LOCATION (decl),
- "uninitialized const %qD", decl);
- else
+ if (!constexpr_context_p)
{
- if (!is_instantiation_of_constexpr (current_function_decl))
- error_at (DECL_SOURCE_LOCATION (decl),
- "uninitialized variable %qD in %<constexpr%> function",
- decl);
- cp_function_chain->invalid_constexpr = true;
+ if (CP_TYPE_CONST_P (type))
+ {
+ if (complain & tf_error)
+ permerror (DECL_SOURCE_LOCATION (decl),
+ "uninitialized const %qD", decl);
+ }
+ else
+ {
+ if (!is_instantiation_of_constexpr (current_function_decl)
+ && (complain & tf_error))
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "uninitialized variable %qD in %<constexpr%> "
+ "function", decl);
+ cp_function_chain->invalid_constexpr = true;
+ }
}
+ else if (complain & tf_error)
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "uninitialized variable %qD in %<constexpr%> context",
+ decl);
- if (CLASS_TYPE_P (type))
+ if (CLASS_TYPE_P (type) && (complain & tf_error))
{
tree defaulted_ctor;
"and the implicitly-defined constructor does not "
"initialize %q#D", field);
}
+
+ return false;
}
+
+ return true;
}
\f
/* Structure holding the current initializer being processed by reshape_init.
flags |= LOOKUP_ALREADY_DIGESTED;
}
else if (!init)
- check_for_uninitialized_const_var (decl);
+ check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
+ tf_warning_or_error);
/* Do not reshape constructors of vectors (they don't need to be
reshaped. */
else if (BRACE_ENCLOSED_INITIALIZER_P (init))
diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false,
/*complain=*/true);
- check_for_uninitialized_const_var (decl);
+ check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
+ tf_warning_or_error);
}
if (init && init != error_mark_node)