D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3118 - Need a clear spec on how inapplicable attributes are handled
Summary: Need a clear spec on how inapplicable attributes are handled
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: All All
: P2 normal
Assignee: No Owner
URL: http://www.digitalmars.com/d/archives...
Keywords: spec
Depends on: 3183
Blocks: 677 3934
  Show dependency treegraph
 
Reported: 2009-06-30 14:26 UTC by Stewart Gordon
Modified: 2014-04-18 09:12 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Stewart Gordon 2009-06-30 14:26:22 UTC
If one tries to apply an argument to an entity to which it is not applicable, how is the compiler supposed to deal with the attempt?  There has been considerable debate about it both here on Bugzilla and on the newsgroups, and the anomalies have been widely observed.

The compiler, under certain conditions, silently ignores such inapplicable attributes.  It isn't clear what these conditions are, and there are some conditions under which it should certainly not be happening.

There are three kinds of inapplicability to consider:
(a) attribute's meaning already implied by the context
(b) doesn't make sense in the context
(c) makes sense in the context but is nonetheless not actually applied.

Issue 1441 (later resurfaced as issue 2830) is a prime example of (c).  That any cases of (c) actually exist is bad in itself.

We need a clear spec on the whole issue.  It should consider not only the three kinds of inapplicability, but also the possible ways of specifying an attribute:
(i) directly to the declaration
(ii) using { }
(iii) using :
(iv) inherited by the members of a compound type, in the case of one or two attributes

AISI the most lenient policy that is reasonable is:
- allow (a) always
- allow (b) except when applied by (i)
- eradicate all cases of (c) by fixing the affected attributes to work

Whatever we do, both the spec and the compiler will need to be amended.

Further discussion at URL given.
Comment 1 Walter Bright 2010-11-09 23:41:33 UTC
i, ii, and iii are equivalent as documented. I think that should remain, as it would be very confusing to make them behave differently. Not sure what you mean by iv.

Other problems with inappropriate attributes should be handled on a case by case basis. I don't think a general policy will work.

Therefore, I'll mark this as wontfix, with the supposition that the various cases should each have their one bugzilla entry.
Comment 2 Stewart Gordon 2010-11-10 04:35:28 UTC
(In reply to comment #1)
> i, ii, and iii are equivalent as documented. I think that should remain, as it
> would be very confusing to make them behave differently.

Not sure what you mean by this.

> Not sure what you mean by iv.

I figured that there might be cases (such as align) where applying the attribute to a class, struct, etc. applies it to each of its members.
Comment 3 Walter Bright 2010-11-10 11:16:26 UTC
attribute int a;
attribute: int a;
attribute { int a; }

should all have the same meaning for a.
Comment 4 Stewart Gordon 2011-02-22 16:11:49 UTC
(In reply to comment #3)
> attribute int a;
> attribute: int a;
> attribute { int a; }
> 
> should all have the same meaning for a.

This whole debate is about legality, not meaning.  Defining that they always all have the same legality erodes the usefulness of the colon notation especially, since one could try to use it and then be forced to move a declaration to which it doesn't make sense to above the attribute, which can get annoying if you want to place declarations in some intuitive or logical order.