Bug 39321 - G++ remove cv qualifiers from typedefs during template instantiation
Summary: G++ remove cv qualifiers from typedefs during template instantiation
Status: RESOLVED DUPLICATE of bug 37806
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-27 20:05 UTC by Dodji Seketeli
Modified: 2009-03-02 01:22 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Don't remove cv quals from typedefs during type substitution (1.38 KB, patch)
2009-02-27 20:06 UTC, Dodji Seketeli
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dodji Seketeli 2009-02-27 20:05:43 UTC
The following program should compile, but current g++ from trunk compiles it.

Please read the comments in the code:

~=~

template<typename T>
struct do_typedef
{
  typedef T type;
};


template<typename T> struct is_function;

// Let's name this template partial specialization #1
template<typename T>
struct is_function< T ()>
{ 
};

template<typename T> struct is_member_func;

template<typename T, typename C>
struct is_member_func<T C::*>
{
  //[1] okay, the following line should not compile. Here is why.  
  //After the type substitution that happens at instantiation time,
  //the value of the argument that matches the T parameter is
  //'void () () const'.
  //In that context, the result of the substitution of T in the expression
  //do_typedef<T>::type _should_ be 'void () () const' as well.
  //So will be the argument of the is_function template.
  //'void () () const' is not compatible with 'T ()', so the  
  //partial template specialization #1 should be instantiated.
  //So we should get a compilation error.
  is_function<typename do_typedef<T>::type> t;
};


struct A;

// Should not compile because of the comment [1] above.
is_member_func<void (A::*) (void) const> t;
~=~

What happens is that during the type substitution of
do_typedef<T>::type, g++ removes the const qualifier from the 'void () () const' function. And that is a bug.

I'll attach below a patch that fixes it.
Comment 1 Dodji Seketeli 2009-02-27 20:06:44 UTC
Created attachment 17372 [details]
Don't remove cv quals from typedefs during type substitution
Comment 2 Andrew Pinski 2009-02-28 08:09:17 UTC
This is related to bug 37806.
Comment 3 Jason Merrill 2009-03-02 01:22:41 UTC
Yep, duplicate.

*** This bug has been marked as a duplicate of 37806 ***