public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/47765] New: Wrong template deduction
@ 2011-02-16 12:32 dk_mipt at mail dot ru
  2011-09-08  9:22 ` [Bug c++/47765] " daniel.kruegler at googlemail dot com
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: dk_mipt at mail dot ru @ 2011-02-16 12:32 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Wrong template deduction
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: dk_mipt@mail.ru


The following code fails to compile neither with g++ version 4.4.5
(Ubuntu/Linaro 4.4.4-14ubuntu5) nor with 4.5.1:


template<typename ItT>
struct traits {
        typedef typename ItT::value_type value_t;
};

template<typename ItT>
struct A {
        typedef typename traits<ItT>::value_t value_t;
};

template<typename T>
struct B {
        typedef T type_t;
};

struct C {

        template<typename T, typename T2>
        void foo(const A<T>& r) {}

        template<typename T>
        void foo(const B<T>& r) {}
};

void foo()
{
        B<char> b;
        C c;
        c.foo(b);
        c.foo<char>(b); // fails to compile
}


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

* [Bug c++/47765] Wrong template deduction
  2011-02-16 12:32 [Bug c++/47765] New: Wrong template deduction dk_mipt at mail dot ru
@ 2011-09-08  9:22 ` daniel.kruegler at googlemail dot com
  2011-09-08 10:52 ` paolo.carlini at oracle dot com
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2011-09-08  9:22 UTC (permalink / raw)
  To: gcc-bugs

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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler at
                   |                            |googlemail dot com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2011-09-08 09:20:26 UTC ---
This problem seems still to exist in gcc 4.7.0 20110903 (experimental)


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

* [Bug c++/47765] Wrong template deduction
  2011-02-16 12:32 [Bug c++/47765] New: Wrong template deduction dk_mipt at mail dot ru
  2011-09-08  9:22 ` [Bug c++/47765] " daniel.kruegler at googlemail dot com
@ 2011-09-08 10:52 ` paolo.carlini at oracle dot com
  2011-09-08 16:22 ` jason at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-08 10:52 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-08 10:51:29 UTC ---
Let's ask Jason what he thinks about this...


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

* [Bug c++/47765] Wrong template deduction
  2011-02-16 12:32 [Bug c++/47765] New: Wrong template deduction dk_mipt at mail dot ru
  2011-09-08  9:22 ` [Bug c++/47765] " daniel.kruegler at googlemail dot com
  2011-09-08 10:52 ` paolo.carlini at oracle dot com
@ 2011-09-08 16:22 ` jason at gcc dot gnu.org
  2011-09-08 17:05 ` daniel.kruegler at googlemail dot com
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2011-09-08 16:22 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011-09-08
     Ever Confirmed|0                           |1

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2011-09-08 16:15:24 UTC ---
14.8.2/6: At certain points in the template argument deduction process it is
necessary to take a function type that makes use of template parameters and
replace those template parameters with the corresponding template arguments.
This is done at the beginning of template argument deduction when any
explicitly specified template arguments are substituted into the function type,
and again at the end of template argument deduction when any template arguments
that were deduced or obtained from default arguments are substituted.

So, when we start to try to evaluate b.foo<char>, we substitute 'char' for T in
both templates, so they become

        template<typename T2>
        void foo(const A<char>& r) {}

        void foo(const B<char>& r) {}

