public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26110]  New: using directive breaks ADL
@ 2006-02-05 22:15 dg001 at t-online dot de
  2006-02-05 22:22 ` [Bug c++/26110] " pinskia at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: dg001 at t-online dot de @ 2006-02-05 22:15 UTC (permalink / raw)
  To: gcc-bugs

When compiling the following code, an incorrect binary is produced:

--- BEGIN CODE ---
namespace test {
        double f(double f)
        {
                return f + 1.;
        }
}

double f(float d)
{
        return d;
}

int main(int argc, char *argv[]) 
{
        using test::f;

        float d = 2.;

        double result1 = f(d);

        double result2 = test::f(d);

        return 0;
}       

--- END CODE ---
The line
double result1 = f(d);
should call the function "double f(float d)", instead it calls the function
"double f(double f)" in namespace test.
This breaks argument dependent lookup. The using directive should only make
visible the function in namespace test, but not hide the global one.
If you replace "using test::f" with "using namespace test", then everything
works correctly.


gcc -v gives me:

~> gcc -v
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,f95,java,ada --disable-checking
--with-gxx-include-dir=/usr/include/c++/4.0.2 --enable-java-awt=gtk
--disable-libjava-multilib --with-slibdir=/lib64 --with-system-zlib
--enable-shared --enable-__cxa_atexit --without-system-libunwind
--host=x86_64-suse-linux
Thread model: posix
gcc version 4.0.2 20050901 (prerelease) (SUSE Linux)


-- 
           Summary: using directive breaks ADL
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dg001 at t-online dot de


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


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

* [Bug c++/26110] using directive breaks ADL
  2006-02-05 22:15 [Bug c++/26110] New: using directive breaks ADL dg001 at t-online dot de
@ 2006-02-05 22:22 ` pinskia at gcc dot gnu dot org
  2006-02-05 23:14 ` dg001 at t-online dot de
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-05 22:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-02-05 22:22 -------
Why do you think this breaks ADL?
float is not in any namespace really.

Also you explicately said to use test::f and no other which is what the using
says to do in this scope.

if you move the using to the global scope it works the way you it to work.


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

* [Bug c++/26110] using directive breaks ADL
  2006-02-05 22:15 [Bug c++/26110] New: using directive breaks ADL dg001 at t-online dot de
  2006-02-05 22:22 ` [Bug c++/26110] " pinskia at gcc dot gnu dot org
@ 2006-02-05 23:14 ` dg001 at t-online dot de
  2006-02-05 23:41 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: dg001 at t-online dot de @ 2006-02-05 23:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from dg001 at t-online dot de  2006-02-05 23:14 -------
The first statement in my code  doesn't use any namespace

double result1 = f(d);

So ADL should take the function with the signature (float d), which is in
global namespace.

There is of course a second statement in my code:
double result2 = test::f(d);
and yes, this works correctly.

So please have a closer look at the *first* statement, which doesn't compile to
correct code.


-- 

dg001 at t-online dot de changed:

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


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


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

* [Bug c++/26110] using directive breaks ADL
  2006-02-05 22:15 [Bug c++/26110] New: using directive breaks ADL dg001 at t-online dot de
  2006-02-05 22:22 ` [Bug c++/26110] " pinskia at gcc dot gnu dot org
  2006-02-05 23:14 ` dg001 at t-online dot de
@ 2006-02-05 23:41 ` pinskia at gcc dot gnu dot org
  2006-02-06  0:17 ` dg001 at t-online dot de
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-05 23:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2006-02-05 23:41 -------
This has nothing to do with ADL really.
using test::f; forces to use test::f when doing f(a) in that scope since that
is the f in that scope.

Again this is not a bug GCC.


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

* [Bug c++/26110] using directive breaks ADL
  2006-02-05 22:15 [Bug c++/26110] New: using directive breaks ADL dg001 at t-online dot de
                   ` (2 preceding siblings ...)
  2006-02-05 23:41 ` pinskia at gcc dot gnu dot org
@ 2006-02-06  0:17 ` dg001 at t-online dot de
  2006-02-06  0:29 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: dg001 at t-online dot de @ 2006-02-06  0:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from dg001 at t-online dot de  2006-02-06 00:17 -------
I had a look at ISO/IEC 14882:2003(E). That is the ANSI/ISO Standard for C++.
Paragraph 3.4.2 deals with Argument-dependent name lookup.
In section 2 I read:
"The sets of namespaces and classes is determined
entirely by the types of the function arguments (and the namespace of any
template template argument).
Typedef names and using-declarations used to specify the types do not
contribute to this set."

So a using-declaration should not alter the way argument-dependent name lookup
works.

