public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "stephen.pope at predict dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/57520] New: alias template substitution/deduction failure
Date: Mon, 03 Jun 2013 21:55:00 -0000	[thread overview]
Message-ID: <bug-57520-4@http.gcc.gnu.org/bugzilla/> (raw)

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>
                                         ^


             reply	other threads:[~2013-06-03 21:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-03 21:55 stephen.pope at predict dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-57520-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).