public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int'
@ 2011-11-17  9:26 mario-baumann at web dot de
  2011-11-17  9:29 ` [Bug c++/51188] " fabien at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: mario-baumann at web dot de @ 2011-11-17  9:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

             Bug #: 51188
           Summary: invalid static_cast from type 'XBase' to type 'int'
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mario-baumann@web.de


Created attachment 25844
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25844
c++ source

Hi all,

i found a strange "bug" while compiling the attached c++ file

> g++ -c x.cpp
x.cpp: In member function 'std::pair<int, int> X::getImp() const':
x.cpp:15:57: error: invalid static_cast from type 'XBase' to type 'int'

if I remove any of the superfluous statements in x.cpp it works fine!

mario.

------------------------------------------------------------------------------

> uname -a
Linux ahsoka.intec.dom 2.6.32-131.17.1.el6.x86_64 #1 SMP Thu Sep 29 10:24:25
EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

> rpm -qa "glibc*" | grep -e 'glibc-[0-9]' | sort -u
glibc-2.12-1.25.el6_1.3.i686
glibc-2.12-1.25.el6_1.3.x86_64

> g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/app2/gcc/4.7.0-20111117-svn181436/x86_64/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/app2/gcc/4.7.0-20111117-svn181436/x86_64
--enable-languages=c,c++,fortran --disable-nls
--with-gmp=/app2/gcc/4.7.0-20111117-svn181436/x86_64/aux
--with-mpfr=/app2/gcc/4.7.0-20111117-svn181436/x86_64/aux
--with-mpc=/app2/gcc/4.7.0-20111117-svn181436/x86_64/aux
--with-ppl=/app2/gcc/4.7.0-20111117-svn181436/x86_64/aux
--with-cloog=/app2/gcc/4.7.0-20111117-svn181436/x86_64/aux
Thread model: posix
gcc version 4.7.0 20111117 (experimental) (GCC) 

> ld -v
GNU ld (GNU Binutils) 2.22.51.20111117


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
@ 2011-11-17  9:29 ` fabien at gcc dot gnu.org
  2011-11-17 10:20 ` fabien at gcc dot gnu.org
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-11-17  9:29 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

--- Comment #1 from fabien at gcc dot gnu.org 2011-11-17 09:25:55 UTC ---
Yet another bug caused by my recent changes with using declarations.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
  2011-11-17  9:29 ` [Bug c++/51188] " fabien at gcc dot gnu.org
@ 2011-11-17 10:20 ` fabien at gcc dot gnu.org
  2011-11-17 10:43 ` fabien at gcc dot gnu.org
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-11-17 10:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

fabien at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011-11-17
                 CC|                            |jason at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #2 from fabien at gcc dot gnu.org 2011-11-17 09:52:40 UTC ---