14.8.1/6: Implicit conversions (Clause 4) will be performed on a function
argument to convert it to the type of the corresponding function parameter if
the parameter type contains no template-parameters that participate in template
argument deduction. [ Note: Template parameters do not participate in template
argument deduction if they are explicitly specified.

So we no longer do deduction on the first parameter, but rather check for a
conversion.  What is unclear in the standard is when exactly the conversion
should happen.  Currently G++ and EDG seem to check for a conversion during
argument deduction, which leads to instantiation of A<char> and thus the error
you see.  But another reasonable interpretation would be to skip the parameter
during deduction and then let normal overload resolution check for the
conversion; in that case deduction would fail for the first foo and so we never
check the conversion, so we don't try to instantiate A<char>.  clang accepts
this testcase, so it seems likely that this is what they are doing.


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

* [Bug c++/47765] Wrong template deduction
  2011-02-16 12:32 [Bug c++/47765] New: Wrong template deduction dk_mipt at mail dot ru
                   ` (2 preceding siblings ...)
  2011-09-08 16:22 ` jason at gcc dot gnu.org
@ 2011-09-08 17:05 ` daniel.kruegler at googlemail dot com
  2011-09-08 19:23 ` jason at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2011-09-08 17:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2011-09-08 16:57:48 UTC ---
(In reply to comment #3)

In fact I expected that there is some implementation freedom which allows this
(I was thinking of 14.7.1 p6), but I still wonder: I have always understood
that 14.8.2 only applies, if *all* template arguments are provided:

p1: "When a function template specialization is referenced, all of the template
arguments shall have values."

p5: "[..] When all template arguments have been deduced or obtained from
default template arguments, all uses of template parameters in the template
parameter list of the template and the function type are replaced with the
corresponding deduced or default argument values. [..]"

Doesn't this indicate that

template<typename T, typename T2>
void foo(const A<T>& r);

must be rejected immediately in this case, because T2 is nowhere specified nor
deducible?


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

* [Bug c++/47765] Wrong template deduction
  2011-02-16 12:32 [Bug c++/47765] New: Wrong template deduction dk_mipt at mail dot ru
                   ` (3 preceding siblings ...)
  2011-09-08 17:05 ` daniel.kruegler at googlemail dot com
@ 2011-09-08 19:23 ` jason at gcc dot gnu.org
  2011-09-08 19:46 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2011-09-08 19:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2011-09-08 18:50:32 UTC ---
(In reply to comment #4)
> In fact I expected that there is some implementation freedom which allows this
> (I was thinking of 14.7.1 p6), but I still wonder: I have always understood
> that 14.8.2 only applies, if *all* template arguments are provided:

"This is done at the beginning of template argument deduction when any
explicitly specified template arguments are substituted into the function type"
seems pretty clear to me that it happens at the beginning and does not require
all parameters to have explicit arguments.

> Doesn't this indicate that
> 
> template<typename T, typename T2>
> void foo(const A<T>& r);
> 
> must be rejected immediately in this case, because T2 is nowhere specified nor
> deducible?

No, it seems to me that the standard specifies that we do deduction on all
parm/arg pairs and only then fail if a template parameter is not deduced; we
don't check ahead of time to see if any parameters are nondeducible.  That
might be a reasonable change given that now some semantics depend on whether or
not a parameter is used in a deducible context, but it isn't what the standard
currently says.


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

* [Bug c++/47765] Wrong template deduction
  2011-02-16 12:32 [Bug c++/47765] New: Wrong template deduction dk_mipt at mail dot ru
                   ` (4 preceding siblings ...)
  2011-09-08 19:23 ` jason at gcc dot gnu.org
@ 2011-09-08 19:46 ` jason at gcc dot gnu.org
  2013-05-25  8:51 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2011-09-08 19:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2011-09-08 19:22:58 UTC ---
(In reply to comment #3)
> But another reasonable interpretation would be to skip the parameter
> during deduction and then let normal overload resolution check for the
> conversion; in that case deduction would fail for the first foo and so we never
> check the conversion, so we don't try to instantiate A<char>.

But that breaks several libstdc++ tests, and this testcase:

template<typename ItT>
struct A {
        typedef typename ItT::value_t value_t;
};

template<typename T>
struct B {
        typedef T type_t;
};

template <class T, class... U>
typename A<T>::value_t f(int, T, U...);

template <class T>
T f(T, T);

void foo()
{
        B<char> b;
        f(b, b);
}

because then we do the substitution before checking whether B<char> can convert
to int.  I suppose that we could check conversion between deduction and
substitution...I think I'm going to raise this with the committee.


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

* [Bug c++/47765] Wrong template deduction
  2011-02-16 12:32 [Bug c++/47765] New: Wrong template deduction dk_mipt at mail dot ru
                   ` (5 preceding siblings ...)
  2011-09-08 19:46 ` jason at gcc dot gnu.org
@ 2013-05-25  8:51 ` paolo.carlini at oracle dot com
  2013-05-25  9:19 ` daniel.kruegler at googlemail dot com
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-05-25  8:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Do we have a DR # for this issue?


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

* [Bug c++/47765] Wrong template deduction
  2011-02-16 12:32 [Bug c++/47765] New: Wrong template deduction dk_mipt at mail dot ru
                   ` (6 preceding siblings ...)
  2013-05-25  8:51 ` paolo.carlini at oracle dot com
@ 2013-05-25  9:19 ` daniel.kruegler at googlemail dot com
  2013-05-25 11:07 ` [Bug c++/47765] [Core/1391] " paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-05-25  9:19 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 3871 bytes --]

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

--- Comment #8 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
(In reply to Paolo Carlini from comment #7)
> Do we have a DR # for this issue?

It seems to me that this is

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1391

submitted by Jason with a simplified form of the example discussed here.
>From gcc-bugs-return-423128-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sat May 25 09:46:38 2013
Return-Path: <gcc-bugs-return-423128-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 28359 invoked by alias); 25 May 2013 09:46:38 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 28340 invoked by uid 48); 25 May 2013 09:46:35 -0000
From: "dominiq at lps dot ens.fr" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug testsuite/57413] New: FAIL: gcc.dg/debug/dwarf2/discriminator.c scan-assembler on x86_64-apple-darwin10
Date: Sat, 25 May 2013 09:46:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: testsuite
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: dominiq at lps dot ens.fr
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc cf_gcchost cf_gcctarget cf_gccbuild attachments.created
Message-ID: <bug-57413-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-05/txt/msg01801.txt.bz2
Content-length: 1598

http://gcc.gnu.org/bugzilla/show_bug.cgi?idW413

            Bug ID: 57413
           Summary: FAIL: gcc.dg/debug/dwarf2/discriminator.c
                    scan-assembler on x86_64-apple-darwin10
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: testsuite
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dominiq at lps dot ens.fr
                CC: dehao at google dot com
              Host: x86_64-apple-darwin10
            Target: x86_64-apple-darwin10
             Build: x86_64-apple-darwin10

Created attachment 30191
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id0191&actioníit
Generated assembly

The test gcc.dg/debug/dwarf2/discriminator.c fails on x86_64-apple-darwin10 for
both -m32 and -m64:

FAIL: gcc.dg/debug/dwarf2/discriminator.c scan-assembler loc [0-9] 9 [0-9](
is_stmt [0-9])?\\n
FAIL: gcc.dg/debug/dwarf2/discriminator.c scan-assembler loc [0-9] 9 [0-9](
is_stmt [0-9])? discriminator 2\\n
FAIL: gcc.dg/debug/dwarf2/discriminator.c scan-assembler loc [0-9] 9 [0-9](
is_stmt [0-9])? discriminator 1\\n

I attach the assembly produced by

/opt/gcc/build_w/gcc/xgcc -B/opt/gcc/build_w/gcc/
/opt/gcc/work/gcc/testsuite/gcc.dg/debug/dwarf2/discriminator.c
-fno-diagnostics-show-caret -fdiagnostics-color=never -O0 -gdwarf-2 -S

GCC is configured with:
../work/configure --prefix=/opt/gcc/gcc4.9w
--enable-languages=c,c++,fortran,objc,obj-c++,java,ada,lto --with-gmp=/opt/mp
--with-system-zlib --with-isl=/opt/mp --enable-lto --enable-plugin


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

* [Bug c++/47765] [Core/1391] Wrong template deduction
  2011-02-16 12:32 [Bug c++/47765] New: Wrong template deduction dk_mipt at mail dot ru
                   ` (7 preceding siblings ...)
  2013-05-25  9:19 ` daniel.kruegler at googlemail dot com
@ 2013-05-25 11:07 ` paolo.carlini at oracle dot com
  2015-03-20 16:57 ` paolo.carlini at oracle dot com
  2020-05-08 15:38 ` mpolacek at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-05-25 11:07 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Wrong template deduction    |[Core/1391] Wrong template
                   |                            |deduction

--- Comment #9 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Ah, nice. Thanks.


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

* [Bug c++/47765] [Core/1391] Wrong template deduction
  2011-02-16 12:32 [Bug c++/47765] New: Wrong template deduction dk_mipt at mail dot ru
                   ` (8 preceding siblings ...)
  2013-05-25 11:07 ` [Bug c++/47765] [Core/1391] " paolo.carlini at oracle dot com
@ 2015-03-20 16:57 ` paolo.carlini at oracle dot com
  2020-05-08 15:38 ` mpolacek at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-20 16:57 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |SUSPENDED


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

* [Bug c++/47765] [Core/1391] Wrong template deduction
  2011-02-16 12:32 [Bug c++/47765] New: Wrong template deduction dk_mipt at mail dot ru
                   ` (9 preceding siblings ...)
  2015-03-20 16:57 ` paolo.carlini at oracle dot com
@ 2020-05-08 15:38 ` mpolacek at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-05-08 15:38 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org
             Status|SUSPENDED                   |RESOLVED
         Resolution|---                         |FIXED

--- Comment #10 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in r223301.

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

end of thread, other threads:[~2020-05-08 15:38 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-16 12:32 [Bug c++/47765] New: Wrong template deduction dk_mipt at mail dot ru
2011-09-08  9:22 ` [Bug c++/47765] " daniel.kruegler at googlemail dot com
2011-09-08 10:52 ` paolo.carlini at oracle dot com
2011-09-08 16:22 ` jason at gcc dot gnu.org
2011-09-08 17:05 ` daniel.kruegler at googlemail dot com
2011-09-08 19:23 ` jason at gcc dot gnu.org
2011-09-08 19:46 ` jason at gcc dot gnu.org
2013-05-25  8:51 ` paolo.carlini at oracle dot com
2013-05-25  9:19 ` daniel.kruegler at googlemail dot com
2013-05-25 11:07 ` [Bug c++/47765] [Core/1391] " paolo.carlini at oracle dot com
2015-03-20 16:57 ` paolo.carlini at oracle dot com
2020-05-08 15:38 ` mpolacek 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).