Bug 39267 - gcc function template instantiation problem
Summary: gcc function template instantiation problem
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.1
Hardware: i686
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-05-06 11:28 UTC by Florin Iucha
Modified: 2007-04-18 16:33 UTC (History)
1 user (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2001-05-06 11:28:51 UTC
Embargoed:


Attachments (Terms of Use)

Description Florin Iucha 2001-05-06 11:28:46 UTC
Description of Problem:

Try to complile this:

---cut-here---template <int SIZE>
class B
{
public:

   class P
   {
   public:
      P(int x) : x_(x) {}
      int x() const { return x_; }
      
   private:
      int x_;
   };

   P get_a_P() { return P(SIZE/2); }
   
};


class G : private B<10>
{
public:

   void test();
   
};


template <int SIZE>
B<SIZE>::P the_bug(B<SIZE>::P p)
{
   // do nothing
   return p;
}


void G::test()
{
   P p = get_a_P();

   P q = the_bug(p);
}


int main()
{
   G g;

   g.test();
   
   return 0;
}

---cut-here---

How Reproducible:
Allways.

Steps to Reproduce:
1. try to compile

Actual Results:
templbug.cpp: In method `void G::test ()':
templbug.cpp:42: no matching function for call to `the_bug (B<10>::P 
&)'

Expected Results:
program complile

Additional Information:
If I do the template instantiation by hand (by replacing SIZE with 10), the
code compiles.

Comment 1 Jakub Jelinek 2001-05-09 10:38:56 UTC
The code is ill formed. See
[templ.deduct.type]/4 and [templ.deduct.type]/14 in ISO C++.
/4 sais that:
The nondeduced contexts are:

  --The nested-name-specifier of a type that was specified using a qualified-id.

/14 sais that:
template<int i, typename T>
T deduce(typename A<T>::X x,    // T is not deduced here

E.g. changing the the_bug(p) call into the_bug<10>(p) (ie. explicitely
providing the template argument because it will not be deduced) should make this
work.


Note You need to log in before you can comment on or make changes to this bug.