This is an archive of the discontinued LLVM Phabricator instance.

[Wdocumentation] Use C2x/C++14 deprecated attribute
ClosedPublic

Authored by Mordante on Dec 6 2019, 12:05 PM.

Details

Summary

This replaces the non-standard __attribute__((deprecated)) with the standard [[deprecated]] when compiling in C2x/C++14 mode.

Discovered while looking at https://bugs.llvm.org/show_bug.cgi?id=43753

Depends: D71140

Diff Detail

Event Timeline

Mordante created this revision.Dec 6 2019, 12:05 PM
aaron.ballman added inline comments.
clang/lib/AST/CommentSema.cpp
693

This attribute also exists with this spelling in C2x, FWIW.

Mordante marked an inline comment as done.Dec 6 2019, 12:25 PM
Mordante added inline comments.
clang/lib/AST/CommentSema.cpp
693

True, but unless I'm mistaken CPlusPlus17 and CPlusPlus2a also include CPlusPlus14. Do you prefer a different name for the Boolean?

aaron.ballman added inline comments.Dec 6 2019, 12:29 PM
clang/lib/AST/CommentSema.cpp
693

I'm talking about C2x, not C++2a. The name for the variable is fine, but we should prefer [[deprecated]] in C2x mode to __attribute__((deprecated)).

I think the correct predicate is: getLangOpts().DoubleSquareBracketAttributes -- if the user says they want to use double-square bracket attributes, we should probably prefer them to GNU-style attributes.

Mordante marked an inline comment as done.Dec 6 2019, 12:41 PM
Mordante added inline comments.
clang/lib/AST/CommentSema.cpp
693

Ah sorry I misread. I'll have a look at C2x. Thanks for the information.

Mordante marked 3 inline comments as done.Dec 7 2019, 4:08 AM
Mordante added inline comments.
clang/lib/AST/CommentSema.cpp
693

getLangOpts().DoubleSquareBracketAttributes will not work since it includes C++11, which doesn't support [[deprecated]], so I will just test for C++14 and C2x.
(I had a look at the proper syntax in C2x and found N2334 ;-))

Mordante updated this revision to Diff 232695.Dec 7 2019, 4:10 AM
Mordante retitled this revision from [Wdocumentation] Use C++14 deprecated attribute to [Wdocumentation] Use C2x/C++14 deprecated attribute.
Mordante edited the summary of this revision. (Show Details)

Added C2x support as requested.

aaron.ballman accepted this revision.Dec 7 2019, 6:24 AM

LGTM!

clang/lib/AST/CommentSema.cpp
693

getLangOpts().DoubleSquareBracketAttributes will not work since it includes C++11, which doesn't support [[deprecated]], so I will just test for C++14 and C2x.

We support [[deprecated]] in C++11 mode as an extension, but I suppose the concern there is pedantic warnings?

I think what you're doing now is fine, but it suggests that we need a better interface to clang::hasAttribute() so that you can test for support through the same machinery as __has_cpp_attribute/__has_c_attribute. It wouldn't be suitable to use here because you want to know something more specific than it can tell you (whether the attribute can be used without triggering an extension diagnostic), but this seems like a reasonable utility for us to have someday.

This revision is now accepted and ready to land.Dec 7 2019, 6:24 AM
Mordante marked an inline comment as done.Dec 8 2019, 6:34 AM

Thanks for the review! I'll wait with committing until @gribozavr2 had time to review this patch and D71140.

clang/lib/AST/CommentSema.cpp
693

My reason not to use [[deprecated]] in C++11 is standard compliance. The original bug reporter was using clang-tidy to improve the code. We don't know whether users of clang-tidy only use the clang compiler or also other compilers which don't offer [[deprecated]] as C++11 extension.

gribozavr2 accepted this revision.Dec 9 2019, 5:56 AM

LGTM with comments fixed.

clang/lib/AST/CommentSema.cpp
698

I know I'm nit-picking, but I'd appreciate periods at the end of sentences.

clang/test/Sema/warn-documentation-fixits.c
27

"[[ATTRIBUTE]]"?

I expected either "[[deprecated]]" or "ATTRIBUTE".

Oh, these are FileCheck's regex brackets, which make it just a literal "ATTRIBUTE"... I think it would be clearer without the brackets :)

clang/test/Sema/warn-documentation-fixits.cpp
130

s/[[ATTRIBUTE]]/ATTRIBUTE/ here as well.

Mordante marked 5 inline comments as done.Dec 9 2019, 12:35 PM

Thanks for your review of this set of patches!

clang/lib/AST/CommentSema.cpp
698

No problem, I added them.

clang/test/Sema/warn-documentation-fixits.c
27

These are not simple regex bracket, but they are substitution blocks [1]. These are defined by the RUN scrips to select between the __attribute__((deprecated)) and [[deprecated]] replacements.

[1] https://llvm.org/docs/CommandGuide/FileCheck.html#filecheck-string-substitution-blocks

gribozavr2 marked an inline comment as done.Dec 9 2019, 2:13 PM
gribozavr2 added inline comments.
clang/test/Sema/warn-documentation-fixits.c
27

Oh, it is FileCheck's -D flag... sorry I misread it. Please carry on.

This revision was automatically updated to reflect the committed changes.
Mordante marked 2 inline comments as done.