Bug 53055 - ICE in cp_build_indirect_ref, at cp/typeck.c:2836
Summary: ICE in cp_build_indirect_ref, at cp/typeck.c:2836
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2012-04-20 13:57 UTC by Matthias Klose
Modified: 2012-10-12 14:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.6.3, 4.7.0, 4.8.0
Last reconfirmed: 2012-04-20 00:00:00


Attachments
preprocessed source (111.36 KB, application/x-gzip)
2012-04-20 13:57 UTC, Matthias Klose
Details
unincluded testcase (38.76 KB, application/octet-stream)
2012-04-20 14:08 UTC, Richard Biener
Details
patch 1 (1.19 KB, patch)
2012-05-12 23:33 UTC, Marc Glisse
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Klose 2012-04-20 13:57:45 UTC
Created attachment 27203 [details]
preprocessed source

seen with 4.6 and 4.7 branches, and trunk on i686-linux-gnu

$ gcc -c -g part-combine-iterator.ii 
part-combine-iterator.cc: In member function 'virtual void Part_combine_iterator::derived_mark() const':
part-combine-iterator.cc:173:40: internal compiler error: in cp_build_indirect_ref, at cp/typeck.c:2836
Please submit a full bug report,
with preprocessed source if appropriate.
Comment 1 Richard Biener 2012-04-20 14:08:31 UTC
Created attachment 27204 [details]
unincluded testcase

4.4 rejects it:

part-combine-iterator.cc: In member function 'virtual void Part_combine_iterator::derived_mark() const':
part-combine-iterator.cc:173: error: invalid use of '' on pointer to member

4.5 also ICEs the same way.
Comment 2 Marc Glisse 2012-04-20 14:44:29 UTC
A brutal application of delta gives this short but non-sensical code:

void f () ;
struct A A :: * p ;
int i = p ->* f ;
Comment 3 Launchpad 2012-04-20 14:44:50 UTC
David Kastrup added the following comment to Launchpad bug report 984577:

Just for the record: the source code triggering the error is invalid C++.  It is just that an internal compiler error is a somewhat intimidating diagnostic.

-- 
http://launchpad.net/bugs/984577
Comment 4 Marc Glisse 2012-05-12 23:33:16 UTC
Created attachment 27390 [details]
patch 1

ice.cc:2:15: error: pointer to member must be on the right side of '->*'
 int i = p ->* p ;
               ^

so the caret is on the wrong side of the operator.
Comment 5 Paolo Carlini 2012-10-11 17:22:00 UTC
If the patch otherwise works fine, I would encourage you to submit it anyway even if the caret isn't accurate: AFAICS, for all the errors emitted by that function the caret is at the end of the expression and fixing that may be conceptually simple but I don't think boils down to 10 or 20 lines, it seems a separate issue really.
Comment 6 Manuel López-Ibáñez 2012-10-11 17:55:50 UTC
Sorry, I think your message is not easily understandable. I think you are trying to say that "the right hand side must be a pointer-to-member", but this is not actually what your proposed message says.

I like more clang's message:

/tmp/webcompile/_28618_0.cc:4:11: error: right hand operand to ->* has non pointer-to-member type 'void ()'
int i = p ->* f ;
          ^   ~

I am not saying that you need to print the type or fix the location (it would be nice but I understand it is quite extra work, and could be done later). But the text could say: "type of right-side operand of %<->*%> is not pointer-to-member", or "right-side operand of %<->*%> has non pointer-to-member type" or "right-side operand of %<->*%> must have pointer-to-member type".
Comment 7 Paolo Carlini 2012-10-11 18:08:23 UTC
As long as we avoid the ICE and the message is fine I'm happy. Then I'll take care of the column number asap.
Comment 8 Marc Glisse 2012-10-11 18:16:58 UTC
Note: this is very old, I barely remember it.

