From: corey taylor <corey.taylor@gmail.com>
To: Jakub Pawlewicz <jakub.pawlewicz@gmail.com>
Cc: MSX to GCC <gcc-help@gcc.gnu.org>
Subject: Re: Two-stage name lookup problem
Date: Wed, 26 Oct 2005 16:20:00 -0000 [thread overview]
Message-ID: <2e393d080510260919r513fcb09jc5cc034fa55702a8@mail.gmail.com> (raw)
In-Reply-To: <33b23e0c0510260856i37cc5aa1p@mail.gmail.com>
Jakub,
I understand your dilemna. The best thing I can do for you right
now is to show the C++ specification paragraph that rules in the
compiler are generated from:
Knowing which names are type names allows the syntax of every template
definition to be checked. No
diagnostic shall be issued for a template definition for which a valid
specialization can be generated. If no
valid specialization can be generated for a template definition, and
that template is not instantiated, the template
definition is ill-formed, no diagnostic required. If a type used in a
non-dependent name is incomplete
at the point at which a template is defined but is complete at the
point at which an instantiation is done, and
if the completeness of that type affects whether or not the program is
well-formed or affects the semantics
of the program, the program is ill-formed; no diagnostic is required.
[Note: if a template is instantiated,
errors will be diagnosed according to the other rules in this
Standard. Exactly when these errors are diagnosed
is a quality of implementation issue. ] [Example:
int j;
template<class T> class X {
// ...
void f(T t, int i, char* p)
{
t = i; // diagnosed if X::f is instantiated
// and the assignment to t is an error
p = i; // may be diagnosed even if X::f is
// not instantiated
p = j; // may be diagnosed even if X::f is
// not instantiated
}
void g(T t) {
+; //may be diagnosed even if X::g is
// not instantiated
}
};
—end example]
corey
On 10/26/05, Jakub Pawlewicz <jakub.pawlewicz@gmail.com> wrote:
> I'm confused. I do not want use any pointers and memory allocation. I
> wrote a program which is very fast because I was using many inline
> templates and no pointers. The program worked find unless I had to
> switch to gcc 3.4. In my first post it is important that there are
> templates and that I am using non-pointer variable declaration of type
> B in function A::f(). Please go back to the original problem.
>
> I don't know template terminology, but I try my best to describe what
> the problem is. So please be gentle if I make something wrong.
>
> The declaration of A a; in struct B should be allowed if we are able
> to postpone instantiation of struct B, because it is a template
> struct. The function A::f() is template also, so maybe we could better
> postpone the instantiation of the function body. I don't know how can
> I do such things. Before two-stage names lookup there was no problem
> with such hacks and now I need a workaround..
>
> 2005/10/26, corey taylor <corey.taylor@gmail.com>:
> > Jakub,
> >
> > The declaration of A a; in struct B because it requires an object
> > size. Using a pointer to an incomplete type is allowed. You could
> > create a new A in the B constructor and assign it to a pointer.
> >
> > The other errors center around this. The question about using B b
> > has nothing to do with the error above.
> >
> > Corey
> >
> > On 10/26/05, Jakub Pawlewicz <jakub.pawlewicz@gmail.com> wrote:
> > > > Your problem is not with templates.
> > > >
> > > > Here's your problem in a nutshell...
> > > >
> > > > struct A
> > > > {
> > > > int x;
> > > >
> > > > struct B
> > > > {
> > > > A a;
> > > > };
> > > > };
> > > >
> > > >
> > > > You cannot use A within B, because at that point A is incomplete.
> > > >
> > > > You can pull B out of A. If you want B to be in the A namespace, change
> > > > 'struct A' to 'namespace A', and make 'struct A_impl', fully declared, and
> > > > then use that within 'struct B'.
> > >
> > > But what about function f(), the member of struct A? I want to declare
> > > variable with type B in the body of the function:
> > >
> > > struct A {
> > > ...
> > > void f()
> > > {
> > > B b;
> > > ...
> > > }
> > > };
> > >
> > > I am aware that kind of code may be ill formed, but when using
> > > templates, there should be something like deferred instantiation.
> > > Struct B is a template and also function A::f() is a template. Struct
> > > B is needed only when function A::f() is used. Struct B should be able
> > > to construct member of type A and Struct B do not use function A::f().
> > > I want all functions be inline. Any solutions?
> > >
> >
>
next prev parent reply other threads:[~2005-10-26 16:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-26 7:18 Jakub Pawlewicz
2005-10-26 12:47 ` John Love-Jensen
2005-10-26 14:07 ` Jakub Pawlewicz
2005-10-26 14:43 ` corey taylor
2005-10-26 15:56 ` Jakub Pawlewicz
2005-10-26 16:20 ` corey taylor [this message]
2005-11-05 19:35 ` Nathan Sidwell
2005-10-27 12:22 ` Jakub Pawlewicz
2005-10-26 13:57 Brian T. Brunner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2e393d080510260919r513fcb09jc5cc034fa55702a8@mail.gmail.com \
--to=corey.taylor@gmail.com \
--cc=gcc-help@gcc.gnu.org \
--cc=jakub.pawlewicz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).