Late parsing of CXX11 attributes

Hello everyone,

AFAIK, GNU attributes can be late parsed within a class (see ParseDecl.cpp, Parser::ParseGNUAttributes), but late parsing of CXX11 attributes is not yet implemented.

Is there any plans to do it or anyone already working on it? Anyway, if no one is owning that issue, I could work on it.

Thanks,

I’m not aware of anyone working on this (CC’d Aaron, who might know if someone is). Patches would be very much welcome :slight_smile:

Also relevant is http://wg21.link/p0542r5 (voted into the current C++ working draft a couple of weeks ago), which requires late parsing for C++11 attributes within a class.

OK, unless Aaron replies that someone is currently implementing this, I will be working on a patch.

I know :slight_smile: I have been working for months in the implementation of P0542 in Clang. Late parsing is one of the missing features.

Wooh! Thanks for working on this.

Clang’s diagnose_if attribute would certainly benefit from this change. Currently it’s usable only
as a GCC attribute.

I tried working on this a while back. IIRC the main issue is that C++11 attributes placed at the end of
a function declaration apply to the function type and not the declaration itself. (See [dcl.spec]p1).

After discussing this with Richard and Aaron about attributes appearing after a function-specifier, I believe the
consensus was to only apply the attribute to the type if said attribute is a “type attribute”. Otherwise the
attribute would apply to the entity being declared. For example, I think we should accept int foo() [[noreturn]];

/Eric

Hi Eric, I wrote a workaround for that issue a few months ago (as part of the implementation of P0542R5, now included in the current C++ working draft). These attributes are manually moved to the attribute list of the declarator. To illustrate this, a patch is included in this mail.

— a/tools/clang/lib/Sema/SemaType.cpp
+++ b/tools/clang/lib/Sema/SemaType.cpp
@@ -7039,6 +7039,14 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
<< attr.getName();
break;

  • // These attributes appertain to the declarator, although they occur
  • // void identifier(void) [[here]];
  • case AttributeList::AT_Expects:
  • case AttributeList::AT_Ensures:
  • moveAttrFromListToList(attr, state.getCurrentAttrListRef(),
  • state.getDeclarator().getAttrListRef());
  • break;

OK, unless Aaron replies that someone is currently implementing this, I will
be working on a patch.

I am unaware of existing work in this area. Thank you for volunteering
to work on it! I'm happy to review any patches you create.

I know :slight_smile: I have been working for months in the implementation of P0542 in
Clang. Late parsing is one of the missing features.

Fantastic!!

~Aaron

Wooh! Thanks for working on this.

Clang's `diagnose_if` attribute would certainly benefit from this change.
Currently it's usable only
as a GCC attribute.

I tried working on this a while back. IIRC the main issue is that C++11
attributes placed at the end of
a function declaration apply to the function type and not the declaration
itself. (See [dcl.spec]p1).

After discussing this with Richard and Aaron about attributes appearing
after a function-specifier, I believe the
consensus was to only apply the attribute to the type if said attribute is a
"type attribute". Otherwise the
attribute would apply to the entity being declared. For example, I think we
should accept `int foo() [[noreturn]];`

It's been a while, but I thought we were exploring making diagnose_if
(and friends) into actual type attributes because they seem to be
type-ish. For instance, if the API designer says "please diagnose if
this argument is bad", they likely expect that to happen when calling
the function directly or indirectly through a function pointer.

~Aaron