Topic: using directive and ambiguities


Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: Mon, 19 Nov 2001 16:54:53 GMT
Raw View
Richard Corden <richards_corden@hotmail.com> writes:

> Is this ambiguous?  As the type name X is already hidden by
> the function A::X?

It is not ambiguous, since the struct is hidden, see 3.3.7.
>
> Is this ambiguous?  Or does paragraph 4 only relate to names
> found via using directives?

Again, it's not ambiguous. See the rules for unqualified lookup in
3.4.1 for details. B::X appears to be in the global namespace when
being lookup up inside foo, but ::X(float) still hides struct ::X; so
lookup only finds ::X(float) and B::X(int), which are both functions.

Regards,
Martin

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Michiel Salters<Michiel.Salters@cmg.nl>
Date: Tue, 20 Nov 2001 18:09:11 GMT
Raw View
In article <831yiy4rn9.fsf@leinster.programmingresearch.ie>, Richard Corden
says...
>
>From 7.3.4 Paragraph 4, I was trying to work out when
>names are ambiguous.
>
>For example, if I modify the example given under para 4,
>so namespace A also contains a fuction:
>
>///////////////////////////
>namespace A {
>    class X {};
>    void X(float);
>}
>
>namespace B {
>    void X (int);
>}
>
>using namespace A;
>using namespace B;
>
>void foo ()
>{
>    X (0);
>}
>///////////////////////////
>
>Is this ambiguous?  As the type name X is already hidden by
>the function A::X?

I don't see this as ambiguous; 7.3.4 says "If name lookup finds
a declaration for a name in two different namespaces, ..."
( Yes - void A::X(float) and void B::X(int) are found by name
lookup, see 3.4/3.3.7 ) "... and the declarations do not declare
the same entity and do not declare functions, the use of the name
is ill-formed. "
Both A::X and B::X are functions, so the use of X isn't ill-formed.

Also, consider 3.3.7/2 "the class or enumeration name is hidden
wherever the object, function, or enumerator name is visible. "
By 3.4.1 , void A::X(int) is visible in your function foo() so it
must hide the class A::X.

The point is that function B::X can't hide class A::X.

>Alternatively, if the names from namespace A are in the global
>scope as follows:
>
>///////////////////////////
>class X {};
>void X(float);
>
>namespace B {
>    void X (int);
>}
>
>using namespace B;
>
>void foo ()
>{
>    X (0);
>}
>///////////////////////////
>
>Is this ambiguous?  Or does paragraph 4 only relate to names
>found via using directives?
>
>Thanks for your help,
>Richard

The global namespace is a namespace, too, so 7.3.4/4 still applies.
3.4.1/2 Is quite clear, B::X(int) is looked up  as if named ::X(int)
in the global namespace.

Regards,

--
Michiel Salters
Consultant Technical Software Engineering
CMG Trade, Transport & Industry
Michiel.Salters@cmg.nl

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Pete Becker <petebecker@acm.org>
Date: Tue, 20 Nov 2001 18:39:18 GMT
Raw View
Richard Corden wrote:
>
> >From 7.3.4 Paragraph 4, I was trying to work out when
> names are ambiguous.
>
> For example, if I modify the example given under para 4,
> so namespace A also contains a fuction:
>
> ///////////////////////////
> namespace A {
>     class X {};
>     void X(float);
> }
>
> namespace B {
>     void X (int);
> }
>
> using namespace A;
> using namespace B;
>
> void foo ()
> {
>     X (0);
> }
> ///////////////////////////
>
> Is this ambiguous?  As the type name X is already hidden by
> the function A::X?
>

Unfortunately, I can't find a compiler that agrees with what I said in
my other message. So if the moderators haven't noticed and posted it
anyway, ignore it. <g>

--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Pete Becker <petebecker@acm.org>
Date: Tue, 20 Nov 2001 19:30:47 GMT
Raw View
Richard Corden wrote:
>
> >From 7.3.4 Paragraph 4, I was trying to work out when
> names are ambiguous.
>
> For example, if I modify the example given under para 4,
> so namespace A also contains a fuction:
>
> ///////////////////////////
> namespace A {
>     class X {};
>     void X(float);
> }
>
> namespace B {
>     void X (int);
> }
>
> using namespace A;
> using namespace B;
>
> void foo ()
> {
>     X (0);
> }
> ///////////////////////////
>
> Is this ambiguous?  As the type name X is already hidden by
> the function A::X?
>

Yes, it's ambiguous. Forget about the class X. The two functions are
defined in different scopes, so they do not overload. The result is that
there are two different functions that could be called, and no rule for
deciding which one to call.

--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Richard Corden <richards_corden@hotmail.com>
Date: Wed, 21 Nov 2001 16:28:01 GMT
Raw View
Thanks to all for your replys...

Actually, the main reason I posted here was because the Comeau compiler
treats my two examples differently.  Where the class and function are
declared in namespace A, it says X is ambiguous.  Where they are declared
in the global namespace it does not complain.

As a general rule I have come to use Comeau as my yard stick about standard
issues, and so this difference left me confused.

Thanks again,

Regards,

Richard


--
Richard Corden
To reply remove 's' from address

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Richard Corden <richards_corden@hotmail.com>
Date: Fri, 16 Nov 2001 16:31:10 GMT
Raw View
>From 7.3.4 Paragraph 4, I was trying to work out when
names are ambiguous.

For example, if I modify the example given under para 4,
so namespace A also contains a fuction:

///////////////////////////
namespace A {
    class X {};
    void X(float);
}

namespace B {
    void X (int);
}

using namespace A;
using namespace B;

void foo ()
{
    X (0);
}
///////////////////////////

Is this ambiguous?  As the type name X is already hidden by
the function A::X?


Alternatively, if the names from namespace A are in the global
scope as follows:

///////////////////////////
class X {};
void X(float);

namespace B {
    void X (int);
}

using namespace B;

void foo ()
{
    X (0);
}
///////////////////////////

Is this ambiguous?  Or does paragraph 4 only relate to names
found via using directives?

Thanks for your help,

Richard

--
Richard Corden
To reply remove 's' from address

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]