public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/61987] New: Name Resolution within a Template
@ 2014-08-01  9:34 gaoyuanming at hotmail dot com
  2014-08-01  9:36 ` [Bug c++/61987] " gaoyuanming at hotmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: gaoyuanming at hotmail dot com @ 2014-08-01  9:34 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 61987
           Summary: Name Resolution within a Template
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gaoyuanming at hotmail dot com

Created attachment 33222
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33222&action=edit
Assembly code

I compiled the piece of code:

#include <stdlib.h>

int foo(double d) { return static_cast<int>(d); }

template <typename T>
class Test
{
public:
        Test(int id, T const & value) : m_id(id), m_value(value) {}

        void change()
        {
                m_value = foo(m_id);
        }

        void change(int seed)
        {
                m_id = foo(m_value) * seed;
        }

        T value() const { return m_value; }
private:
        int m_id;
        T   m_value;
};

int foo(int n) { return n; }

int main()
{
    Test<int> t(10, 20);
    t.change();
    t.change(2);

    Test<unsigned long> tul(10, 30);
    tul.change();
    tul.change(3);

    return 0;
}

and found that the function void Test<int>::change(int) calls int foo(double)
to implement it. It is a bug.


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

* [Bug c++/61987] Name Resolution within a Template
  2014-08-01  9:34 [Bug c++/61987] New: Name Resolution within a Template gaoyuanming at hotmail dot com
@ 2014-08-01  9:36 ` gaoyuanming at hotmail dot com
  2014-08-01  9:46 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gaoyuanming at hotmail dot com @ 2014-08-01  9:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Yuanming Gao <gaoyuanming at hotmail dot com> ---
Created attachment 33223
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33223&action=edit
source code


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

* [Bug c++/61987] Name Resolution within a Template
  2014-08-01  9:34 [Bug c++/61987] New: Name Resolution within a Template gaoyuanming at hotmail dot com
  2014-08-01  9:36 ` [Bug c++/61987] " gaoyuanming at hotmail dot com
@ 2014-08-01  9:46 ` pinskia at gcc dot gnu.org
  2014-08-01 10:00 ` gaoyuanming at hotmail dot com
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-08-01  9:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I don't think this is a bug as foundmental types does not have an associated
namespace associated with it. So the overload set is only what is declared
before the template.


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

* [Bug c++/61987] Name Resolution within a Template
  2014-08-01  9:34 [Bug c++/61987] New: Name Resolution within a Template gaoyuanming at hotmail dot com
  2014-08-01  9:36 ` [Bug c++/61987] " gaoyuanming at hotmail dot com
  2014-08-01  9:46 ` pinskia at gcc dot gnu.org
@ 2014-08-01 10:00 ` gaoyuanming at hotmail dot com
  2014-08-01 10:06 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gaoyuanming at hotmail dot com @ 2014-08-01 10:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Yuanming Gao <gaoyuanming at hotmail dot com> ---
Please read the book: <<Inside the Cpp Object Mode>>. The code comes from <<7.1
Templates>>. The author thought the function int foo(int) must be selected.


Best regards,
Yuanming Gao

> From: gcc-bugzilla@gcc.gnu.org
> To: gaoyuanming@hotmail.com
> Subject: [Bug c++/61987] Name Resolution within a Template
> Date: Fri, 1 Aug 2014 09:46:21 +0000
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61987
> 
> --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> I don't think this is a bug as foundmental types does not have an associated
> namespace associated with it. So the overload set is only what is declared
> before the template.
> 
> -- 
> You are receiving this mail because:
> You reported the bug.


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

* [Bug c++/61987] Name Resolution within a Template
  2014-08-01  9:34 [Bug c++/61987] New: Name Resolution within a Template gaoyuanming at hotmail dot com
                   ` (2 preceding siblings ...)
  2014-08-01 10:00 ` gaoyuanming at hotmail dot com
