Bug 51188 - invalid static_cast from type 'XBase' to type 'int'
Summary: invalid static_cast from type 'XBase' to type 'int'
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: fabien
URL:
Keywords:
: 51141 51152 51189 51190 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-11-17 09:12 UTC by Mario Baumann
Modified: 2011-11-18 20:36 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-11-17 00:00:00


Attachments
c++ source (218 bytes, text/x-c++src)
2011-11-17 09:12 UTC, Mario Baumann
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mario Baumann 2011-11-17 09:12:50 UTC
Created attachment 25844 [details]
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
Comment 1 fabien 2011-11-17 09:25:55 UTC
Yet another bug caused by my recent changes with using declarations.
Comment 2 fabien 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.
Comment 3 fabien 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.
Comment 4 Jason Merrill 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.
Comment 5 Jason Merrill 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).
Comment 6 fabien 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;
Comment 7 fabien 2011-11-17 20:57:16 UTC
FYI, it fixes the following PRs: c++/51190, c++/51189, c++/51188, c++/51152, c++/51141.
Comment 8 fabien 2011-11-17 20:58:46 UTC
*** Bug 51190 has been marked as a duplicate of this bug. ***
Comment 9 fabien 2011-11-17 20:59:37 UTC
*** Bug 51189 has been marked as a duplicate of this bug. ***
Comment 10 fabien 2011-11-17 21:00:17 UTC
*** Bug 51152 has been marked as a duplicate of this bug. ***
Comment 11 fabien 2011-11-17 21:01:06 UTC
*** Bug 51141 has been marked as a duplicate of this bug. ***
Comment 12 Jason Merrill 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.
Comment 13 fabien 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;
 	    }
 	}
Comment 14 fabien 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
Comment 15 fabien 2011-11-18 20:36:54 UTC
Fixed by rev 181490, not 181492.