diff options
author | Paolo Carlini <pcarlini@suse.de> | 2007-03-30 19:45:57 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2007-03-30 19:45:57 +0000 |
commit | cb68ec50055e516ac270a043f772935561b01968 (patch) | |
tree | 63250c95176e6d94178beae6b2735b398dfbfec1 /gcc/doc | |
parent | c7a0240aa55b4f7a2d11d33bd12af7a40f42aa55 (diff) | |
download | gcc-cb68ec50055e516ac270a043f772935561b01968.zip gcc-cb68ec50055e516ac270a043f772935561b01968.tar.gz gcc-cb68ec50055e516ac270a043f772935561b01968.tar.bz2 |
re PR c++/26099 (support for type traits is not available)
gcc/
2007-03-30 Paolo Carlini <pcarlini@suse.de>
PR c++/26099
* c-common.h (enum rid): Add RID_HAS_NOTHROW_ASSIGN,
RID_HAS_NOTHROW_CONSTRUCTOR, RID_HAS_NOTHROW_COPY,
RID_HAS_TRIVIAL_ASSIGN, RID_HAS_TRIVIAL_CONSTRUCTOR,
RID_HAS_TRIVIAL_COPY, RID_HAS_TRIVIAL_DESTRUCTOR,
RID_HAS_VIRTUAL_DESTRUCTOR, RID_IS_ABSTRACT, RID_IS_BASE_OF,
RID_IS_CONVERTIBLE_TO, RID_IS_CLASS, RID_IS_EMPTY, RID_IS_ENUM,
RID_IS_POD, RID_IS_POLYMORPHIC, RID_IS_UNION, as
C++ extensions.
* doc/extend.texi (Extensions to the C++ Language): Add Type Traits.
gcc/cp/
2007-03-30 Paolo Carlini <pcarlini@suse.de>
PR c++/26099
* cp-tree.h (enum cp_trait_kind, struct tree_trait_expr,
TRAIT_EXPR_TYPE1, TRAIT_EXPR_TYPE2, TRAIT_EXPR_KIND): Add.
(enum cp_tree_node_structure_enum, union lang_tree_node): Update.
(CLASS_TYPE_NON_UNION_P): Add.
(struct lang_type_class): Add has_complex_dflt.
(TYPE_HAS_COMPLEX_DFLT, TYPE_HAS_TRIVIAL_DFLT): Add.
(locate_copy, locate_ctor, locate_dtor, finish_trait_expr): Declare.
* cp-tree.def: Add TRAIT_EXPR.
* cp-objcp-common.c (cp_tree_size): Add TRAIT_EXPR case.
* lex.c (struct resword): Add __has_nothrow_assign,
__has_nothrow_constructor, __has_nothrow_copy, __has_trivial_assign,
__has_trivial_constructor, __has_trivial_copy,
__has_trivial_destructor, __has_virtual_destructor, __is_abstract,
__is_base_of, __is_class, __is_convertible_to, __is_empty, __is_enum,
__is_pod, __is_polymorphic, __is_union.
* parser.c (cp_parser_primary_expression): Deal with the new RIDs.
(cp_parser_trait_expr): New.
* semantics.c (finish_trait_expr, trait_expr_value
classtype_has_nothrow_copy_or_assign_p): New.
* method.c (locate_copy, locate_ctor, locate_dtor): Do not define
as static.
* decl.c (cp_tree_node_structure): Add TRAIT_EXPR.
* class.c (check_bases, check_field_decl, check_bases_and_members):
Deal with TYPE_HAS_COMPLEX_DFLT (t) too.
* pt.c (uses_template_parms, tsubst_copy_and_build,
value_dependent_expression_p, type_dependent_expression_p): Deal with
TRAIT_EXPR.
* tree.c (cp_walk_subtrees): Deal with TRAIT_EXPR.
gcc/testsuite/
2007-03-30 Paolo Carlini <pcarlini@suse.de>
PR c++/26099
* g++.dg/ext/is_base_of.C: New.
* g++.dg/ext/has_virtual_destructor.C: New.
* g++.dg/ext/is_polymorphic.C: New.
* g++.dg/ext/is_base_of_diagnostic.C: New.
* g++.dg/ext/is_enum.C: New.
* g++.dg/ext/has_nothrow_assign.C: New.
* g++.dg/ext/has_nothrow_constructor.C: New.
* g++.dg/ext/is_empty.C: New.
* g++.dg/ext/has_trivial_copy.C: New.
* g++.dg/ext/has_trivial_assign.C: New.
* g++.dg/ext/is_abstract.C: New.
* g++.dg/ext/is_pod.C: New.
* g++.dg/ext/has_nothrow_copy.C: New.
* g++.dg/ext/is_class.C: New.
* g++.dg/ext/has_trivial_constructor.C: New.
* g++.dg/ext/is_union.C: New.
* g++.dg/ext/has_trivial_destructor.C: New.
* g++.dg/tree-ssa/pr22444.C: Adjust, avoid __is_pod.
* g++.dg/template/crash43.C: Likewise.
libstdc++-v3/
2007-03-30 Paolo Carlini <pcarlini@suse.de>
PR c++/26099
* include/bits/cpp_type_traits.h (struct __is_pod, struct __is_empty):
Remove.
* include/bits/valarray_array.h: Adjust.
* include/bits/allocator.h: Likewise.
* include/bits/stl_tree.h: Likewise.
From-SVN: r123366
Diffstat (limited to 'gcc/doc')
-rw-r--r-- | gcc/doc/extend.texi | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index d01e5fa..ccdc995 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -10675,6 +10675,7 @@ Predefined Macros,cpp,The GNU C Preprocessor}). method denoted by a @samp{->*} or @samp{.*} expression. * C++ Attributes:: Variable, function, and type attributes for C++ only. * Namespace Association:: Strong using-directives for namespace association. +* Type Traits:: Compiler support for type traits * Java Exceptions:: Tweaking exception handling to work with Java. * Deprecated Features:: Things will disappear from g++. * Backwards Compatibility:: Compatibilities with earlier definitions of C++. @@ -11232,6 +11233,124 @@ int main() @} @end smallexample +@node Type Traits +@section Type Traits + +The C++ front-end implements syntactic extensions that allow to +determine at compile time various characteristics of a type (or of a +pair of types). + +@table @code +@item __has_nothrow_assign (type) +If @code{__has_trivial_assign (type)} is true then the trait is true, else if +@code{type} is a cv class or union type with copy assignment operators that +are known not to throw an exception then the trait is true, else it is false. +If @code{type} is const qualified, any copy assignment operator must +be both known not to throw an exception, and const qualified, for the +trait to be true. Requires: @code{type} shall be a complete type, an +array type of unknown bound, or is a @code{void} type. + +@item __has_nothrow_copy (type) +If @code{__has_trivial_copy (type)} is true then the trait is true, else if +@code{type} is a cv class or union type with copy constructors that +are known not to throw an exception then the trait is true, else it is false. +Requires: @code{type} shall be a complete type, an array type of +unknown bound, or is a @code{void} type. + +@item __has_nothrow_constructor (type) +If @code{__has_trivial_constructor (type)} is true then the trait is +true, else if @code{type} is a cv class or union type (or array +thereof) with a default constructor that is known not to throw an +exception then the trait is true, else it is false. Requires: +@code{type} shall be a complete type, an array type of unknown bound, +or is a @code{void} type. + +@item __has_trivial_assign (type) +If @code{type} is const qualified or is a reference type then the trait is +false. Otherwise if @code{__is_pod (type)} is true then the trait is +true, else if @code{type} is a cv class or union type with a trivial +copy assignment ([class.copy]) then the trait is true, else it is +false. Requires: @code{type} shall be a complete type, an array type +of unknown bound, or is a @code{void} type. + +@item __has_trivial_copy (type) +If @code{__is_pod (type)} is true or @code{type} is a reference type +then the trait is true, else if @code{type} is a cv class or union type +with a trivial copy constructor ([class.copy]) then the trait +is true, else it is false. Requires: @code{type} shall be a complete +type, an array type of unknown bound, or is a @code{void} type. + +@item __has_trivial_constructor (type) +If @code{__is_pod (type)} is true then the trait is true, else if +@code{type} is a cv class or union type (or array thereof) with a +trivial default constructor ([class.ctor]) then the trait is true, +else it is false. Requires: @code{type} shall be a complete type, an +array type of unknown bound, or is a @code{void} type. + +@item __has_trivial_destructor (type) +If @code{__is_pod (type)} is true or @code{type} is a reference type then +the trait is true, else if @code{type} is a cv class or union type (or +array thereof) with a trivial destructor ([class.dtor]) then the trait +is true, else it is false. Requires: @code{type} shall be a complete +type, an array type of unknown bound, or is a @code{void} type. + +@item __has_virtual_destructor (type) +If @code{type} is a class type with a virtual destructor +([class.dtor]) then the trait is true, else it is false. Requires: +@code{type} shall be a complete type, an array type of unknown bound, +or is a @code{void} type. + +@item __is_abstract (type) +If @code{type} is an abstract class ([class.abstract]) then the trait +is true, else it is false. Requires: @code{type} shall be a complete +type, an array type of unknown bound, or is a @code{void} type. + +@item __is_base_of (base_type, derived_type) +If @code{base_type} is a base class of @code{derived_type} +([class.derived]) then the trait is true, otherwise it is false. +Top-level cv qualifications of @code{base_type} and +@code{derived_type} are ignored. For the purposes of this trait, a +class type is considered is own base. Requires: if @code{__is_class +(base_type)} and @code{__is_class (derived_type)} are true and +@code{base_type} and @code{derived_type} are not the same type +(disregarding cv-qualifiers), @code{derived_type} shall be a complete +type. Diagnostic is produced if this requirement is not met. + +@item __is_class (type) +If @code{type} is a cv class type, and not a union type +([basic.compound]) the the trait is true, else it is false. + +@item __is_empty (type) +If @code{__is_class (type)} is false then the trait is false. +Otherwise @code{type} is considered empty if and only if: @code{type} +has no non-static data members, or all non-static data members, if +any, are bit-fields of lenght 0, and @code{type} has no virtual +members, and @code{type} has no virtual base classes, and @code{type} +has no base classes @code{base_type} for which +@code{__is_empty (base_type)} is false. Requires: @code{type} shall +be a complete type, an array type of unknown bound, or is a +@code{void} type. + +@item __is_enum (type) +If @code{type} is a cv enumeration type ([basic.compound]) the the trait is +true, else it is false. + +@item __is_pod (type) +If @code{type} is a cv POD type ([basic.types]) then the trait is true, +else it is false. Requires: @code{type} shall be a complete type, +an array type of unknown bound, or is a @code{void} type. + +@item __is_polymorphic (type) +If @code{type} is a polymorphic class ([class.virtual]) then the trait +is true, else it is false. Requires: @code{type} shall be a complete +type, an array type of unknown bound, or is a @code{void} type. + +@item __is_union (type) +If @code{type} is a cv union type ([basic.compound]) the the trait is +true, else it is false. + +@end table + @node Java Exceptions @section Java Exceptions |