This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] PR52
- To: gcc-patches at gcc dot gnu dot org
- Subject: [C++ PATCH] PR52
- From: Nathan Sidwell <nathan at codesourcery dot com>
- Date: Wed, 08 Mar 2000 12:06:59 +0000
- Organization: CodeSourcery, LLC
Hi
the attached patch makes it more obvious why g++ was moaning about
a conversion op to void. You can define one, it'll just never
be called. [12.3.2] not even virtually via a base.
g++.old-deja/g++.bugs/900215_01.C was testing for this behaviour,
which it marked as an error. The comments in that test suggest
this got batted about several times during C++ drafting.
We now don't warn at the out-of-class definition, because
grok_op_properties treats it as friendp when current_class is
NULL -- perhaps grok_fndecl should set that earlier?
ok?
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2000-03-08 Nathan Sidwell <nathan@codesourcery.com>
* decl.c (grok_op_properties): Merge conversion to void warning
with other silly op warnings.
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl.c,v
retrieving revision 1.559
diff -c -3 -p -r1.559 decl.c
*** decl.c 2000/03/08 11:21:27 1.559
--- decl.c 2000/03/08 11:45:22
*************** grok_op_properties (decl, virtualp, frie
*** 11980,11995 ****
if (IDENTIFIER_TYPENAME_P (name) && ! DECL_TEMPLATE_INFO (decl))
{
tree t = TREE_TYPE (name);
! if (TREE_CODE (t) == VOID_TYPE)
! pedwarn ("void is not a valid type conversion operator");
! else if (! friendp)
{
int ref = (TREE_CODE (t) == REFERENCE_TYPE);
const char *what = 0;
if (ref)
t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
! if (t == current_class_type)
what = "the same type";
/* Don't force t to be complete here. */
else if (IS_AGGR_TYPE (t)
--- 11980,11996 ----
if (IDENTIFIER_TYPENAME_P (name) && ! DECL_TEMPLATE_INFO (decl))
{
tree t = TREE_TYPE (name);
! if (! friendp)
{
int ref = (TREE_CODE (t) == REFERENCE_TYPE);
const char *what = 0;
+
if (ref)
t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
! if (TREE_CODE (t) == VOID_TYPE)
! what = "void";
! else if (t == current_class_type)
what = "the same type";
/* Don't force t to be complete here. */
else if (IS_AGGR_TYPE (t)
2000-03-08 Nathan Sidwell <nathan@codesourcery.com>
* g++.old-deja/g++.bugs/900215_01.C: Adjust.
Index: testsuite/g++.old-deja/g++.bugs/900215_01.C
===================================================================
RCS file: /cvs/gcc/egcs/gcc/testsuite/g++.old-deja/g++.bugs/900215_01.C,v
retrieving revision 1.2
diff -c -3 -p -r1.2 900215_01.C
*** 900215_01.C 1998/12/16 21:28:54 1.2
--- 900215_01.C 2000/03/08 12:06:03
***************
*** 16,30 ****
// keywords: user-defined type conversion operators, void type, explicit casts
struct struct0 {
! operator void (); // ERROR - operator void
};
int exit_status = 1;
struct0::operator void ()
! { // ERROR - operator void
exit_status = 0;
}
--- 16,33 ----
// keywords: user-defined type conversion operators, void type, explicit casts
+ // 8/3/2000 (nathan): The std allows you to define such an op, but
+ // it will never be called. [class.conv.fct]. Make it an unconditional warning.
+
struct struct0 {
! operator void (); // WARNING - operator void
};
int exit_status = 1;
struct0::operator void ()
! {
exit_status = 0;
}