@ 2014-08-01 10:06 ` pinskia at gcc dot gnu.org
  2014-08-01 10:28 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-08-01 10:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Yuanming Gao from comment #3)
> Please read the book: <<Inside the Cpp Object Mode>>. The code comes from
> <<7.1 Templates>>. The author thought the function int foo(int) must be
> selected.

Well I disagree with that book based on what the c++ standard says about
foundmental types and how argument dependent lookup works.


>  
>  
> Best regards,
> Yuanming Gao
>  
> > From: gcc-bugzilla@gcc.gnu.org
> > To: gaoyuanming@hotmail.com
> > Subject: [Bug c++/61987] Name Resolution within a Template
> > Date: Fri, 1 Aug 2014 09:46:21 +0000
> > 
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61987
> > 
> > --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> > I don't think this is a bug as foundmental types does not have an associated
> > namespace associated with it. So the overload set is only what is declared
> > before the template.
> > 
> > -- 
> > You are receiving this mail because:
> > You reported the bug.


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

* [Bug c++/61987] Name Resolution within a Template
  2014-08-01  9:34 [Bug c++/61987] New: Name Resolution within a Template gaoyuanming at hotmail dot com
                   ` (3 preceding siblings ...)
  2014-08-01 10:06 ` pinskia at gcc dot gnu.org
@ 2014-08-01 10:28 ` redi at gcc dot gnu.org
  2014-08-01 11:25 ` gaoyuanming at hotmail dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2014-08-01 10:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
G++ and clang++ call f(double) four times, because that is the only function
visible in the template definition. foo(int) is only visible at the point of
instantiation, so could only be found by ADL, but int has no associated
namespaces.

EDG does call foo(int) twice, and fails to compile because the call with
unsigned long argument could call foo(double) or foo(int) and so is ambiguous.

So either the code never calls foo(int) or the code doesn't compile!


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

* [Bug c++/61987] Name Resolution within a Template
  2014-08-01  9:34 [Bug c++/61987] New: Name Resolution within a Template gaoyuanming at hotmail dot com
                   ` (4 preceding siblings ...)
  2014-08-01 10:28 ` redi at gcc dot gnu.org
@ 2014-08-01 11:25 ` gaoyuanming at hotmail dot com
  2014-08-01 11:27 ` gaoyuanming at hotmail dot com
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gaoyuanming at hotmail dot com @ 2014-08-01 11:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Yuanming Gao <gaoyuanming at hotmail dot com> ---
Visual C++ can select the  int foo(int) correctly. I don't know whether it is
an implementation issue, or it is by design.

Best regards,
Yuanming

> From: gcc-bugzilla@gcc.gnu.org
> To: gaoyuanming@hotmail.com
> Subject: [Bug c++/61987] Name Resolution within a Template
> Date: Fri, 1 Aug 2014 10:06:00 +0000
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61987
> 
> --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> (In reply to Yuanming Gao from comment #3)
> > Please read the book: <<Inside the Cpp Object Mode>>. The code comes from
> > <<7.1 Templates>>. The author thought the function int foo(int) must be
> > selected.
> 
> Well I disagree with that book based on what the c++ standard says about
> foundmental types and how argument dependent lookup works.
> 
> 
> >  
> >  
> > Best regards,
> > Yuanming Gao
> >  
> > > From: gcc-bugzilla@gcc.gnu.org
> > > To: gaoyuanming@hotmail.com
> > > Subject: [Bug c++/61987] Name Resolution within a Template
> > > Date: Fri, 1 Aug 2014 09:46:21 +0000
> > > 
> > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61987
> > > 
> > > --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> > > I don't think this is a bug as foundmental types does not have an associated
> > > namespace associated with it. So the overload set is only what is declared
> > > before the template.
> > > 
> > > -- 
> > > You are receiving this mail because:
> > > You reported the bug.
> 
> -- 
> You are receiving this mail because:
> You reported the bug.


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

* [Bug c++/61987] Name Resolution within a Template
  2014-08-01  9:34 [Bug c++/61987] New: Name Resolution within a Template gaoyuanming at hotmail dot com
                   ` (5 preceding siblings ...)
  2014-08-01 11:25 ` gaoyuanming at hotmail dot com
@ 2014-08-01 11:27 ` gaoyuanming at hotmail dot com
  2014-08-01 11:32 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gaoyuanming at hotmail dot com @ 2014-08-01 11:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Yuanming Gao <gaoyuanming at hotmail dot com> ---
Please read the book: <<Inside the Cpp Object Mode>>. The code comes from <<7.1
Templates>>. The author thought the function int foo(int) must be selected.

Visual C++ can select the int foo(int) correctly. I don't know whether it is an
implementation issue, or it is by design.

Best regards,
Yuanming