I came across this issue when I tried to compile an example from Scott Myers,
"Effective C++", 3rd edition, item 25. There is a using-declaration on page
110, that doesn't work with gcc version 4.0.2.

Again, the using-declaration only makes the function, if it be my f(...), Myers
or stl's swap(...), visible in the scope. But the compiler takes the arguments
of the function call into consideration, which of the visible functions fits
best.

The example I gave above is very simplified. But you can replace the
fundamental types of double and float with real classes, and the problem
persits.

I just didn't want to post the contents of 5 files (header + implementation)
here.

I'd be glad, if you looked up my references. I still claim that the
beforementioned version of gcc doesn't conform to the C++ standard.


-- 

dg001 at t-online dot de changed:

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


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


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

* [Bug c++/26110] using directive breaks ADL
  2006-02-05 22:15 [Bug c++/26110] New: using directive breaks ADL dg001 at t-online dot de
                   ` (3 preceding siblings ...)
  2006-02-06  0:17 ` dg001 at t-online dot de
@ 2006-02-06  0:29 ` pinskia at gcc dot gnu dot org
  2006-02-06 20:06 ` dg001 at t-online dot de
  2006-02-06 20:24 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-06  0:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2006-02-06 00:29 -------
Why do you think ADL has anything to do with finding ::f here?

>From the standard:
-- If T is a fundamental type, its associated sets of namespaces and classes
are both empty.

So we cannot find ::f here at all.


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

* [Bug c++/26110] using directive breaks ADL
  2006-02-05 22:15 [Bug c++/26110] New: using directive breaks ADL dg001 at t-online dot de
                   ` (4 preceding siblings ...)
  2006-02-06  0:29 ` pinskia at gcc dot gnu dot org
@ 2006-02-06 20:06 ` dg001 at t-online dot de
  2006-02-06 20:24 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: dg001 at t-online dot de @ 2006-02-06 20:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from dg001 at t-online dot de  2006-02-06 20:06 -------
Note, I didn't change the status of the bug yet.
And you are absolutely right about the behavior of fundamental types. But I
still encounter a problem with classes.
Can you explain the behavior of gcc in the following example?

--- BEGIN CODE ---

namespace test {
        template<typename T1> double f(T1 f)
        {
                return 2.;
        }
}

class Type1 {
public:
        Type1()
        {}
        ~Type1()
        {}
};

double f(Type1 f)
{
        return 1.;
}       




int main(int argc, char *argv[]) 
{
        using test::f;

        Type1 d;

        double result1 = f(d);

        double result2 = test::f(d);

        return 0;
}       

--- END CODE ---

class Type1 and the function f are in the global namespace. Nevertheless
"double result1 = f(d);" calls "template<typename T1> double f(T1 f)", which I
think is wrong. The function "double f(Type1 f)" should be called instead.
I tested this with another compiler (MS VC++ 8) and the code of this compiler
calls the global function f in this case.
Which behavior is the right one acording to the standard?

If you now put "class Type1" and and "double f(Type1 f)" in their own namespace
and change the code so it builds again, then gcc produces code, that calls the
function "double f(Type1 f)" when executing the line "double result1 = f(d);". 

Is there anything wrong with the global namespace?


-- 


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


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

* [Bug c++/26110] using directive breaks ADL
  2006-02-05 22:15 [Bug c++/26110] New: using directive breaks ADL dg001 at t-online dot de
                   ` (5 preceding siblings ...)
  2006-02-06 20:06 ` dg001 at t-online dot de
@ 2006-02-06 20:24 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-06 20:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pinskia at gcc dot gnu dot org  2006-02-06 20:24 -------
(In reply to comment #6)
> Note, I didn't change the status of the bug yet.
> And you are absolutely right about the behavior of fundamental types. But I
> still encounter a problem with classes.
> Can you explain the behavior of gcc in the following example?

That was a bug in GCC before 4.1.0 and has been fixed in 4.1.0.


-- 


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


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

end of thread, other threads:[~2006-02-06 20:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-05 22:15 [Bug c++/26110] New: using directive breaks ADL dg001 at t-online dot de
2006-02-05 22:22 ` [Bug c++/26110] " pinskia at gcc dot gnu dot org
2006-02-05 23:14 ` dg001 at t-online dot de
2006-02-05 23:41 ` pinskia at gcc dot gnu dot org
2006-02-06  0:17 ` dg001 at t-online dot de
2006-02-06  0:29 ` pinskia at gcc dot gnu dot org
2006-02-06 20:06 ` dg001 at t-online dot de
2006-02-06 20:24 ` pinskia at gcc dot gnu dot 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).