Multiple attribute specifiers

Chris Nicholson-Sauls ibisbasenji at gmail.com
Wed Sep 6 11:53:05 PDT 2006


Comments imbeded.

Ary Manzana wrote:
> If I write this inside a module:
> 
> --------------------------------------
> public private int x;
> --------------------------------------
> 
> it compiles perfectly.

Okay this is odd, indeed.  I would expect an error from contradictory attributes applied 
directly to a single decleration.  I consider this a bug, personally.

> 
> What is the protection level of x? public or private? Well, you can try 
> compiling it and using it to find out, but I think the compiler should 
> issue a warning or, much better, an error.
> 
> This confusion also appears if I write
> 
> --------------------------------------
> public {
> 
>     private {
> 
>         int x;
> 
>     }
> 
> }
> --------------------------------------
> 
> Again, the same question. Is x public or private?

In this case I would actually expect x to be private.  With nested attribute blocks, my 
assumption is that the inner-most attributes take precedance.  There may be corner-case 
uses for this behavior... perhaps in a property definition, a la:

# class Foo {
#   public {
#     ... ...
#     int bar () { ... }
#     int bar (int x) { ... }
#     private int _bar ;
#     ... ...
#   }
#   ... ...
# }

Still seems needless, but I guess it ought to be allowed, but only in terms of attribute 
blocks.  Definitely not in the first case.

> I was going to post this to the digitalmars.D.bugs list, but I want some 
> comments on this before proceeding.
> 
> I know no one would want to write such a thing, but on the compiler side 
> (or other tools) it is crucial to know what should be the semantic 
> (because currently it's legal).
> 
> Thanks,
> Ary

-- Chris Nicholson-Sauls



More information about the Digitalmars-d-learn mailing list