(In reply to comment #0)
[...]
> if I remove any of the superfluous statements in x.cpp it works fine!

There is a strange thing here, if we reach 7 members in a class, things are
done differently in the compiler.

Jason, I'd like to run the testsuite without this 7 member rule, how could I do
that ?

Thanks.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
  2011-11-17  9:29 ` [Bug c++/51188] " fabien at gcc dot gnu.org
  2011-11-17 10:20 ` fabien at gcc dot gnu.org
@ 2011-11-17 10:43 ` fabien at gcc dot gnu.org
  2011-11-17 15:22 ` jason at gcc dot gnu.org
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-11-17 10:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

--- Comment #3 from fabien at gcc dot gnu.org 2011-11-17 10:21:30 UTC ---
(In reply to comment #2)
> (In reply to comment #0)
[...]
> Jason, I'd like to run the testsuite without this 7 member rule, how could I do
> that ?

To clarify, I mean 0 instead of 7.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
                   ` (2 preceding siblings ...)
  2011-11-17 10:43 ` fabien at gcc dot gnu.org
@ 2011-11-17 15:22 ` jason at gcc dot gnu.org
  2011-11-17 20:04 ` jason at gcc dot gnu.org
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2011-11-17 15:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2011-11-17 15:17:35 UTC ---
(In reply to comment #2)
> There is a strange thing here, if we reach 7 members in a class, things are
> done differently in the compiler.
> 
> Jason, I'd like to run the testsuite without this 7 member rule, how could I do
> that ?

Look for "if (n_fields > 7)" in finish_struct_1.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
                   ` (3 preceding siblings ...)
  2011-11-17 15:22 ` jason at gcc dot gnu.org
@ 2011-11-17 20:04 ` jason at gcc dot gnu.org
  2011-11-17 20:58 ` fabien at gcc dot gnu.org
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2011-11-17 20:04 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2011-11-17 19:32:13 UTC ---
It looks like the sorted fields code in lookup_field_1 needs to handle
using_decl like the unsorted fields code does.  I think this will also fix
PR51141 (instead of the patch you already posted).


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
                   ` (4 preceding siblings ...)
  2011-11-17 20:04 ` jason at gcc dot gnu.org
@ 2011-11-17 20:58 ` fabien at gcc dot gnu.org
  2011-11-17 21:00 ` fabien at gcc dot gnu.org
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-11-17 20:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

--- Comment #6 from fabien at gcc dot gnu.org 2011-11-17 20:24:56 UTC ---
(In reply to comment #5)
> It looks like the sorted fields code in lookup_field_1 needs to handle
> using_decl like the unsorted fields code does.  I think this will also fix
> PR51141 (instead of the patch you already posted).

Thanks, I'm current testing the below patch:

Index: class.c
===================================================================
--- class.c    (revision 181436)
+++ class.c    (working copy)
@@ -6000,7 +6000,7 @@ finish_struct_1 (tree t)
      hierarchy), and we want this failure to occur quickly.  */

   n_fields = count_fields (TYPE_FIELDS (t));
-  if (n_fields > 7)
+  if (n_fields > 0)
     {
       struct sorted_fields_type *field_vec = sorted_fields_type_new
(n_fields);
       add_fields_to_record_type (TYPE_FIELDS (t), field_vec, 0);
Index: search.c
===================================================================
--- search.c    (revision 181436)
+++ search.c    (working copy)
@@ -424,8 +424,9 @@ lookup_field_1 (tree type, tree name, bo
           if (want_type)
         {
           do
-            field = fields[i--];
+            field = strip_using_decl (fields[i--]);
           while (i >= lo && DECL_NAME (fields[i]) == name);
+
           if (TREE_CODE (field) != TYPE_DECL
               && !DECL_TYPE_TEMPLATE_P (field))
             field = NULL_TREE;
@@ -433,7 +434,7 @@ lookup_field_1 (tree type, tree name, bo
           else
         {
           do
-            field = fields[i++];
+            field = strip_using_decl (fields[i++]);
           while (i < hi && DECL_NAME (fields[i]) == name);
         }
           return field;


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
                   ` (5 preceding siblings ...)
  2011-11-17 20:58 ` fabien at gcc dot gnu.org
@ 2011-11-17 21:00 ` fabien at gcc dot gnu.org
  2011-11-17 21:02 ` fabien at gcc dot gnu.org
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-11-17 21:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

--- Comment #7 from fabien at gcc dot gnu.org 2011-11-17 20:57:16 UTC ---
FYI, it fixes the following PRs: c++/51190, c++/51189, c++/51188, c++/51152,
c++/51141.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
                   ` (6 preceding siblings ...)
  2011-11-17 21:00 ` fabien at gcc dot gnu.org
@ 2011-11-17 21:02 ` fabien at gcc dot gnu.org
  2011-11-17 21:04 ` fabien at gcc dot gnu.org
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-11-17 21:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

fabien at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |reichelt at gcc dot gnu.org

--- Comment #8 from fabien at gcc dot gnu.org 2011-11-17 20:58:46 UTC ---
*** Bug 51190 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
                   ` (7 preceding siblings ...)
  2011-11-17 21:02 ` fabien at gcc dot gnu.org
@ 2011-11-17 21:04 ` fabien at gcc dot gnu.org
  2011-11-17 21:06 ` fabien at gcc dot gnu.org
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-11-17 21:04 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

--- Comment #9 from fabien at gcc dot gnu.org 2011-11-17 20:59:37 UTC ---
*** Bug 51189 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
                   ` (8 preceding siblings ...)
  2011-11-17 21:04 ` fabien at gcc dot gnu.org
@ 2011-11-17 21:06 ` fabien at gcc dot gnu.org
  2011-11-17 21:07 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-11-17 21:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

fabien at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |markus at trippelsdorf dot
                   |                            |de

--- Comment #11 from fabien at gcc dot gnu.org 2011-11-17 21:01:06 UTC ---
*** Bug 51141 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
                   ` (9 preceding siblings ...)
  2011-11-17 21:06 ` fabien at gcc dot gnu.org
@ 2011-11-17 21:07 ` jason at gcc dot gnu.org
  2011-11-17 21:09 ` fabien at gcc dot gnu.org
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2011-11-17 21:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

--- Comment #12 from Jason Merrill <jason at gcc dot gnu.org> 2011-11-17 21:03:31 UTC ---
(In reply to comment #6)
>            do
> -            field = fields[i--];
> +            field = strip_using_decl (fields[i--]);
>            while (i >= lo && DECL_NAME (fields[i]) == name);

Let's wait and strip_using_decl after the loop (i.e. at the return statement),
since a USING_DECL has the same name.  We also need to check
is_overloaded_decl.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
                   ` (10 preceding siblings ...)
  2011-11-17 21:07 ` jason at gcc dot gnu.org
@ 2011-11-17 21:09 ` fabien at gcc dot gnu.org
  2011-11-17 21:59 ` fabien at gcc dot gnu.org
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-11-17 21:09 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

fabien at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cas43 at cs dot
                   |                            |stanford.edu

--- Comment #10 from fabien at gcc dot gnu.org 2011-11-17 21:00:17 UTC ---
*** Bug 51152 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
                   ` (11 preceding siblings ...)
  2011-11-17 21:09 ` fabien at gcc dot gnu.org
@ 2011-11-17 21:59 ` fabien at gcc dot gnu.org
  2011-11-18 21:03 ` fabien at gcc dot gnu.org
  2011-11-18 21:12 ` fabien at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-11-17 21:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

--- Comment #13 from fabien at gcc dot gnu.org 2011-11-17 21:53:15 UTC ---
(In reply to comment #12)
> Let's wait and strip_using_decl after the loop (i.e. at the return statement),
> since a USING_DECL has the same name.  We also need to check
> is_overloaded_decl.

Like that ?

Index: search.c
===================================================================
--- search.c    (revision 181386)
+++ search.c    (working copy)
@@ -436,6 +436,14 @@ lookup_field_1 (tree type, tree name, bo
             field = fields[i++];
           while (i < hi && DECL_NAME (fields[i]) == name);
         }
+
+          if (field)
+        {
+          field = strip_using_decl (field);
+          if (is_overloaded_fn (field))
+            field = NULL_TREE;
+        }
+
           return field;
         }
     }


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
                   ` (12 preceding siblings ...)
  2011-11-17 21:59 ` fabien at gcc dot gnu.org
@ 2011-11-18 21:03 ` fabien at gcc dot gnu.org
  2011-11-18 21:12 ` fabien at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-11-18 21:03 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

--- Comment #14 from fabien at gcc dot gnu.org 2011-11-18 20:32:08 UTC ---
Author: fabien
Date: Fri Nov 18 20:32:04 2011
New Revision: 181492

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181492
Log:
gcc/testsuite/ChangeLog

2011-11-18  Fabien Chene  <fabien@gcc.gnu.org>

    PR c++/51188
    * g++.dg/lookup/using46.C: New.
    * g++.dg/lookup/using47.C: New.
    * g++.dg/lookup/using48.C: New.
    * g++.dg/lookup/using49.C: New.
    * g++.dg/lookup/using50.C: New.

gcc/cp/ChangeLog

2011-11-18  Fabien Chene  <fabien@gcc.gnu.org>

    PR c++/51188
    * search.c (lookup_field_1): Handle USING_DECLs for the storted
    case.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c++/51188] invalid static_cast from type 'XBase' to type 'int'
  2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
                   ` (13 preceding siblings ...)
  2011-11-18 21:03 ` fabien at gcc dot gnu.org
@ 2011-11-18 21:12 ` fabien at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-11-18 21:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51188

fabien at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #15 from fabien at gcc dot gnu.org 2011-11-18 20:36:54 UTC ---
Fixed by rev 181490, not 181492.


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2011-11-18 20:37 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-17  9:26 [Bug c++/51188] New: invalid static_cast from type 'XBase' to type 'int' mario-baumann at web dot de
2011-11-17  9:29 ` [Bug c++/51188] " fabien at gcc dot gnu.org
2011-11-17 10:20 ` fabien at gcc dot gnu.org
2011-11-17 10:43 ` fabien at gcc dot gnu.org
2011-11-17 15:22 ` jason at gcc dot gnu.org
2011-11-17 20:04 ` jason at gcc dot gnu.org
2011-11-17 20:58 ` fabien at gcc dot gnu.org
2011-11-17 21:00 ` fabien at gcc dot gnu.org
2011-11-17 21:02 ` fabien at gcc dot gnu.org
2011-11-17 21:04 ` fabien at gcc dot gnu.org
2011-11-17 21:06 ` fabien at gcc dot gnu.org
2011-11-17 21:07 ` jason at gcc dot gnu.org
2011-11-17 21:09 ` fabien at gcc dot gnu.org
2011-11-17 21:59 ` fabien at gcc dot gnu.org
2011-11-18 21:03 ` fabien at gcc dot gnu.org
2011-11-18 21:12 ` fabien at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).