> From: gcc-bugzilla@gcc.gnu.org
> To: gaoyuanming@hotmail.com
> Subject: [Bug c++/61987] Name Resolution within a Template
> Date: Fri, 1 Aug 2014 10:28:36 +0000
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61987
> 
> --- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> G++ and clang++ call f(double) four times, because that is the only function
> visible in the template definition. foo(int) is only visible at the point of
> instantiation, so could only be found by ADL, but int has no associated
> namespaces.
> 
> EDG does call foo(int) twice, and fails to compile because the call with
> unsigned long argument could call foo(double) or foo(int) and so is ambiguous.
> 
> So either the code never calls foo(int) or the code doesn't compile!
> 
> -- 
> You are receiving this mail because:
> You reported the bug.


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

* [Bug c++/61987] Name Resolution within a Template
  2014-08-01  9:34 [Bug c++/61987] New: Name Resolution within a Template gaoyuanming at hotmail dot com
                   ` (6 preceding siblings ...)
  2014-08-01 11:27 ` gaoyuanming at hotmail dot com
@ 2014-08-01 11:32 ` redi at gcc dot gnu.org
  2014-08-01 18:39 ` daniel.kruegler at googlemail dot com
  2014-08-07 15:57 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2014-08-01 11:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
VC++ and the book are both wrong.


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

* [Bug c++/61987] Name Resolution within a Template
  2014-08-01  9:34 [Bug c++/61987] New: Name Resolution within a Template gaoyuanming at hotmail dot com
                   ` (7 preceding siblings ...)
  2014-08-01 11:32 ` redi at gcc dot gnu.org
@ 2014-08-01 18:39 ` daniel.kruegler at googlemail dot com
  2014-08-07 15:57 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2014-08-01 18:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler@googlemail.
                   |                            |com

--- Comment #9 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
(In reply to Yuanming Gao from comment #7)
> Please read the book: <<Inside the Cpp Object Mode>>. The code comes from
> <<7.1 Templates>>. The author thought the function int foo(int) must be
> selected.
> 
> Visual C++ can select the int foo(int) correctly. I don't know whether it is
> an implementation issue, or it is by design.

"Can select" is irrelevant in the context of correctness. As others have
already said: The standard requires to consider *only* the overload
foo(double), because for fundamental types the associated set of namespaces is
empty (see [basic.lookup.argdep] p2 b1). In this case, argument-depending
lookup doesn't happen, and only the overloads that can be found lexically
before the call location as part of the (reduced) unqualified lookup are
considered.
>From gcc-bugs-return-457584-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Aug 01 18:45:31 2014
Return-Path: <gcc-bugs-return-457584-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 6912 invoked by alias); 1 Aug 2014 18:45:28 -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 6830 invoked by uid 48); 1 Aug 2014 18:45:22 -0000
From: "jason at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/53492] [4.8 Regression] ICE in retrieve_specialization, at cp/pt.c:985
Date: Fri, 01 Aug 2014 18:45:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.6.1
X-Bugzilla-Keywords: accepts-invalid, ice-on-invalid-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jason at gcc dot gnu.org
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: jason at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.8.4
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status resolution
Message-ID: <bug-53492-4-PlzWU3Z3Xe@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-53492-4@http.gcc.gnu.org/bugzilla/>
References: <bug-53492-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: 2014-08/txt/msg00081.txt.bz2
Content-length: 460

https://gcc.gnu.org/bugzilla/show_bug.cgi?idS492

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> ---
Not backporting fixes for invalid code bugs.


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

* [Bug c++/61987] Name Resolution within a Template
  2014-08-01  9:34 [Bug c++/61987] New: Name Resolution within a Template gaoyuanming at hotmail dot com
                   ` (8 preceding siblings ...)
  2014-08-01 18:39 ` daniel.kruegler at googlemail dot com
@ 2014-08-07 15:57 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2014-08-07 15:57 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

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

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Closing - GCC does the right thing.


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

end of thread, other threads:[~2014-08-07 15:57 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-01  9:34 [Bug c++/61987] New: Name Resolution within a Template gaoyuanming at hotmail dot com
2014-08-01  9:36 ` [Bug c++/61987] " gaoyuanming at hotmail dot com
2014-08-01  9:46 ` pinskia at gcc dot gnu.org
2014-08-01 10:00 ` gaoyuanming at hotmail dot com
2014-08-01 10:06 ` pinskia at gcc dot gnu.org
2014-08-01 10:28 ` redi at gcc dot gnu.org
2014-08-01 11:25 ` gaoyuanming at hotmail dot com
2014-08-01 11:27 ` gaoyuanming at hotmail dot com
2014-08-01 11:32 ` redi at gcc dot gnu.org
2014-08-01 18:39 ` daniel.kruegler at googlemail dot com
2014-08-07 15:57 ` redi 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).