Bug 55058 - [4.7/4.8 Regression] Unexpected invalid type conversion error
Summary: [4.7/4.8 Regression] Unexpected invalid type conversion error
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.3
: P2 normal
Target Milestone: 4.7.3
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
: 55097 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-10-24 15:38 UTC by Sebastian Huber
Modified: 2012-12-07 05:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.6.4
Known to fail: 4.7.3, 4.8.0
Last reconfirmed: 2012-10-24 00:00:00


Attachments
Sample code (56.86 KB, text/x-c++src)
2012-10-24 15:38 UTC, Sebastian Huber
Details
Reduced smaple code. (534 bytes, text/plain)
2012-10-25 11:43 UTC, Sebastian Huber
Details
Test case. (136 bytes, text/x-c++src)
2012-10-26 13:28 UTC, Sebastian Huber
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Huber 2012-10-24 15:38:52 UTC
Created attachment 28518 [details]
Sample code

The attached test file produces with "g++ -c test.cc" of GCC version 4.7 (e.g. the one shipped with OpenSuse 12.2) and 4.8 the following output:

test.cc: In constructor 'C_DrvDataBuffer::C_DrvDataBuffer(ushort, ushort)':
test.cc:20748:34: error: invalid conversion from 'const T_SND_NODE C_DrvSndDataBlock::* {aka const list_node<C_DrvSndDataBlock, with_lock, oper_safe> C_DrvSndDataBlock::*}' to 'list_node<C_DrvSndDataBlock, with_lock, oper_safe> C_DrvSndDataBlock::*' [-fpermissive]
test.cc:16667:1: error:   initializing argument 1 of 'list_base< <template-parameter-1-1>, <template-parameter-1-2>, test_, amp_>::list_base(const T_C_NODE_ T_::*, const char*, bool) [with T_ = C_DrvSndDataBlock; lock_ = with_lock; test_ = oper_safe; bool amp_ = false; list_base< <template-parameter-1-1>, <template-parameter-1-2>, test_, amp_>::T_C_NODE_ = list_node<C_DrvSndDataBlock, with_lock, oper_safe>]' [-fpermissive]
test.cc:20748:34: error: invalid conversion from 'const T_SND_NODE C_DrvSndDataBlock::* {aka const list_node<C_DrvSndDataBlock, with_lock, oper_safe> C_DrvSndDataBlock::*}' to 'list_node<C_DrvSndDataBlock, with_lock, oper_safe> C_DrvSndDataBlock::*' [-fpermissive]
test.cc:16667:1: error:   initializing argument 1 of 'list_base< <template-parameter-1-1>, <template-parameter-1-2>, test_, amp_>::list_base(const T_C_NODE_ T_::*, const char*, bool) [with T_ = C_DrvSndDataBlock; lock_ = with_lock; test_ = oper_safe; bool amp_ = false; list_base< <template-parameter-1-1>, <template-parameter-1-2>, test_, amp_>::T_C_NODE_ = list_node<C_DrvSndDataBlock, with_lock, oper_safe>]' [-fpermissive]
test.cc:20748:34: error: invalid conversion from 'const T_RCV_NODE C_DrvRcvDataBlock::* {aka const list_node<C_DrvRcvDataBlock, with_lock, oper_safe> C_DrvRcvDataBlock::*}' to 'list_node<C_DrvRcvDataBlock, with_lock, oper_safe> C_DrvRcvDataBlock::*' [-fpermissive]
test.cc:16667:1: error:   initializing argument 1 of 'list_base< <template-parameter-1-1>, <template-parameter-1-2>, test_, amp_>::list_base(const T_C_NODE_ T_::*, const char*, bool) [with T_ = C_DrvRcvDataBlock; lock_ = with_lock; test_ = oper_safe; bool amp_ = false; list_base< <template-parameter-1-1>, <template-parameter-1-2>, test_, amp_>::T_C_NODE_ = list_node<C_DrvRcvDataBlock, with_lock, oper_safe>]' [-fpermissive]

The test code can be compiled with the Comeau-Online-Compiler:

http://www.comeaucomputing.com/tryitout

The GCC 4.6 works also.
Comment 1 Jonathan Wakely 2012-10-24 16:06:13 UTC
can you reduce it to get rid of all the code that doesn't affect the failure?
Comment 2 Sebastian Huber 2012-10-24 16:12:39 UTC
(In reply to comment #1)
> can you reduce it to get rid of all the code that doesn't affect the failure?

I already reduced it quite a lot, but I try harder tomorrow.
Comment 3 Sebastian Huber 2012-10-25 11:43:09 UTC
Created attachment 28527 [details]
Reduced smaple code.

This is the offending code reduced to the minimum.  The error is no longer present, that means the surrounding code has an effect.
Comment 4 Jonathan Wakely 2012-10-25 12:03:56 UTC
(In reply to comment #3)
> The error is no longer
> present, 

Then the attachment isn't very useful. It needs to be reduced to the minimum that still shows the bug, otherwise it's just some code.

http://gcc.gnu.org/bugs/minimize.html
Comment 5 Sebastian Huber 2012-10-26 13:28:08 UTC
Created attachment 28537 [details]
Test case.

Thanks for the hint to the delta tool.  This is great for automatic test case reduction.

The test code is now:

template <typename T>
struct A { };

template <typename T>
struct B {
  B(const A<T> T::* p);
  typedef A<T> D;
};

template <typename T>
B<T>::B(const D T::* p) { }

struct C {
  C() : e() {};

  const A<C> e;
};

B<C> g(&C::e);

The crucial thing is the "typedef A<T> D".  It works, if we move it before the constructor declaration "B(const A<T> T::* p)".  Removing the constructor definition works also.
Comment 6 Sebastian Huber 2012-10-30 09:18:03 UTC
If I revert parts of commit 44f861fca343148a1b0720105ec2b7f14bbcc849

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 1ff1c73..8f5b9f7 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -11015,9 +11015,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
             complain | tf_ignore_bad_quals);
          return r;
        }
-      else
-       /* We don't have an instantiation yet, so drop the typedef.  */
-       t = DECL_ORIGINAL_TYPE (decl);
+      /* Else we must be instantiating the typedef, so fall through.  */
     }
 
   if (type

mentioned in

http://gcc.gnu.org/ml/gcc/2012-10/msg00399.html

then, the test case compiles well.
Comment 7 Paolo Carlini 2012-11-07 15:12:52 UTC
*** Bug 55097 has been marked as a duplicate of this bug. ***
Comment 8 Jason Merrill 2012-12-07 04:54:12 UTC
Author: jason
Date: Fri Dec  7 04:53:59 2012
New Revision: 194282

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194282
Log:
	PR c++/55058
	* pt.c (tsubst): Keep the quals when looking through a typedef.

Added:
    trunk/gcc/testsuite/g++.dg/template/typedef40.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
Comment 9 Jason Merrill 2012-12-07 05:13:30 UTC
Author: jason
Date: Fri Dec  7 05:13:22 2012
New Revision: 194289

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194289
Log:
	PR c++/55058
	* pt.c (tsubst): Keep the quals when looking through a typedef.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/template/typedef40.C
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/pt.c
Comment 10 Jason Merrill 2012-12-07 05:15:08 UTC
Fixed.