public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15075] New: "using namespace" fails in part
@ 2004-04-22 17:05 gcc-bugzilla at gcc dot gnu dot org
2004-04-22 17:12 ` [Bug c++/15075] " lnewberg at wadsworth dot org
` (6 more replies)
0 siblings, 7 replies; 9+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2004-04-22 17:05 UTC (permalink / raw)
To: gcc-bugs
"using namespace Test;" fails to tell the compiler that a friendly
function definition is within Test. "namespace Test {...}" works fine.
Environment:
System: SunOS bioquad 5.9 Generic_112233-11 sun4u sparc SUNW,Sun-Fire-V440
Architecture: sun4
host: sparc-sun-solaris2.9
build: sparc-sun-solaris2.9
target: sparc-sun-solaris2.9
configured with: ../../../distribution/gcc-3.3.2/configure --prefix=/local/bioproj/people/lnewberg/install/sparc-sun-solaris2.9/gcc-3.3.2 --with-ld=/usr/ccs/bin/ld --with-as=/usr/ccs/bin/as --disable-nls --enable-languages=c,c++,objc
How-To-Repeat:
Compile with g++ -c test2.cc
--- Begin test2.cc ---
// This file does not compile under g++. I think it should. See
// below.
namespace Test
{
class A
{
private:
class B
{
public:
int _b;
};
friend bool works1(B const &);
friend bool works2(B const &);
friend bool fails(B const &);
};
} // End of namespace Test
namespace Test
{
bool works1(A::B const &lhs)
{
return true;
}
} // End of namespace Test
using namespace Test;
// Despite the "using namespace Test" directive, the function fails()
// must be declared as "Test::fails" rather than simply "fails" or the
// compiler complains that class Test::A::B is private in this
// context.
//
// Note that the "using" directive does work to eliminate the need to
// use the explicit Test::A::B instead of the shorter A::B in the
// definition of fails() below.
//
// Contrastingly, the functions works1(), above, and works2(), below,
// compile without error.
bool Test::works2(A::B const &)
{
return true;
}
bool fails(A::B const &)
{
return true;
}
--- End test2.cc ---
------- Additional Comments From lnewberg at wadsworth dot org 2004-04-22 16:55 -------
Fix:
Use "namespace Test {...}" instead.
--
Summary: "using namespace" fails in part
Product: gcc
Version: 3.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: lnewberg at wadsworth dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: sparc-sun-solaris2.9
GCC host triplet: sparc-sun-solaris2.9
GCC target triplet: sparc-sun-solaris2.9
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15075
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/15075] "using namespace" fails in part
2004-04-22 17:05 [Bug c++/15075] New: "using namespace" fails in part gcc-bugzilla at gcc dot gnu dot org
@ 2004-04-22 17:12 ` lnewberg at wadsworth dot org
2004-04-22 17:19 ` lnewberg at wadsworth dot org
` (5 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: lnewberg at wadsworth dot org @ 2004-04-22 17:12 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From lnewberg at wadsworth dot org 2004-04-22 17:01 -------
Created an attachment (id=6138)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=6138&action=view)
G++ source file
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15075
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/15075] "using namespace" fails in part
2004-04-22 17:05 [Bug c++/15075] New: "using namespace" fails in part gcc-bugzilla at gcc dot gnu dot org
2004-04-22 17:12 ` [Bug c++/15075] " lnewberg at wadsworth dot org
@ 2004-04-22 17:19 ` lnewberg at wadsworth dot org
2004-04-22 17:28 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: lnewberg at wadsworth dot org @ 2004-04-22 17:19 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From lnewberg at wadsworth dot org 2004-04-22 17:02 -------
Created an attachment (id=6139)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=6139&action=view)
.ii file for the previous .cc file.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15075
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/15075] "using namespace" fails in part
2004-04-22 17:05 [Bug c++/15075] New: "using namespace" fails in part gcc-bugzilla at gcc dot gnu dot org
2004-04-22 17:12 ` [Bug c++/15075] " lnewberg at wadsworth dot org
2004-04-22 17:19 ` lnewberg at wadsworth dot org
@ 2004-04-22 17:28 ` pinskia at gcc dot gnu dot org
2004-04-22 17:37 ` giovannibajo at libero dot it
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-22 17:28 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-04-22 17:12 -------
Actually I believe that works2 should be rejected just as fail is rejected.
namespace Test
{
class A
{
class B
{
};
friend bool works2(B const &);
};
}
using namespace Test;
bool Test::works2(A::B const &)
{
return true;
}
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |accepts-invalid
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15075
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/15075] "using namespace" fails in part
2004-04-22 17:05 [Bug c++/15075] New: "using namespace" fails in part gcc-bugzilla at gcc dot gnu dot org
` (2 preceding siblings ...)
2004-04-22 17:28 ` pinskia at gcc dot gnu dot org
@ 2004-04-22 17:37 ` giovannibajo at libero dot it
2004-04-22 18:35 ` bangerth at dealii dot org
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: giovannibajo at libero dot it @ 2004-04-22 17:37 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From giovannibajo at libero dot it 2004-04-22 17:28 -------
Andrew, your code is well-formed. In the friend declaration, the unqualified
name "works2" is looked up and nothing is found. So a name is injected within
the most enclosing namespace, which is Test. Basically, the friend function
acts also as a predeclaration for Test::works2().
This is a bug, but I don't have time to confirm/regression-check it now.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15075
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/15075] "using namespace" fails in part
2004-04-22 17:05 [Bug c++/15075] New: "using namespace" fails in part gcc-bugzilla at gcc dot gnu dot org
` (3 preceding siblings ...)
2004-04-22 17:37 ` giovannibajo at libero dot it
@ 2004-04-22 18:35 ` bangerth at dealii dot org
2004-04-24 22:53 ` Gabriel Dos Reis
2004-04-23 3:38 ` giovannibajo at libero dot it
2004-04-24 23:01 ` gdr at integrable-solutions dot net
6 siblings, 1 reply; 9+ messages in thread
From: bangerth at dealii dot org @ 2004-04-22 18:35 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-04-22 17:50 -------
Actually, I believe that gcc is right rejecting the code. This is how it
fails:
-----------
namespace Test {
class A {
private:
class B {};
friend void fails(B const &);
};
}
using namespace Test;
void fails(A::B const &) {}
--------------
So we agree that the friend declaration injects the name into namespace Test.
Which we then have again in the using thing. And then comes the definition
of fail, but I believe the compiler is correct in assuming that this
definition has to be in the global namespace -- the using directive only
gets active once we _look up_ names, not when we declare/define new names.
So clearly the definition of fails() does not define the predeclared/injected
Test::fails function, and the compiler is correct in rejecting it due to
an access violation:
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.cc
x.cc: In function `void fails(const Test::A::B&)':
x.cc:4: error: `class Test::A::B' is private
x.cc:11: error: within this context
Giovanni, what was your reasoning that differed from this here?
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords|accepts-invalid |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15075
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/15075] "using namespace" fails in part
2004-04-22 17:05 [Bug c++/15075] New: "using namespace" fails in part gcc-bugzilla at gcc dot gnu dot org
` (4 preceding siblings ...)
2004-04-22 18:35 ` bangerth at dealii dot org
@ 2004-04-23 3:38 ` giovannibajo at libero dot it
2004-04-24 23:01 ` gdr at integrable-solutions dot net
6 siblings, 0 replies; 9+ messages in thread
From: giovannibajo at libero dot it @ 2004-04-23 3:38 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From giovannibajo at libero dot it 2004-04-23 02:42 -------
Yes ok, I didn't properly look at the bug report. I thought GCC was behaving in
a different way.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15075
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Bug c++/15075] "using namespace" fails in part
2004-04-22 18:35 ` bangerth at dealii dot org
@ 2004-04-24 22:53 ` Gabriel Dos Reis
0 siblings, 0 replies; 9+ messages in thread
From: Gabriel Dos Reis @ 2004-04-24 22:53 UTC (permalink / raw)
To: gcc-bugzilla; +Cc: gcc-bugs
"bangerth at dealii dot org" <gcc-bugzilla@gcc.gnu.org> writes:
| definition has to be in the global namespace -- the using directive only
| gets active once we _look up_ names, not when we declare/define new names.
Your analysis is correct.
-- Gaby
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/15075] "using namespace" fails in part
2004-04-22 17:05 [Bug c++/15075] New: "using namespace" fails in part gcc-bugzilla at gcc dot gnu dot org
` (5 preceding siblings ...)
2004-04-23 3:38 ` giovannibajo at libero dot it
@ 2004-04-24 23:01 ` gdr at integrable-solutions dot net
6 siblings, 0 replies; 9+ messages in thread
From: gdr at integrable-solutions dot net @ 2004-04-24 23:01 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gdr at integrable-solutions dot net 2004-04-24 20:45 -------
Subject: Re: "using namespace" fails in part
"bangerth at dealii dot org" <gcc-bugzilla@gcc.gnu.org> writes:
| definition has to be in the global namespace -- the using directive only
| gets active once we _look up_ names, not when we declare/define new names.
Your analysis is correct.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15075
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2004-04-24 20:45 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-22 17:05 [Bug c++/15075] New: "using namespace" fails in part gcc-bugzilla at gcc dot gnu dot org
2004-04-22 17:12 ` [Bug c++/15075] " lnewberg at wadsworth dot org
2004-04-22 17:19 ` lnewberg at wadsworth dot org
2004-04-22 17:28 ` pinskia at gcc dot gnu dot org
2004-04-22 17:37 ` giovannibajo at libero dot it
2004-04-22 18:35 ` bangerth at dealii dot org
2004-04-24 22:53 ` Gabriel Dos Reis
2004-04-23 3:38 ` giovannibajo at libero dot it
2004-04-24 23:01 ` gdr at integrable-solutions dot net
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).