This is an archive of the discontinued LLVM Phabricator instance.

[clang] Document extensions from later standards
ClosedPublic

Authored by philnik on May 10 2023, 3:40 PM.

Diff Detail

Event Timeline

philnik created this revision.May 10 2023, 3:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2023, 3:40 PM
philnik requested review of this revision.May 10 2023, 3:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2023, 3:40 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Thank you for working on this! Just a few questions, but in general, this is looking good.

clang/docs/LanguageExtensions.rst
1386

This brings up a few questions for me: how should we handle C? For example, designated initializers also exist in C99 and are backported to C89? And how should we handle C features extended into C++ (or vice versa)?

Should we have multiple tables? Should we try to put both languages into one table with different columns?

(I'm not asking you to sign up to figure out the C extensions, just trying to get an idea for whether we want to change the layout of this table to account for that sort of thing.)

1387

What are your thoughts on extensions enabled by a feature flag? e.g., https://godbolt.org/z/ex9K5dzv6

H-G-Hristov added inline comments.
clang/docs/LanguageExtensions.rst
1398
philnik added inline comments.May 11 2023, 8:06 AM
clang/docs/LanguageExtensions.rst
1386

I think it would make sense to put C features that are back-ported into previous standards also into this table (are there FTMs for C?). C into C++ or vice versa should probably live somewhere else, since in these cases it would also be interesting how things interact with other language features. Maybe this is not as much of a problem for C++->C(?), but definitely for C->C++. e.g. __restrict on member functions or VLAs with non-trivial classes. Essentially, there is a lot more to say than "this also exists in previous standards".

1387

I actually had no idea they existed (might be worth documenting :P)! Specifically for this case: Is there any reason this is behind a feature flag? I guess it's a non-conforming extension? If not, I'd say just make it an enabled-by-default extension (it would be a really nice cleanup opportunity for libc++). Anyways, we could add another column "flags required" for these cases. Do you know how many of these kinds of flags there are?

aaron.ballman added inline comments.May 11 2023, 8:53 AM
clang/docs/LanguageExtensions.rst
1386

I think it would make sense to put C features that are back-ported into previous standards also into this table (are there FTMs for C?).

Okay, I think that makes sense to me. Clang has feature test macros for some C functionality (e.g., c_generic_selections, more full list at: https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/Features.def#L241)

C into C++ or vice versa should probably live somewhere else, since in these cases it would also be interesting how things interact with other language features.

Sold!

1387

I actually had no idea they existed (might be worth documenting :P)!

Right? https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fdouble-square-bracket-attributes exists but is hardly ideal.

Specifically for this case: Is there any reason this is behind a feature flag? I guess it's a non-conforming extension? If not, I'd say just make it an enabled-by-default extension (it would be a really nice cleanup opportunity for libc++).

It's a bit of an odd situation. I added the feature flag because I wanted to expose this functionality in C before WG14 adopted the functionality and it wasn't entirely clear whether I would run into ambiguities with Objective-C's message sending syntax. C++ has this language rule: http://eel.is/c++draft/dcl.dcl#dcl.attr.grammar-7 but Objective-C allows for things like [[foo bar] baz];. We had already solved this for C++, but it wasn't entirely clear whether we'd hit other situations in older language modes or different situations.

These days, it may be possible we could enable this extension by default in all language modes.

Anyways, we could add another column "flags required" for these cases. Do you know how many of these kinds of flags there are?

I can't think of many... Features.def lists the language options required for various features and extensions, and it doesn't look like many have specific flags, though there are some that needs a more general flag like -fms-extensions. We do have things like -fno-rtti disabling RTTI, but I don't think we want to list that sort of thing here.

philnik updated this revision to Diff 521375.May 11 2023, 11:11 AM
philnik marked 5 inline comments as done.

Address comments

aaron.ballman accepted this revision.May 11 2023, 11:47 AM

LGTM, this is awesome -- thank you for the improved docs!

clang/docs/LanguageExtensions.rst
1373

Seems to be the style we're using for this level of heading.

This revision is now accepted and ready to land.May 11 2023, 11:47 AM
This revision was landed with ongoing or failed builds.May 11 2023, 11:55 AM
This revision was automatically updated to reflect the committed changes.
philnik marked an inline comment as done.