[Bug c++/19288] No more possible to have a template function that uses a nested class of a template class

giovannibajo at libero dot it gcc-bugzilla@gcc.gnu.org
Thu Jan 6 10:13:00 GMT 2005


------- Additional Comments From giovannibajo at libero dot it  2005-01-06 10:13 -------
This is invalid. Within the expression "C1<T>::nested", T cannot be deduced 
because it is in an nondeduced context. 

ISO/ANSI C++ standard reference: [temp.deduct.type]/4:

The nondeduced contexts are:

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

  --  A type that is a template-id in which one or more of the template-
      arguments is an expression that references a template-parameter.

  When  a  type  name  is  specified in a way that includes a nondeduced
  context, all of the types  that  comprise  that  type  name  are  also
  nondeduced.   However,  a  compound  type can include both deduced and
  nondeduced types.  [Example: If a type is  specified  as  A<T>::B<T2>,
  both  T  and  T2  are nondeduced.  Likewise, if a type is specified as
  A<I+J>::X<T>, I, J, and T are nondeduced.  If a type is  specified  as
  void f(typename A<T>::B, A<T>), the T in A<T>::B is nondeduced but the
  T in A<T> is deduced.


Also notice the end of paragraph 3: "If a template parameter is used only in 
nondeduced contexts and is not explicitly specified, template argument 
deduction fails."


Using a specialization as a workaround is a bit bloating. The correct way is to 
explicitly specify the template arguments which cannot be deduced when calling 
the template. In your case, you can use f2<float>(n).

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19288



More information about the Gcc-bugs mailing list