This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ Patch] PR 33464
Gabriel Dos Reis wrote:
On Tue, 18 Sep 2007, Paolo Carlini wrote:
| Hi again Gaby,
|
| >Could you try pp_type_id, or since you'd be in the implementation
| >file, pp_cxx_type_id?
| >
| >
| The below passes regtesting. What do you think? If you parefer I can call
| pp_cxx_trait_expression directly from error.c, without passing from
| pp_cxx_primary_expression,
If you can do that, that would be great! Modified patch pre-approved.
Excellent. The below amended variant is going in.
Paolo.
/////////////////
/cp
2007-09-18 Paolo Carlini <pcarlini@suse.de>
PR c++/33464
* cxx-pretty-print.c (pp_cxx_trait_expression): Add.
(pp_cxx_primary_expression): Use it.
* cxx-pretty-print.h (pp_cxx_trait_expression): Declare.
* error.c (dump_expr): Use it.
/testsuite
2007-09-18 Paolo Carlini <pcarlini@suse.de>
PR c++/33464
* g++.dg/ext/is_class_error.C: Rename to is_class_error1.C.
* g++.dg/ext/is_class_error2.C: New.
Index: testsuite/g++.dg/ext/is_class_error2.C
===================================================================
*** testsuite/g++.dg/ext/is_class_error2.C (revision 0)
--- testsuite/g++.dg/ext/is_class_error2.C (revision 0)
***************
*** 0 ****
--- 1,22 ----
+ // PR c++/33464
+
+ template<int> void foo()
+ {
+ __has_nothrow_assign(int)(); // { dg-error "'__has_nothrow_assign\\(int\\)' cannot be used" }
+ __has_trivial_assign(int)(); // { dg-error "'__has_trivial_assign\\(int\\)' cannot be used" }
+ __has_nothrow_constructor(int)(); // { dg-error "'__has_nothrow_constructor\\(int\\)' cannot be used" }
+ __has_trivial_constructor(int)(); // { dg-error "'__has_trivial_constructor\\(int\\)' cannot be used" }
+ __has_nothrow_copy(int)(); // { dg-error "'__has_nothrow_copy\\(int\\)' cannot be used" }
+ __has_trivial_copy(int)(); // { dg-error "'__has_trivial_copy\\(int\\)' cannot be used" }
+ __has_trivial_destructor(int)(); // { dg-error "'__has_trivial_destructor\\(int\\)' cannot be used" }
+ __has_virtual_destructor(int)(); // { dg-error "'__has_virtual_destructor\\(int\\)' cannot be used" }
+ __is_abstract(int)(); // { dg-error "'__is_abstract\\(int\\)' cannot be used" }
+ __is_base_of(int, float)(); // { dg-error "'__is_base_of\\(int, float\\)' cannot be used" }
+ __is_class(int)(); // { dg-error "'__is_class\\(int\\)' cannot be used" }
+ __is_convertible_to(int, float)(); // { dg-error "unimplemented" }
+ __is_empty(int)(); // { dg-error "'__is_empty\\(int\\)' cannot be used" }
+ __is_enum(int)(); // { dg-error "'__is_enum\\(int\\)' cannot be used" }
+ __is_pod(int)(); // { dg-error "'__is_pod\\(int\\)' cannot be used" }
+ __is_polymorphic(int)(); // { dg-error "'__is_polymorphic\\(int\\)' cannot be used" }
+ __is_union(int)(); // { dg-error "'__is_union\\(int\\)' cannot be used" }
+ }
Index: testsuite/g++.dg/ext/is_class_error.C
===================================================================
*** testsuite/g++.dg/ext/is_class_error.C (revision 128570)
--- testsuite/g++.dg/ext/is_class_error.C (working copy)
***************
*** 1,6 ****
- // PR c++/33212
-
- template<int> void foo()
- {
- __is_class((int); // { dg-error "type-specifier|primary-expression" }
- }
--- 0 ----
Index: cp/error.c
===================================================================
*** cp/error.c (revision 128570)
--- cp/error.c (working copy)
*************** dump_expr (tree t, int flags)
*** 2054,2059 ****
--- 2054,2063 ----
dump_type (t, flags);
break;
+ case TRAIT_EXPR:
+ pp_cxx_trait_expression (cxx_pp, t);
+ break;
+
/* This list is incomplete, but should suffice for now.
It is very important that `sorry' does not call
`report_error_function'. That could cause an infinite loop. */
Index: cp/cxx-pretty-print.c
===================================================================
*** cp/cxx-pretty-print.c (revision 128570)
--- cp/cxx-pretty-print.c (working copy)
*************** pp_cxx_id_expression (cxx_pretty_printer
*** 348,354 ****
:: operator-function-id
:: qualifier-id
( expression )
! id-expression */
static void
pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t)
--- 348,373 ----
:: operator-function-id
:: qualifier-id
( expression )
! id-expression
!
! GNU Extensions:
! __has_nothrow_assign ( type-id )
! __has_nothrow_constructor ( type-id )
! __has_nothrow_copy ( type-id )
! __has_trivial_assign ( type-id )
! __has_trivial_constructor ( type-id )
! __has_trivial_copy ( type-id )
! __has_trivial_destructor ( type-id )
! __has_virtual_destructor ( type-id )
! __is_abstract ( type-id )
! __is_base_of ( type-id , type-id )
! __is_class ( type-id )
! __is_convertible_to ( type-id , type-id )
! __is_empty ( type-id )
! __is_enum ( type-id )
! __is_pod ( type-id )
! __is_polymorphic ( type-id )
! __is_union ( type-id ) */
static void
pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t)
*************** pp_cxx_primary_expression (cxx_pretty_pr
*** 387,392 ****
--- 406,415 ----
pp_cxx_right_paren (pp);
break;
+ case TRAIT_EXPR:
+ pp_cxx_trait_expression (pp, t);
+ break;
+
default:
pp_c_primary_expression (pp_c_base (pp), t);
break;
*************** pp_cxx_declaration (cxx_pretty_printer *
*** 2123,2128 ****
--- 2146,2225 ----
}
}
+ void
+ pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t)
+ {
+ cp_trait_kind kind = TRAIT_EXPR_KIND (t);
+
+ switch (kind)
+ {
+ case CPTK_HAS_NOTHROW_ASSIGN:
+ pp_cxx_identifier (pp, "__has_nothrow_assign");
+ break;
+ case CPTK_HAS_TRIVIAL_ASSIGN:
+ pp_cxx_identifier (pp, "__has_trivial_assign");
+ break;
+ case CPTK_HAS_NOTHROW_CONSTRUCTOR:
+ pp_cxx_identifier (pp, "__has_nothrow_constructor");
+ break;
+ case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
+ pp_cxx_identifier (pp, "__has_trivial_constructor");
+ break;
+ case CPTK_HAS_NOTHROW_COPY:
+ pp_cxx_identifier (pp, "__has_nothrow_copy");
+ break;
+ case CPTK_HAS_TRIVIAL_COPY:
+ pp_cxx_identifier (pp, "__has_trivial_copy");
+ break;
+ case CPTK_HAS_TRIVIAL_DESTRUCTOR:
+ pp_cxx_identifier (pp, "__has_trivial_destructor");
+ break;
+ case CPTK_HAS_VIRTUAL_DESTRUCTOR:
+ pp_cxx_identifier (pp, "__has_virtual_destructor");
+ break;
+ case CPTK_IS_ABSTRACT:
+ pp_cxx_identifier (pp, "__is_abstract");
+ break;
+ case CPTK_IS_BASE_OF:
+ pp_cxx_identifier (pp, "__is_base_of");
+ break;
+ case CPTK_IS_CLASS:
+ pp_cxx_identifier (pp, "__is_class");
+ break;
+ case CPTK_IS_CONVERTIBLE_TO:
+ pp_cxx_identifier (pp, "__is_convertible_to");
+ break;
+ case CPTK_IS_EMPTY:
+ pp_cxx_identifier (pp, "__is_empty");
+ break;
+ case CPTK_IS_ENUM:
+ pp_cxx_identifier (pp, "__is_enum");
+ break;
+ case CPTK_IS_POD:
+ pp_cxx_identifier (pp, "__is_pod");
+ break;
+ case CPTK_IS_POLYMORPHIC:
+ pp_cxx_identifier (pp, "__is_polymorphic");
+ break;
+ case CPTK_IS_UNION:
+ pp_cxx_identifier (pp, "__is_union");
+ break;
+
+ default:
+ gcc_unreachable ();
+ }
+
+ pp_cxx_left_paren (pp);
+ pp_cxx_type_id (pp, TRAIT_EXPR_TYPE1 (t));
+
+ if (kind == CPTK_IS_BASE_OF || kind == CPTK_IS_CONVERTIBLE_TO)
+ {
+ pp_cxx_separate_with (pp, ',');
+ pp_cxx_type_id (pp, TRAIT_EXPR_TYPE2 (t));
+ }
+
+ pp_cxx_right_paren (pp);
+ }
typedef c_pretty_print_fn pp_fun;
Index: cp/cxx-pretty-print.h
===================================================================
*** cp/cxx-pretty-print.h (revision 128570)
--- cp/cxx-pretty-print.h (working copy)
*************** void pp_cxx_separate_with (cxx_pretty_pr
*** 69,74 ****
void pp_cxx_declaration (cxx_pretty_printer *, tree);
void pp_cxx_canonical_template_parameter (cxx_pretty_printer *, tree);
!
#endif /* GCC_CXX_PRETTY_PRINT_H */
--- 69,74 ----
void pp_cxx_declaration (cxx_pretty_printer *, tree);
void pp_cxx_canonical_template_parameter (cxx_pretty_printer *, tree);
! void pp_cxx_trait_expression (cxx_pretty_printer *, tree);
#endif /* GCC_CXX_PRETTY_PRINT_H */