public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57520] New: alias template substitution/deduction failure
@ 2013-06-03 21:55 stephen.pope at predict dot com
  2013-10-24 14:31 ` [Bug c++/57520] " pei.chunsheng at outlook dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: stephen.pope at predict dot com @ 2013-06-03 21:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57520
           Summary: alias template substitution/deduction failure
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stephen.pope at predict dot com

gcc 4.8.1 (as well as 4.8.0 and 4.7.2) appears to fail to correctly substitute
the alias's template-id for an alias template instantiation when reference or
by pointer types are involved.

I was able to whittle a messy real-world problem down to a minor variation on
the non-normative example provided in the C++ 11 standard section temp.alias
(14.5.7/2):

#include <vector>

using namespace std;

template <class T>
using Vec = vector<T, allocator<T>>;

template <template <class> class TT>
void f1(TT<int> v);

template <template <class> class TT>
void f2(TT<int>& v);

template <template <class> class TT>
void f3(TT<int>* v);

template <template <class, class> class TT>
void g1(TT<int, allocator<int>> v);

template <template <class, class> class TT>
void g2(TT<int, allocator<int>>& v);

template <template <class, class> class TT>
void g3(TT<int, allocator<int>>* v);

void foo()
{
   Vec<int> v;

   f1(v);    // gcc and clang both correctly yield no matching function error
   g1(v);

   f2(v);    // clang yields a no matching function error
   g2(v);    // gcc yields a no matching function error

   f3(&v);    // clang yields a no matching function error
   g3(&v);    // gcc yields a no matching function error
}

(compile with -std=c++11)

As noted above, clang 3.3 (recent pull from svn) and gcc (4.7.2, 4.8.0, and
4.8.1) agree on the handling of f1/g1 in conformance with the standard, but
differ on the handling of f2/g2 and f3/g3 (to be clear, all tested versions of
gcc incorrectly accept the call to f2() and f3() and error on the call to g2()
and g3()).

All indications, both in this example and in my real problem, are that gcc is
not correctly converting the type of the instantiation of the alias template
(e.g. Vec<int>) to the aliased type (e.g. vector<int, allocator<int>>) prior to
trying to deduce the template parameter for the instantiations of f2, f3, g2,
and g3.

Here is the full error output of gcc-4.8.1:

% gcc-4.8.1/bin/g++ -Wall -Wextra -std=c++11 temp.cpp
temp.cpp: In function 'void foo()':
temp.cpp:30:8: error: no matching function for call to 'f1(Vec<int>&)'
    f1(v);    // gcc and clang both correctly yield no matching function error
        ^
temp.cpp:30:8: note: candidate is:
temp.cpp:9:6: note: template<template<class> class TT> void f1(TT<int>)
 void f1(TT<int> v);
      ^
temp.cpp:9:6: note:   template argument deduction/substitution failed:
temp.cpp:30:8: error: wrong number of template arguments (2, should be 1)
    f1(v);    // gcc and clang both correctly yield no matching function error
        ^
temp.cpp:8:34: error: provided for 'template<class> class TT'
 template <template <class> class TT>
                                  ^
temp.cpp:34:8: error: no matching function for call to 'g2(Vec<int>&)'
    g2(v);    // gcc yields a no matching function error
        ^
temp.cpp:34:8: note: candidate is:
temp.cpp:21:6: note: template<template<class, class> class TT> void g2(TT<int,
std::allocator<int> >&)
 void g2(TT<int, allocator<int>>& v);
      ^
temp.cpp:21:6: note:   template argument deduction/substitution failed:
temp.cpp:34:8: error: wrong number of template arguments (1, should be 2)
    g2(v);    // gcc yields a no matching function error
        ^
temp.cpp:20:41: error: provided for 'template<class, class> class TT'
 template <template <class, class> class TT>
                                         ^
temp.cpp:37:9: error: no matching function for call to 'g3(Vec<int>*)'
    g3(&v);    // gcc yields a no matching function error
         ^
temp.cpp:37:9: note: candidate is:
temp.cpp:24:6: note: template<template<class, class> class TT> void g3(TT<int,
std::allocator<int> >*)
 void g3(TT<int, allocator<int>>* v);
      ^
temp.cpp:24:6: note:   template argument deduction/substitution failed:
temp.cpp:37:9: error: wrong number of template arguments (1, should be 2)
    g3(&v);    // gcc yields a no matching function error
         ^
temp.cpp:23:41: error: provided for 'template<class, class> class TT'
 template <template <class, class> class TT>
                                         ^


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/57520] alias template substitution/deduction failure
  2013-06-03 21:55 [Bug c++/57520] New: alias template substitution/deduction failure stephen.pope at predict dot com
@ 2013-10-24 14:31 ` pei.chunsheng at outlook dot com
  2013-10-24 14:41 ` pei.chunsheng at outlook dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pei.chunsheng at outlook dot com @ 2013-10-24 14:31 UTC (permalink / raw)
  To: gcc-bugs

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

Chunsheng Pei <pei.chunsheng at outlook dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pei.chunsheng at outlook dot com

--- Comment #1 from Chunsheng Pei <pei.chunsheng at outlook dot com> ---
I confirm this behavior. And I tried the following

   vector<int, allocator<int>> int_v;
   f1(int_v);
   g1(int_v);
   f2(int_v);
   g2(int_v);

GCC/clang reports it could not match f2 only this time.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/57520] alias template substitution/deduction failure
  2013-06-03 21:55 [Bug c++/57520] New: alias template substitution/deduction failure stephen.pope at predict dot com
  2013-10-24 14:31 ` [Bug c++/57520] " pei.chunsheng at outlook dot com