(In reply to comment #6)
> Sorry, I think your message is not easily understandable. I think you are
> trying to say that "the right hand side must be a pointer-to-member",

No, I think I am saying: hello, this is the left hand side of a ->* operator, and you are feeding me a pointer to member, which obviously should be on the right hand side.

> I like more clang's message:
> 
> /tmp/webcompile/_28618_0.cc:4:11: error: right hand operand to ->* has non
> pointer-to-member type 'void ()'
> int i = p ->* f ;
>           ^   ~

The testcase in the patch has p ->* p, and clang says:

test.cc:2:11: error: left hand operand to ->* must be a pointer to class
      compatible with the right hand operand, but is 'struct  A::*'
int i = p ->* p ; // { dg-error "" }
          ^~~
          .*

(not sure what that .* is doing there)

> I am not saying that you need to print the type or fix the location (it would
> be nice but I understand it is quite extra work, and could be done later). But
> the text could say: "type of right-side operand of %<->*%> is not
> pointer-to-member", or "right-side operand of %<->*%> has non pointer-to-member
> type" or "right-side operand of %<->*%> must have pointer-to-member type".

IIRC (and I could be wrong), this test is really about the lhs. Which doesn't mean that the error message is good...
Comment 9 Manuel López-Ibáñez 2012-10-11 18:27:00 UTC
(In reply to comment #8)
> Note: this is very old, I barely remember it.
> 
> (In reply to comment #6)
> > Sorry, I think your message is not easily understandable. I think you are
> > trying to say that "the right hand side must be a pointer-to-member",
> 
> No, I think I am saying: hello, this is the left hand side of a ->* operator,
> and you are feeding me a pointer to member, which obviously should be on the
> right hand side.

Ah! I was looking at the testcase here and I got confused.

> test.cc:2:11: error: left hand operand to ->* must be a pointer to class
>       compatible with the right hand operand, but is 'struct  A::*'
> int i = p ->* p ; // { dg-error "" }
>           ^~~
>           .*
> 
> (not sure what that .* is doing there)

Me neither, but clang's text is clearer in my humble opinion. I will be happy with the text changed to "left-side operand of %<->*%> must a pointer to class compatible with the right-side operand", and everything the same as your current patch. Please submit that!
Comment 10 Marc Glisse 2012-10-12 14:14:46 UTC
Author: glisse
Date: Fri Oct 12 14:14:37 2012
New Revision: 192401

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192401
Log:
2012-10-12  Marc Glisse  <marc.glisse@inria.fr>

	PR c++/53055

gcc/c-family/
	* c-common.h (enum ref_operator) [RO_ARROW_STAR]: New.

gcc/cp/
	* call.c (build_new_op_1): Pass RO_ARROW_STAR to cp_build_indirect_ref.
	* typeck.c (cp_build_indirect_ref): Handle RO_ARROW_STAR.

gcc/testsuite/
	* g++.dg/pr53055.C: New testcase.


Added:
    trunk/gcc/testsuite/g++.dg/pr53055.C   (with props)
Modified:
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-common.h
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog

Propchange: trunk/gcc/testsuite/g++.dg/pr53055.C
            ('svn:eol-style' added)

Propchange: trunk/gcc/testsuite/g++.dg/pr53055.C
            ('svn:keywords' added)
Comment 11 Marc Glisse 2012-10-12 14:21:18 UTC
(In reply to comment #7)
> Then I'll take care of the column number asap.

Ok, your turn ;-)

(In reply to comment #9)
> I will be happy
> with the text changed to "left-side operand of %<->*%> must a pointer to class
> compatible with the right-side operand",

I went with: "left hand operand of ->* must be a pointer to class, but is a pointer to member of type ...", the bit about the RHS didn't seem relevant to this particular error. But you still have a chance to convince Paolo for the follow-up patch...
Comment 12 Paolo Carlini 2012-10-12 14:35:53 UTC
Great. This is fixed anyway.