diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2011-04-25 22:27:19 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2011-04-25 22:27:19 +0000 |
commit | a0d260fcc5f6fe1a246e8ee40235a825369f3627 (patch) | |
tree | b836cd0e728b772f3240bdb6c981032673cb2745 /gcc/cp/semantics.c | |
parent | d95f258e9027e7d797bde4eace3e29ab7d9382db (diff) | |
download | gcc-a0d260fcc5f6fe1a246e8ee40235a825369f3627.zip gcc-a0d260fcc5f6fe1a246e8ee40235a825369f3627.tar.gz gcc-a0d260fcc5f6fe1a246e8ee40235a825369f3627.tar.bz2 |
c-common.c (struct c_common_resword): Add __underlying_type.
/gcc
2011-04-25 Paolo Carlini <paolo.carlini@oracle.com>
* c-family/c-common.c (struct c_common_resword): Add
__underlying_type.
* c-family/c-common.h (enum rid): Add RID_UNDERLYING_TYPE.
/cp
2011-04-25 Paolo Carlini <paolo.carlini@oracle.com>
* cp-tree.def: Add a new UNDERLYING_TYPE tree code.
* cp-tree.h (enum cp_trait_kind): Add CPTK_UNDERLYING_TYPE, tidy.
(UNDERLYING_TYPE_TYPE): Add.
* cp-objcp-common.c (cp_common_init_ts): Mark UNDERLYING_TYPE
as TS_COMMON.
* parser.c (cp_lexer_next_token_is_decl_specifier_keyword,
cp_parser_simple_type_specifier): Handle UNDERLYING_TYPE.
(cp_parser_trait_expr): Deal with RID_UNDERLYING_TYPE; tidy.
* semantics.c (finish_underlying_type): New.
* typeck.c (structural_comptypes): Handle UNDERLYING_TYPE.
* error.c (dump_type, dump_type_prefix, dump_type_suffix): Likewise.
* cxx-pretty-print.c (p_cxx_type_id): Likewise.
* tree.c (cp_walk_subtrees): Likewise.
* pt.c (for_each_template_parm_r, tsubst, unify,
dependent_type_p_r): Likewise.
* mangle.c (write_type): Sorry for __underlying_type.
* doc/extend.texi: Document __underlying_type.
/testsuite
2011-04-25 Paolo Carlini <paolo.carlini@oracle.com>
* g++.dg/ext/underlying_type1.C: New.
* g++.dg/ext/underlying_type2.C: Likewise.
* g++.dg/ext/underlying_type3.C: Likewise.
* g++.dg/ext/underlying_type4.C: Likewise.
* g++.dg/ext/underlying_type5.C: Likewise.
* g++.dg/ext/underlying_type6.C: Likewise.
* g++.dg/ext/underlying_type7.C: Likewise.
* g++.dg/ext/underlying_type8.C: Likewise.
* g++.dg/ext/underlying_type9.C: Likewise.
* g++.dg/ext/underlying_type10.C: Likewise.
From-SVN: r172943
Diffstat (limited to 'gcc/cp/semantics.c')
-rw-r--r-- | gcc/cp/semantics.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 7763ae0..62272aa 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3366,6 +3366,44 @@ finish_typeof (tree expr) return type; } +/* Implement the __underlying_type keyword: Return the underlying + type of TYPE, suitable for use as a type-specifier. */ + +tree +finish_underlying_type (tree type) +{ + tree underlying_type; + + if (processing_template_decl) + { + underlying_type = cxx_make_type (UNDERLYING_TYPE); + UNDERLYING_TYPE_TYPE (underlying_type) = type; + SET_TYPE_STRUCTURAL_EQUALITY (underlying_type); + + return underlying_type; + } + + complete_type (type); + + if (TREE_CODE (type) != ENUMERAL_TYPE) + { + error ("%qE is not an enumeration type", type); + return error_mark_node; + } + + underlying_type = ENUM_UNDERLYING_TYPE (type); + + /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE + includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information. + See finish_enum_value_list for details. */ + if (!ENUM_FIXED_UNDERLYING_TYPE_P (type)) + underlying_type + = c_common_type_for_mode (TYPE_MODE (underlying_type), + TYPE_UNSIGNED (underlying_type)); + + return underlying_type; +} + /* Perform C++-specific checks for __builtin_offsetof before calling fold_offsetof. */ |