Bug 39267

Summary: gcc function template instantiation problem
Product: [Retired] Red Hat Linux Reporter: Florin Iucha <florin>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1CC: florin
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-05-06 11:28:51 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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.