@ 2013-10-24 14:41 ` pei.chunsheng at outlook dot com
  2013-11-07  7:09 ` potswa at mac dot com
  2021-07-27  8:32 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pei.chunsheng at outlook dot com @ 2013-10-24 14:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Chunsheng Pei <pei.chunsheng at outlook dot com> ---
Addition to my previous comments

GCC/clang also reports it could not match f1 at this time.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/57520] alias template substitution/deduction failure
  2013-06-03 21:55 [Bug c++/57520] New: alias template substitution/deduction failure stephen.pope at predict dot com
  2013-10-24 14:31 ` [Bug c++/57520] " pei.chunsheng at outlook dot com
  2013-10-24 14:41 ` pei.chunsheng at outlook dot com
@ 2013-11-07  7:09 ` potswa at mac dot com
  2021-07-27  8:32 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: potswa at mac dot com @ 2013-11-07  7:09 UTC (permalink / raw)
  To: gcc-bugs

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

David Krauss <potswa at mac dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |potswa at mac dot com

--- Comment #3 from David Krauss <potswa at mac dot com> ---
To summarize the above, template template argument deduction finds an alias
template used to declare an object instead of the template type the alias
resolved to. This is wrong because alias template specializations are not
distinct types.

The f1/g1 examples are extraneous. f2 matches the alias (wrong) and g2 matches
the type generated by the alias (correct).

One workaround is to simply add a typedef, this fixes overload resolution of
both functions.

   typedef Vec<int> vit;
   vit v;

I still reproduce this in a 4.9 trunk build from mid October.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/57520] alias template substitution/deduction failure
  2013-06-03 21:55 [Bug c++/57520] New: alias template substitution/deduction failure stephen.pope at predict dot com
                   ` (2 preceding siblings ...)
  2013-11-07  7:09 ` potswa at mac dot com
@ 2021-07-27  8:32 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27  8:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57520

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
On the trunk with C++14 (and C++11), gcc errors out where clang used to error
out only.  With C++17 (and C++20), though GCC accepts the code.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-07-27  8:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-03 21:55 [Bug c++/57520] New: alias template substitution/deduction failure stephen.pope at predict dot com
2013-10-24 14:31 ` [Bug c++/57520] " pei.chunsheng at outlook dot com
2013-10-24 14:41 ` pei.chunsheng at outlook dot com
2013-11-07  7:09 ` potswa at mac dot com
2021-07-27  8:32 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).