public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/7395: namespace qualification in friend causes later semantic failure
@ 2002-07-24 11:56 geb
  0 siblings, 0 replies; only message in thread
From: geb @ 2002-07-24 11:56 UTC (permalink / raw)
  To: gcc-gnats


>Number:         7395
>Category:       c++
>Synopsis:       namespace qualification in friend causes later semantic failure
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 24 11:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Gary Barnes
>Release:        3.0.1
>Organization:
>Environment:
System: Linux smbear.attbi.com 2.4.3-20mdk #1 Sun Apr 15 23:03:10 CEST 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure --prefix=/usr/local
>Description:
A template class is given a friend template class from a related but
different namespace.  This prevents recognition of that friend's name in
later contexts.  Removal of the namespace qualification from the friend
declaration eliminates the error, but the code is then illegal because the
named class is not directly visible.  But the code does then compile and I
can make progress.

>How-To-Repeat:
g++ -c foo.cc -g -MMD -frepo -ansi -pedantic -fshort-enums -W -Wall -Wundef \
-Wshadow -Wpointer_arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings \
-Wconversion -Wsign-compare -Wredundant-decls -Wunreachable-code -Wmissing-declarations \
-Winline -fmessage-length=99999 -Werror -DSHOW_ERROR
foo.cc:38: invalid use of undefined type `class One::Two::Three::One_Two_Three<Outer_t>'
foo.cc:5: forward declaration of `class One::Two::Three::One_Two_Three<Outer_t>'
foo.cc:38: template definition of non-template `void One::Two::Three::One_Two_Three<Outer_t>::In123(int)'
foo.cc:5: confused by earlier errors, bailing out

Remove -DSHOW_ERROR from the command line and the unit then compiles (and it
should not).  The error is related in some way to the namespace qualification
used in the friend declaration.

The contents of foo.cc are below.  The error goes away if the
"One::Two::Three::" qualification is removed.  The unit then compiles even
though it should not (One_Two_Three is not directly visible at that point).

If the "One::Two::Three::" is changed to "One::Two::" then the compiler
correctly states that there is no One::Two::One_Two_Three declared.

If the "One:Two:Three::" is changed to just "Three::" then the error again
manifests.

namespace One {
    namespace Two {
        namespace Three {
            template <class Outer_t>
            class One_Two_Three {
            public:
                One_Two_Three () : I (2) {};
                int I;
                void In123 (int _I);
            };
        }
    }
}

namespace One {
    namespace Two {
        template <class Some_t>
        class One_Two {
        public:
            One_Two () : J (1) {};
            int J;
            void In12 (int _J);
        private:
            int K;
            template <class Outer_t>
            friend class
#ifdef SHOW_ERROR
            One::Two::Three::
#endif
            One_Two_Three;
            typedef One::Two::Three::One_Two_Three <One_Two> Friend123;
            Friend123   Our_Friend;
        };
    }
}

template <class Outer_t>
void One::Two::Three::One_Two_Three <Outer_t>::In123 (int _I) {
    I = _I;
}

template <class Some_t>
void One::Two::One_Two <Some_t>::In12 (int _J) {
    J = _J;
}

int main (int, char**) {
    auto One::Two::One_Two <int>    X;
    X.In12 (3);
}

>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-07-24 18:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-24 11:56 c++/7395: namespace qualification in friend causes later semantic failure geb

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