Deutsch English Français Italiano |
<vbi6qd$1fpiu$1@raubtier-asyl.eternal-september.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!3.eu.feeder.erje.net!feeder.erje.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail From: Bonita Montero <Bonita.Montero@gmail.com> Newsgroups: comp.lang.c++ Subject: Re: Namespace vs. class ambiguity: three compilers - three different outcomes Date: Sat, 7 Sep 2024 20:42:26 +0200 Organization: A noiseless patient Spider Lines: 52 Message-ID: <vbi6qd$1fpiu$1@raubtier-asyl.eternal-september.org> References: <vbi5p0$1f8u2$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 07 Sep 2024 20:42:21 +0200 (CEST) Injection-Info: raubtier-asyl.eternal-september.org; posting-host="8d495bec4d845596c9456083b69cf5b8"; logging-data="1566302"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/dj8iwkPSL9cr4jnhLoy/qogBwR9z8nsg=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:3pxQeS7mhB2D3KzBf1BLAMu/3mY= In-Reply-To: <vbi5p0$1f8u2$1@dont-email.me> Content-Language: de-DE Bytes: 2698 Am 07.09.2024 um 20:24 schrieb Andrey Tarasevich: > Hello > > It is illegal to just flat-out declare a class and a namespace with > identical names in the same scope > > namespace N {} > class N {}; // <- Not allowed > > However, one can try to circumvent the direct restriction by means of > using-directive or using-declaration > > #include <iostream> > > namespace N > { > void foo() { std::cout << "namespace" << std::endl; } > } > > namespace X > { > struct N > { > static void foo() { std::cout << "class" << std::endl; } > }; > } > > using X::N; > // or > // using namespace X; > > int main() > { > N::foo(); > } > > GCC is perfectly happy with either version of this code (both using- > declaration and using-directive versions are OK). It simply resolves the > call to the "namespace" version of `foo()`. > > Clang issues an error: it complains about the call being ambiguous. I.e. > the error is issued at the point of the call. > > MSVC++ issues an error for `using X::N;` at the point of using- > declaration: it basically says that `N` already exists in this scope. > But if we switch to `using namespace X;` version, MSVC++ will exhibit > Clang-like behavior: complain about ambiguity at the point of the call. > > So, who is right here? Does it really matter or is it just sufficient to prevent such code ?