public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "zeratul976 at hotmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/56943] New: Incorrect two-phase name lookup for operators
Date: Fri, 12 Apr 2013 23:35:00 -0000	[thread overview]
Message-ID: <bug-56943-4@http.gcc.gnu.org/bugzilla/> (raw)


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

             Bug #: 56943
           Summary: Incorrect two-phase name lookup for operators
    Classification: Unclassified
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: zeratul976@hotmail.com


When the following code is run:


#include <iostream>

namespace N
{
    struct A
    {
        int operator+(const void*) 
        { 
            return 42; 
        }
    };
}

namespace M
{
    struct B
    {
    };
}


template <typename T, typename U>
int add(T t, U u)
{
    return t + u;
}

int operator+(N::A, M::B*) 
{ 
    return 5; 
}

int main(int argc, char** argv)
{
    N::A a;
    M::B b;
    std::cout << add(a, &b) << "\n";
}


the output is "5". I believe the correct output wouldbe "42", because when
looking up operator+ in the expression "t + u", the operator+(N::A, M::B*)
overload is found neither by unqualified lookup at the point of definition
(since it is not declared yet at the point of definition), nor by
argument-dependent lookup at the point of instantiation (since it is not in the
namespace of either of its arguments).

Clang outputs "42" for this example, as expected.


             reply	other threads:[~2013-04-12 23:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-12 23:35 zeratul976 at hotmail dot com [this message]
2013-04-13  0:33 ` [Bug c++/56943] " paolo.carlini at oracle dot com
2013-04-13  0:45 ` zeratul976 at hotmail dot com

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-56943-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).