This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH RFA: Avoid enum bitfield in C++ frontend


In C++, this kind of code is invalid:

enum e { A = 1, B = 2, C = 4 };
extern void f1(enum e);
void f2() { f1(A | B); }

The expression A | B has type "int", not type "enum e".  Passing an int
to a function which expects an enum is an invalid conversion in C++.

gcc's C++ frontend uses this construct all over the place in the form of
the tsubst_flags_t enum.  The values are bitmasks (tf_error, tf_warning,
etc.) which are or'ed together.  The functions which take combinations
of these bits are declared with the type tsubst_flags_t.

I have an unsubmitted patch to the C frontend which makes cases like
this an error when using -Wc++-compat.  In preparation for submitting
that patch, I would like to clean up the C++ frontend.

The patch in this e-mail messages changes tsubst_flags_t to int.  It
eliminates the tsubst_flags_t typedef.  Since type names ending in "_t"
are reserved by POSIX, I also renamed the enum type (the "_t" is
probably OK in C but probably not OK in C++).

This is how I think the code looks best--I don't see a need for a
special type to hold this combination of bitfields.  However, it would
be a smaller change to let the C++ frontend continue to use
tsubst_flags_t, and simply do "typedef int tsubst_flags_t".  If the C++
frontend maintainers would prefer that patch, I can do that instead.

This patch was bootstrapped and tested on i686-pc-linux-gnu.

OK for mainline?

Ian


2009-04-13  Ian Lance Taylor  <iant@google.com>

	* cp-tree.h (enum tsubst_flags): Rename from enum tsubst_flags_t.
	(tsubst_flags_t): Remove typedef.
	* cp-tree.h: Change parameter types from tsubst_flags_t to int in
	declarations.
	* call.c (standard_conversion): Change tflags from tsubst_flags_t
	to int.
	(build_new_function_call): Change parameter type from
	tsubst_flags_t to int.
	(build_object_call, build_conditional_expr): Likewise.
	(build_new_op, convert_like_real, build_over_call): Likewise.
	(build_special_member_call, build_new_method_call): Likewise.
	(perform_implicit_conversion): Likewise.
	(perform_direct_initialization_if_possible): Likewise.
	* class.c (resolve_address_of_overloaded_function): Likewise.
	(instantiate_type): Likewise.
	* cp-lang.c (objcp_tsubst_copy_and_build): Likewise.
	* cvt.c (convert_to_void): Likewise.
	* decl.c (make_typename_type): Likewise.
	(make_unbound_class_template): Likewise.
	* init.c (build_aggr_init): Likewise.
	(expand_default_init, expand_aggr_init_1): Likewise.
	(build_new_1, build_new, build_vec_init): Likewise.
	* pt.c (reduce_template_parm_level): Likewise.
	(coerce_template_template_parm): Likewise.
	(coerce_template_template_parms): Likewise.
	(convert_template_argument): Likewise.
	(coerce_template_parameter_pack): Likewise.
	(coerce_template_parms, lookup_template_class): Likewise.
	(apply_late_template_attributes): Likewise.
	(tsubst_template_arg, tsubst_pack_expansion): Likewise.
	(tsubst_template_args, tsubst_template_parms): Likewise.
	(tsubst_aggr_type, tsubst_decl, tsubst_arg_types): Likewise.
	(tsubst_function_type, tsubst_exception_specification): Likewise.
	(tsubst, tsubst_baselink, tsubst_copy): Likewise.
	(tsubst_omp_clauses, tsubst_copy_asm_operands): Likewise.
	(tsubst_omp_for_iterator, tsubst_expr): Likewise.
	(tsubst_non_call_postfix_expression): Likewise.
	(tsubst_copy_and_build): Likewise.
	(check_instantiated_arg, check_instantiated_args): Likewise.
	(instantiate_template, do_type_instantiation): Likewise.
	(invalid_nontype_parm_type_p): Likewise.
	* rtti.c (build_dynamic_cast_1): Likewise.
	(build_dynamic_cast): Likewise.
	* semantics.c (finish_call_expr): Likewise.
	* tree.c (cp_build_qualified_type_real): Likewise.
	* typeck.c (composite_pointer_type_r): Likewise.
	(composite_pointer_type, cxx_sizeof_expr): Likewise.
	(cxx_alignof_expr, invalid_nonstatic_memfn_p): Likewise.
	(rationalize_conditional_expr): Likewise.
	(build_class_member_access_expr): Likewise.
	(finish_class_member_access_expr): Likewise.
	(build_x_indirect_ref, cp_build_indirect_ref): Likewise.
	(cp_build_function_call, convert_arguments): Likewise.
	(build_x_binary_op, build_x_array_ref): Likewise.
	(cp_build_binary_op, build_x_unary_op): Likewise.
	(cp_build_unary_op, build_x_conditional_expr): Likewise.
	(build_x_compound_expr, cp_build_compound_expr): Likewise.
	(build_static_cast_1, build_static_cast): Likewise.
	(build_reinterpret_cast_1, build_reinterpret_cast): Likewise.
	(build_const_cast, cp_build_c_cast): Likewise.
	(cp_build_modify_expr, build_x_modify_expr): Likewise.
	(convert_for_assignment, convert_for_initialization): Likewise.
	(lvalue_or_else): Likewise.
	* typeck2.c (build_functional_cast): Likewise.
	* cp-objcp-common.h (objcp_tsubst_copy_and_build): Update
	declaration.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]