Topic: Multiple declarations in block scope


Author: Hideaki Onaru <gomarine@mx1.ttcn.ne.jp>
Date: 2000/03/03
Raw View
>From 7.3.3 "The using declaration" of Draft (Dec, 1996):

"A using-declaration is a declaration and can therefore be used repeatedly
where (and only where) multiple declarations are allowed. [Example:

    namespace A {
        int i;
    }
    namespace A1 {
        using A::i;
        using A::i; // ok: double declaration
    }
    void f()
    {
        using A::i;
        using A::i; // error: double declaration
    }

    class B {
    public:
        int i;
    };
    class X : public B {
        using B::i;
        using B::i; // error: double member declaration
    };

_(IQ_(Bend example]"

The example (of f()) implies that the code below is also an error:

int i;
void f()
{
    extern int i;
    extern int i;
}

My question is:
Where is the clause which prohibits multiple declarations in a block scope?

(In 6.7 "Declaration statement", the Draft says:
"A declaration statement introduces one or more new identifiers into a block; (...)"
Does this single word "new" forbid multiple declarations?)

Hideaki Onaru

---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 2000/03/04
Raw View
Hideaki Onaru <gomarine@mx1.ttcn.ne.jp> writes:

> The example (of f()) implies that the code below is also an error:
>
> int i;
> void f()
> {
>     extern int i;
>     extern int i;
> }
>
> My question is:
> Where is the clause which prohibits multiple declarations in a block scope?

It is the other way 'round: Since the redeclaration in block scope is
ok, the repeated using-declaration should be also ok. This is subject
of Core Issue 36
(http://www.informatik.hu-berlin.de/~loewis/corer8.html#36), the
proposed resolution is to change the example in 7.3.3.

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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Hideaki Onaru <gomarine@mx1.ttcn.ne.jp>
Date: 2000/03/04
Raw View
Martin von Loewis wrote:
>
> Hideaki Onaru <gomarine@mx1.ttcn.ne.jp> writes:
>
> > The example (of f()) implies that the code below is also an error:
> >
> > int i;
> > void f()
> > {
> >     extern int i;
> >     extern int i;
> > }
> >
> > My question is:
> > Where is the clause which prohibits multiple declarations in a block scope?
>
> It is the other way 'round: Since the redeclaration in block scope is
> ok, the repeated using-declaration should be also ok. This is subject
> of Core Issue 36
> (http://www.informatik.hu-berlin.de/~loewis/corer8.html#36), the
> proposed resolution is to change the example in 7.3.3.
Thank you!
This has troubled me for weeks...

Hideaki Onaru

---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: David R Tribble <david@tribble.com>
Date: 2000/03/07
Raw View
Hideaki Onaru wrote:
> "A using-declaration is a declaration and can therefore be used
> repeatedly where (and only where) multiple declarations are allowed.
> [Example:
...
>     void f()
>     {
>         using A::i;
>         using A::i; // error: double declaration
>     }
...
>
> The example of f() implies that the code below is also an error:
>
>    int i;
>    void f()
>    {
>        extern int i;
>        extern int i;
>    }
>
> My question is:
> Where is the clause which prohibits multiple declarations in a block
> scope?

Multiple declarations of extern identifiers is allowed anywhere.
The second declaration above is benign (and simply redundant).

I'm not sure of the reasoning behind limiting 'using' declarations
to one per block, though.  Perhaps the second 'using' makes the
identifier ambiguous (even though it's the same identifier)?

-- David R. Tribble, david@tribble.com, http://david.tribble.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://reality.sgi.com/austern_mti/std-c++/faq.html              ]