Bug 18803 - [3.4 regression] rejects access to operator() in template
Summary: [3.4 regression] rejects access to operator() in template
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 3.4.5
Assignee: Volker Reichelt
URL:
Keywords: rejects-valid
Depends on: 18445
Blocks:
  Show dependency treegraph
 
Reported: 2004-12-02 23:42 UTC by Wolfgang Bangerth
Modified: 2005-09-17 20:53 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.4
Known to fail: 3.4.5
Last reconfirmed: 2004-12-02 23:44:42


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Bangerth 2004-12-02 23:42:23 UTC
Here's a recent regression (within the last 6 weeks or so): 
----------------------- 
struct A { 
  int operator() (); 
}; 
 
template <int> void foo () { 
  A &a = *new A(); 
  const int i = a(); 
} 
----------------------- 
deal.II/lac> c++ -c x.cc 
x.cc: In function 'void foo()': 
x.cc:8: error: 'a' cannot be used as a function 
 
That's clearly bogus. Of course the error goes away once the function 
is made a nontemplate. 
 
This error triggers about a dozen times in my code... 
 
W.
Comment 1 Andrew Pinski 2004-12-02 23:44:42 UTC
: Search converges between 2004-11-25-014001-trunk (#656) and 2004-11-25-161001-trunk 
(#657).

Confirmed.
Comment 2 Wolfgang Bangerth 2004-12-02 23:57:31 UTC
I would venture a guess that it was this patch: 
 
2004-11-25  Mark Mitchell  <mark@codesourcery.com> 
 
	PR c++/18445 
	* class.c (instantiate_type): Treat NON_DEPENDENT_EXPRs with 
	unknown_type as non matching.  Tidy up. 
	* pt.c (build_non_dependent_expr): Do not build a 
	NON_DEPENDENT_EXPR for a VAR_DECL. 
 
W. 
Comment 3 GCC Commits 2004-12-08 08:36:35 UTC
Subject: Bug 18803

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	nathan@gcc.gnu.org	2004-12-08 08:36:10

Modified files:
	gcc/cp         : ChangeLog call.c class.c cp-tree.h cvt.c decl.c 
	                 decl2.c except.c init.c parser.c pt.c rtti.c 
	                 semantics.c typeck.c typeck2.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: operator5.C 

Log message:
	cp:
	PR c++/18803
	* cp-tree.h (REFERENCE_REF_P): New.
	(CPTI_TYPE_INFO_TYPE): Rename to ...
	(CPTI_CONST_TYPE_INFO_TYPE): ... here.
	(CPTI_TYPE_INFO_REF_TYPE): Remove.
	(type_info_type_node): Rename to ...
	(const_type_info_type_node): ... here.
	(type_info_ref_type): Remove.
	* call.c (build_user_type_conversion): Reformat.
	(resolve_args): Do not convert_from_reference.
	(build_object_call): Call convert_from_reference.
	(prep_operand): Do not convert_from_reference.
	(build_new_method_call): Likewise.
	* class.c (build_vfield_ref): Likewise.
	* cvt.c (convert_to_reference): Likewise.
	(convert_from_reference): Build INDIRECT_REF here, not with
	build_indirect_ref.
	(convert_force): Do not convert_from_reference.
	(build_expr_type_conversion): Likewise.
	* decl.c (grok_reference_init): Likewise.
	* decl2.c (delete_sanity): Likewise.
	* except.c (initialize_handler_parm): Use POINTER_TYPE_P.
	* init.c (build_dtor_call): Do not convert_from_reference.
	* parser.c (cp_parser_template_argument): Unwrap indirected
	reference. Allow TEMPLATE_PARM_INDEX as an object parm.
	* pt.c (tsubst_copy_and_build) <case INDIRECT_REF>: Use
	convert_from_reference, if indicated.
	<case CALL_EXPR>: Do not convert_from_reference.
	<case PARM_DECL, VAR_DECL>: Convert_from_reference if needed.
	(tsubst_initializer_list): Do not convert_from_reference.
	* rtti.c (init_rtti_processing): Adjust node creation.
	(throw_bad_typeid): Use const_type_info_type_node.
	Do not convert_from_reference.
	(typeid_ok_p): Use const_type_info_type_node.
	(build_typeid, get_typeid): Always return type_info typed node.
	(build_dynamic_cast_1): Dont convert_from_reference. Refactor.
	* semantics.c (finish_stmt_expr_expr): Do not
	convert_from_reference.
	(finish_id_expression): Convert_from_reference as appropriate.
	* typeck.c (decay_conversion): Do not convert_from_reference.
	(finish_class_member_access_expr): Likewise.
	(build_indirect_ref): Use POINTER_TYPE_P.
	(convert_arguments): Do not convert_from_reference.
	(build_modify_expr): Likewise.
	(convert_for_initialization): Likewise.
	* typeck2.c (build_x_arrow): Likewise.
	testsuite:
	PR c++/18803
	* g++.dg/template/operator5.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4519&r2=1.4520
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.521&r2=1.522
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&r1=1.691&r2=1.692
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.1079&r2=1.1080
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cvt.c.diff?cvsroot=gcc&r1=1.172&r2=1.173
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1338&r2=1.1339
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.759&r2=1.760
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/except.c.diff?cvsroot=gcc&r1=1.177&r2=1.178
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&r1=1.402&r2=1.403
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.289&r2=1.290
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.955&r2=1.956
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/rtti.c.diff?cvsroot=gcc&r1=1.204&r2=1.205
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.451&r2=1.452
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.600&r2=1.601
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck2.c.diff?cvsroot=gcc&r1=1.179&r2=1.180
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4721&r2=1.4722
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/operator5.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 Nathan Sidwell 2004-12-08 08:40:47 UTC
2004-12-08  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/18803
	* cp-tree.h (REFERENCE_REF_P): New.
	(CPTI_TYPE_INFO_TYPE): Rename to ...
	(CPTI_CONST_TYPE_INFO_TYPE): ... here.
	(CPTI_TYPE_INFO_REF_TYPE): Remove.
	(type_info_type_node): Rename to ...
	(const_type_info_type_node): ... here.
	(type_info_ref_type): Remove.
	* call.c (build_user_type_conversion): Reformat.
	(resolve_args): Do not convert_from_reference.
	(build_object_call): Call convert_from_reference.
	(prep_operand): Do not convert_from_reference.
	(build_new_method_call): Likewise.
	* class.c (build_vfield_ref): Likewise.
	* cvt.c (convert_to_reference): Likewise.
	(convert_from_reference): Build INDIRECT_REF here, not with
	build_indirect_ref.
	(convert_force): Do not convert_from_reference.
	(build_expr_type_conversion): Likewise.
	* decl.c (grok_reference_init): Likewise.
	* decl2.c (delete_sanity): Likewise.
	* except.c (initialize_handler_parm): Use POINTER_TYPE_P.
	* init.c (build_dtor_call): Do not convert_from_reference.
	* parser.c (cp_parser_template_argument): Unwrap indirected
	reference. Allow TEMPLATE_PARM_INDEX as an object parm.
	* pt.c (tsubst_copy_and_build) <case INDIRECT_REF>: Use
	convert_from_reference, if indicated.
	<case CALL_EXPR>: Do not convert_from_reference.
	<case PARM_DECL, VAR_DECL>: Convert_from_reference if needed.
	(tsubst_initializer_list): Do not convert_from_reference.
	* rtti.c (init_rtti_processing): Adjust node creation.
	(throw_bad_typeid): Use const_type_info_type_node.
	Do not convert_from_reference.
	(typeid_ok_p): Use const_type_info_type_node.
	(build_typeid, get_typeid): Always return type_info typed node.
	(build_dynamic_cast_1): Dont convert_from_reference. Refactor.
	* semantics.c (finish_stmt_expr_expr): Do not
	convert_from_reference.
	(finish_id_expression): Convert_from_reference as appropriate.
	* typeck.c (decay_conversion): Do not convert_from_reference.
	(finish_class_member_access_expr): Likewise.
	(build_indirect_ref): Use POINTER_TYPE_P.
	(convert_arguments): Do not convert_from_reference.
	(build_modify_expr): Likewise.
	(convert_for_initialization): Likewise.
	* typeck2.c (build_x_arrow): Likewise.
Comment 5 Wolfgang Bangerth 2005-09-12 01:18:42 UTC
Folks,   
I find that this bug is now present on the 3.4.x branch. I don't know   
for how long, but believe that it broke somewhere between 5 and 15 days   
ago. It would be good if we could fix this before 3.4.5 finally comes  
out. Note that both 4.0.x and mainline seem to be unaffected, so it may 
be one of the patches that were backported that caused this... 
  
W.  
Comment 6 Nathan Sidwell 2005-09-15 11:36:52 UTC
I haven't backported anything recently.
Comment 7 Volker Reichelt 2005-09-16 20:34:38 UTC
The backport of the fix for PR 18445 caused this.
I'll try to backport the fix for PR18803, too.
If that fails, reverting the patch for PR 18445 seems like the right thing
to me, because this was only an ice-on-invalid-code.
Comment 8 Nathan Sidwell 2005-09-16 20:57:26 UTC
IMHO reverting 18445 would be the most prudent thing to do.  The combination of
18845+18803 are touching too many things for my liking.
Comment 9 Volker Reichelt 2005-09-16 21:04:28 UTC
On 16 Sep, nathan at gcc dot gnu dot org wrote:
> IMHO reverting 18445 would be the most prudent thing to do.  The combination
> of 18845+18803 are touching too many things for my liking.

Gaby, would that be OK with you?

I'd revert the patch for PR 18445 on the 3.4 branch, add the testcase
for PR18803 to the 3.4 branch (bootstrapped and regtested, of course),
and close PR 18445 as fixed in 4.0.0 and WONTFIX in 3.4.
Comment 10 Gabriel Dos Reis 2005-09-16 22:40:53 UTC
Subject: Re:  [3.4 regression] rejects access to operator() in template

"reichelt at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| On 16 Sep, nathan at gcc dot gnu dot org wrote:
| > IMHO reverting 18445 would be the most prudent thing to do.  The combination
| > of 18845+18803 are touching too many things for my liking.
| 
| Gaby, would that be OK with you?

Yes -- fixes for ice-on-invalid are nice to have but they are not
critical, especially if their fixing introduces more potential for
regression. 

| I'd revert the patch for PR 18445 on the 3.4 branch, add the testcase
| for PR18803 to the 3.4 branch (bootstrapped and regtested, of course),
| and close PR 18445 as fixed in 4.0.0 and WONTFIX in 3.4.

Thanks!

-- Gaby
Comment 11 GCC Commits 2005-09-17 20:49:00 UTC
Subject: Bug 18803

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	reichelt@gcc.gnu.org	2005-09-17 20:48:46

Modified files:
	gcc/cp         : ChangeLog class.c pt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: operator5.C 
Removed files:
	gcc/testsuite/g++.dg/template: crash28.C 

Log message:
	PR c++/18803
	Revert:
	
	2005-09-02  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
	PR c++/18445
	* class.c (instantiate_type): Treat NON_DEPENDENT_EXPRs with
	unknown_type as non matching.
	* pt.c (build_non_dependent_expr): Do not build a
	NON_DEPENDENT_EXPR for a VAR_DECL.
	
	PR c++/18803
	g++.dg/template/operator5.C: New test.
	
	PR c++/18445
	g++.dg/template/crash28.C: Remove.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.240&r2=1.3892.2.241
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.595.4.12&r2=1.595.4.13
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.816.2.60&r2=1.816.2.61
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.434&r2=1.3389.2.435
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/operator5.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.46.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/crash28.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.1.46.1&r2=NONE

Comment 12 Volker Reichelt 2005-09-17 20:53:17 UTC
Reverted patch for PR 18445, which broke this.
Fixed on the 3.4 branch, thusly.
Comment 13 Paul Thomas 2006-04-16 03:45:35 UTC
Subject: Bug 18803

Author: pault
Date: Sun Apr 16 03:45:24 2006
New Revision: 112981

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=112981
Log:
2006-04-16  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/26822
	* intrinsic.c (add_functions): Mark LOGICAL as elemental.

	PR fortran/26787
	* expr.c (gfc_check_assign): Extend scope of error to include
	assignments to a procedure in the main program or, from a
	module or internal procedure that is not that represented by
	the lhs symbol. Use VARIABLE rather than l-value in message.

	PR fortran/27096
	* trans-array.c (gfc_trans_deferred_array): If the backend_decl
	is not a descriptor, dereference and then test and use the type.

	PR fortran/25597
	* trans-decl.c (gfc_trans_deferred_vars): Check if an array
	result, is also automatic character length.  If so, process
	the character length.

	PR fortran/18803
	PR fortran/25669
	PR fortran/26834
	* trans_intrinsic.c (gfc_walk_intrinsic_bound): Set
	data.info.dimen for bound intrinsics.
	* trans_array.c (gfc_conv_ss_startstride): Pick out LBOUND and
	UBOUND intrinsics and supply their shape information to the ss
	and the loop.

	PR fortran/27124
	* trans_expr.c (gfc_trans_function_call):  Add a new block, post,
	in to which all the argument post blocks are put.  Add this block
	to se->pre after a byref call or to se->post, otherwise.

2006-04-16  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/26787
	* gfortran.dg/proc_assign_1.f90: New test.
	* gfortran.dg/procedure_lvalue.f90: Change message.
	* gfortran.dg/namelist_4.f90: Add new error.

	PR fortran/27096
	* gfortran.dg/auto_pointer_array_result_1.f90

	PR fortran/27089
	* gfortran.dg/specification_type_resolution_1.f90

	PR fortran/18803
	PR fortran/25669
	PR fortran/26834
	* gfortran.dg/bounds_temporaries_1.f90: New test.

	PR fortran/27124
	* gfortran.dg/array_return_value_1.f90: New test.



Added:
    trunk/gcc/testsuite/gfortran.dg/array_return_value_1.f90
    trunk/gcc/testsuite/gfortran.dg/auto_char_pointer_array_result_1.f90
    trunk/gcc/testsuite/gfortran.dg/auto_pointer_array_result_1.f90
    trunk/gcc/testsuite/gfortran.dg/bounds_temporaries_1.f90
    trunk/gcc/testsuite/gfortran.dg/proc_assign_1.f90
    trunk/gcc/testsuite/gfortran.dg/specification_type_resolution_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/namelist_4.f90
    trunk/gcc/testsuite/gfortran.dg/procedure_lvalue.f90

Comment 14 Paul Thomas 2006-04-23 05:33:26 UTC
Subject: Bug 18803

Author: pault
Date: Sun Apr 23 05:33:16 2006
New Revision: 113191

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113191
Log:
2006-04-23  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/27122
	* resolve.c (resolve_function): Remove general restriction on auto
	character length function interfaces.
	(gfc_resolve_uops): Check restrictions on defined operator
	procedures.
	(resolve_types): Call the check for defined operators.

	PR fortran/27113
	* trans-array.c (get_array_ctor_var_strlen): Remove typo in enum.
	Part of the fix in 4.2, which does not work in 4.1 because the
	divergence is now too great.

	PR fortran/26822
	* intrinsic.c (add_functions): Mark LOGICAL as elemental.

	PR fortran/26787
	* expr.c (gfc_check_assign): Extend scope of error to include
	assignments to a procedure in the main program or, from a
	module or internal procedure that is not that represented by
	the lhs symbol. Use VARIABLE rather than l-value in message.

	PR fortran/25597
	* trans-decl.c (gfc_trans_deferred_vars): Check if an array
	result, is also automatic character length.  If so, process
	the character length. Note that this fixes the bug in 4.2
	but not here in 4.1 because the trees have diverged too much.
	Manifestly correct, so applied anyway.

	PR fortran/18803
	PR fortran/25669
	PR fortran/26834
	* trans_intrinsic.c (gfc_walk_intrinsic_bound): Set
	data.info.dimen for bound intrinsics.
	* trans_array.c (gfc_conv_ss_startstride): Pick out LBOUND and
	UBOUND intrinsics and supply their shape information to the ss
	and the loop.

	PR fortran/27124
	* trans_expr.c (gfc_trans_function_call):  Add a new block, post,
	in to which all the argument post blocks are put.  Add this block
	to se->pre after a byref call or to se->post, otherwise.

2006-04-23  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/27122
	* gfortran.dg/defined_operators_1.f90: New test.
	* gfortran.dg/assumed_charlen_function_1.f90: Add new error and
	remove old ones associated, incorrectly, with Note 5.46.

	PR fortran/26787
	* gfortran.dg/proc_assign_1.f90: New test.
	* gfortran.dg/procedure_lvalue.f90: Change message.
	* gfortran.dg/namelist_4.f90: Add new error.

	PR fortran/27089
	* gfortran.dg/specification_type_resolution_1.f90

	PR fortran/18803
	PR fortran/25669
	PR fortran/26834
	* gfortran.dg/bounds_temporaries_1.f90: New test.

	PR fortran/27124
	* gfortran.dg/array_return_value_1.f90: New test.



Added:
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/array_return_value_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/bounds_temporaries_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/defined_operators_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/proc_assign_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/specification_type_resolution_1.f90
Modified:
    branches/gcc-4_1-branch/gcc/fortran/ChangeLog
    branches/gcc-4_1-branch/gcc/fortran/expr.c
    branches/gcc-4_1-branch/gcc/fortran/intrinsic.c
    branches/gcc-4_1-branch/gcc/fortran/resolve.c
    branches/gcc-4_1-branch/gcc/fortran/trans-array.c
    branches/gcc-4_1-branch/gcc/fortran/trans-decl.c
    branches/gcc-4_1-branch/gcc/fortran/trans-expr.c
    branches/gcc-4_1-branch/gcc/fortran/trans-intrinsic.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/assumed_charlen_function_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/namelist_4.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/procedure_lvalue.f90