[cfe-dev] Storage class as written in the source.

Douglas Gregor dgregor at apple.com
Sat Apr 17 07:55:14 PDT 2010


On Apr 16, 2010, at 11:48 PM, Enea Zaffanella wrote:

> Douglas Gregor wrote:
>> Hi Enea,
>> 
>> On Apr 16, 2010, at 12:27 PM, Enea Zaffanella wrote:
>>> Some time ago, Paolo Bolzoni sent to the mailing list a patch meant to enhance VarDecl and FunctionDecl nodes so that they can record the storage class "as written" in the source code (in contrast with the semantic storage class, which could be inherited).
>>> 
>>> This was the message:
>>> http://lists.cs.uiuc.edu/pipermail/cfe-dev/2010-February/007982.html
>>> 
>>> The patch was not applied and now is out-of-date.
>>> 
>>> I have just refreshed it to be a patch against a recent version (r101446, see attached file). It passes all of the clang tests.
>>> 
>>> It would be nice if someone could have a look on and possibly commit it.
>> Looks very good. I have a few comments that I'd like to see addressed before I commit.
> 
> Thank you for the very quick reply.
> 
> [...]
> 
>> Constructors, destructors, and conversions don't have storage classes in well-formed code, so we shouldn't make the storage-class specifier part of the constructors for the corresponding AST nodes. Just pass FunctionDecl::None down to the CXXMethodDecl constructor in the appropriate place.
> 
> Paolo in his message observed that out-of-line definitions of constructors, destructors and conversions can have "extern" as a storage class. The following compiles cleanly on g++:
> 
> struct S {
>  S();
>  ~S();
>  operator bool();
> };
> 
> extern S::S() {}
> extern S::~S() {}
> extern S::operator bool() { return true; }

GCC allows it (but it doesn't have any effect on translation), while EDG rejects it. C++ [class.mem]p5 explicitly calls this ill-formed:

	A member shall not be declared with the extern or register storage-class-specifier.

We should have an Extension/ExtWarn diagnostic about the storage-class-specifier being redundant and then just drop the storage-class-specifier.

> Hence, will it be OK if we leave the extra argument in the constructors of the AST nodes above?

I don't think we should model it in the AST because (1) it's not in the language and (2) it has no effect in GCC. Do you disagree?

	- Doug



More information about the cfe-dev mailing list