From aa4313ebb01ea82f6c62cc08dfa221d980b6bf1d Mon Sep 17 00:00:00 2001 From: redi Date: Thu, 15 Dec 2011 10:02:45 +0000 Subject: [PATCH] c-family: PR libstdc++/51365 * c-common.c (RID_IS_FINAL): Add. * c-common.h (RID_IS_FINAL): Add. cp: PR libstdc++/51365 * cp-tree.h (CPTK_IS_FINAL): Add. * parser.c (cp_parser_translation_unit): Handle RID_IS_FINAL. (cp_parser_primary_expression, cp_parser_trait_expr): Likewise. * semantics.c (trait_expr_value, finish_trait_expr): Handle CPTK_IS_FINAL. * cxx-pretty-print.c (pp_cxx_trait_expression): Likewise. testsuite: PR libstdc++/51365 * g++.dg/ext/is_final.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@182360 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/c-family/ChangeLog | 6 +++++ gcc/c-family/c-common.c | 1 + gcc/c-family/c-common.h | 12 +++++----- gcc/cp/ChangeLog | 10 ++++++++ gcc/cp/cp-tree.h | 1 + gcc/cp/cxx-pretty-print.c | 3 +++ gcc/cp/parser.c | 5 ++++ gcc/cp/semantics.c | 5 ++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/ext/is_final.C | 46 +++++++++++++++++++++++++++++++++++++ 10 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_final.C diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 075da2f43b3..78854e2f81b 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2011-12-15 Jonathan Wakely + + PR libstdc++/51365 + * c-common.c (RID_IS_FINAL): Add. + * c-common.h (RID_IS_FINAL): Add. + 2011-11-30 Iain Sandoe * c.opt (fgnu-runtime): Provide full description. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index fbbcb3841dd..3e50dcf924f 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -462,6 +462,7 @@ const struct c_common_resword c_common_reswords[] = { "__is_convertible_to", RID_IS_CONVERTIBLE_TO, D_CXXONLY }, { "__is_empty", RID_IS_EMPTY, D_CXXONLY }, { "__is_enum", RID_IS_ENUM, D_CXXONLY }, + { "__is_final", RID_IS_FINAL, D_CXXONLY }, { "__is_literal_type", RID_IS_LITERAL_TYPE, D_CXXONLY }, { "__is_pod", RID_IS_POD, D_CXXONLY }, { "__is_polymorphic", RID_IS_POLYMORPHIC, D_CXXONLY }, diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 8ef95aa0b17..103c5816ac4 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -134,7 +134,7 @@ enum rid RID_CONSTCAST, RID_DYNCAST, RID_REINTCAST, RID_STATCAST, /* C++ extensions */ - RID_BASES, RID_DIRECT_BASES, + RID_BASES, RID_DIRECT_BASES, RID_HAS_NOTHROW_ASSIGN, RID_HAS_NOTHROW_CONSTRUCTOR, RID_HAS_NOTHROW_COPY, RID_HAS_TRIVIAL_ASSIGN, RID_HAS_TRIVIAL_CONSTRUCTOR, RID_HAS_TRIVIAL_COPY, @@ -142,12 +142,12 @@ enum rid RID_IS_ABSTRACT, RID_IS_BASE_OF, RID_IS_CLASS, RID_IS_CONVERTIBLE_TO, RID_IS_EMPTY, RID_IS_ENUM, - RID_IS_LITERAL_TYPE, RID_IS_POD, - RID_IS_POLYMORPHIC, RID_IS_STD_LAYOUT, - RID_IS_TRIVIAL, RID_IS_UNION, - RID_UNDERLYING_TYPE, + RID_IS_FINAL, RID_IS_LITERAL_TYPE, + RID_IS_POD, RID_IS_POLYMORPHIC, + RID_IS_STD_LAYOUT, RID_IS_TRIVIAL, + RID_IS_UNION, RID_UNDERLYING_TYPE, - /* C++0x */ + /* C++11 */ RID_CONSTEXPR, RID_DECLTYPE, RID_NOEXCEPT, RID_NULLPTR, RID_STATIC_ASSERT, /* Objective-C ("AT" reserved words - they are only keywords when diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 07816eb5c4f..7e99f58f037 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2011-12-15 Jonathan Wakely + + PR libstdc++/51365 + * cp-tree.h (CPTK_IS_FINAL): Add. + * parser.c (cp_parser_translation_unit): Handle RID_IS_FINAL. + (cp_parser_primary_expression, cp_parser_trait_expr): Likewise. + * semantics.c (trait_expr_value, finish_trait_expr): Handle + CPTK_IS_FINAL. + * cxx-pretty-print.c (pp_cxx_trait_expression): Likewise. + 2011-12-14 Jason Merrill PR c++/51554 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index a96adbb17b2..42a9ced641a 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -587,6 +587,7 @@ typedef enum cp_trait_kind CPTK_IS_CONVERTIBLE_TO, CPTK_IS_EMPTY, CPTK_IS_ENUM, + CPTK_IS_FINAL, CPTK_IS_LITERAL_TYPE, CPTK_IS_POD, CPTK_IS_POLYMORPHIC, diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c index 55cb64b21e4..3d10afb837c 100644 --- a/gcc/cp/cxx-pretty-print.c +++ b/gcc/cp/cxx-pretty-print.c @@ -2380,6 +2380,9 @@ pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t) case CPTK_IS_ENUM: pp_cxx_ws_string (pp, "__is_enum"); break; + case CPTK_IS_FINAL: + pp_cxx_ws_string (pp, "__is_final"); + break; case CPTK_IS_POD: pp_cxx_ws_string (pp, "__is_pod"); break; diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 49b508ce83a..9301e531407 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -3854,6 +3854,7 @@ cp_parser_translation_unit (cp_parser* parser) __is_convertible_to ( type-id , type-id ) __is_empty ( type-id ) __is_enum ( type-id ) + __is_final ( type-id ) __is_literal_type ( type-id ) __is_pod ( type-id ) __is_polymorphic ( type-id ) @@ -4199,6 +4200,7 @@ cp_parser_primary_expression (cp_parser *parser, case RID_IS_CONVERTIBLE_TO: case RID_IS_EMPTY: case RID_IS_ENUM: + case RID_IS_FINAL: case RID_IS_LITERAL_TYPE: case RID_IS_POD: case RID_IS_POLYMORPHIC: @@ -7868,6 +7870,9 @@ cp_parser_trait_expr (cp_parser* parser, enum rid keyword) case RID_IS_ENUM: kind = CPTK_IS_ENUM; break; + case RID_IS_FINAL: + kind = CPTK_IS_FINAL; + break; case RID_IS_LITERAL_TYPE: kind = CPTK_IS_LITERAL_TYPE; break; diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index ef85e453ad3..2f2a26a0d52 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -5434,6 +5434,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: return (type_code1 == ENUMERAL_TYPE); + case CPTK_IS_FINAL: + return (CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1)); + case CPTK_IS_LITERAL_TYPE: return (literal_type_p (type1)); @@ -5493,6 +5496,7 @@ finish_trait_expr (cp_trait_kind kind, tree type1, tree type2) || kind == CPTK_IS_CONVERTIBLE_TO || kind == CPTK_IS_EMPTY || kind == CPTK_IS_ENUM + || kind == CPTK_IS_FINAL || kind == CPTK_IS_LITERAL_TYPE || kind == CPTK_IS_POD || kind == CPTK_IS_POLYMORPHIC @@ -5533,6 +5537,7 @@ finish_trait_expr (cp_trait_kind kind, tree type1, tree type2) case CPTK_HAS_VIRTUAL_DESTRUCTOR: case CPTK_IS_ABSTRACT: case CPTK_IS_EMPTY: + case CPTK_IS_FINAL: case CPTK_IS_LITERAL_TYPE: case CPTK_IS_POD: case CPTK_IS_POLYMORPHIC: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 66880f0e0a7..71c3f67a245 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-12-15 Jonathan Wakely + + PR libstdc++/51365 + * g++.dg/ext/is_final.C: New. + 2012-12-15 Richard Guenther PR lto/48508 diff --git a/gcc/testsuite/g++.dg/ext/is_final.C b/gcc/testsuite/g++.dg/ext/is_final.C new file mode 100644 index 00000000000..7833f3a101b --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_final.C @@ -0,0 +1,46 @@ +// PR c++/51365 +// { dg-do compile } +// { dg-options "-std=c++0x" } + +struct A { }; +static_assert( ! __is_final (A), "A not final" ); + +struct Af final { }; +static_assert( __is_final (Af), "Af is final" ); + +class B { }; +static_assert( ! __is_final (B), "B not final" ); + +class Bf final { }; +static_assert( __is_final (Bf), "Bf is final" ); + +struct C : private A, private B { }; +static_assert( ! __is_final (C), "C not final" ); + +struct Cf final : private A, private B { }; +static_assert( __is_final (Cf), "Cf is final" ); + +struct D { virtual ~D() final { } }; +static_assert( ! __is_final (D), "D not final" ); + +struct Df final { virtual ~Df() final { } }; +static_assert( __is_final (Df), "Df is final" ); + +template struct E { }; +static_assert( ! __is_final (E), "E not final" ); +static_assert( ! __is_final (E), "E not final" ); + +template struct Ef final { }; +static_assert( __is_final (Ef), "Ef is final" ); +static_assert( __is_final (Ef), "Ef is final" ); +static_assert( __is_final (Ef), "Ef is final" ); + +template struct F { virtual ~F() final { }; }; +static_assert( ! __is_final (F), "F not final" ); +static_assert( ! __is_final (F), "F not final" ); + +template struct Ff final { virtual ~Ff() final { }; }; +static_assert( __is_final (Ff), "Ff is final" ); +static_assert( __is_final (Ff), "Ff is final" ); +static_assert( __is_final (Ff), "Ff is final" ); + -- 2.11.0