This is an archive of the discontinued LLVM Phabricator instance.

[clang] adds `__is_scoped_enum`, `__is_nullptr`, and `__is_referenceable`
ClosedPublic

Authored by cjdb on Oct 4 2022, 9:48 AM.

Details

Summary

... as builtins.

This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

This was originally a part of D116280.

Depends on D135175.

Diff Detail

Event Timeline

cjdb created this revision.Oct 4 2022, 9:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 4 2022, 9:48 AM
cjdb requested review of this revision.Oct 4 2022, 9:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 4 2022, 9:48 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cjdb updated this revision to Diff 465273.Oct 4 2022, 9:37 PM

Replaces T/F with static_assert to match D116203

cjdb updated this revision to Diff 465277.Oct 4 2022, 9:41 PM
cjdb edited the summary of this revision. (Show Details)

Updates the commit message so patch applications work

cjdb added a reviewer: Restricted Project.Oct 4 2022, 10:35 PM
erichkeane accepted this revision.Oct 6 2022, 6:19 AM
erichkeane added a subscriber: Restricted Project.
erichkeane added a subscriber: erichkeane.

LGTM... Please do the re-ordering separately here, unless it was necessary here.

clang/lib/Parse/ParseExpr.cpp
1071

Can you just put this in the right place in the other commit?

1079

Why are the rest of these re-ordered? Feel free to do an NFC re-ordering these, but please dont do them here.

This revision is now accepted and ready to land.Oct 6 2022, 6:20 AM
aaron.ballman added inline comments.Oct 7 2022, 11:38 AM
clang/test/SemaCXX/type-traits.cpp
405

It'd probably not be a bad idea at some point to add test coverage for incomplete types.

830

I think we should have test cases for the following:

struct incomplete;

__is_referenceable(struct incomplete); // Also interesting to make sure we handle elaborated type specifiers properly

typedef void function_type(int);
__is_referenceable(function_type); // Note, this is not a function *pointer* type

struct S {
  void func1() &;
  void func2() const;
};

// Both of these should be false, by my understanding of what "referenceable" means in the standard.
__is_referenceable(decltype(&S::func1));
__is_referenceable(decltype(&S::func2));
aaron.ballman accepted this revision.Oct 7 2022, 11:41 AM

Assuming the additional test cases don't uncover any surprises, this LGTM as well (modulo nits already brought up).

Mordante added inline comments.
clang/include/clang/Basic/TokenKinds.def
525

Shouldn't these traits be documented or is the documentation generated automatically from the def files?

cjdb updated this revision to Diff 466315.Oct 8 2022, 4:45 PM
cjdb marked 5 inline comments as done.

applies feedback, rebases, adds documentation

aaron.ballman added inline comments.Oct 10 2022, 6:06 AM
clang/test/SemaCXX/type-traits.cpp
830

Do you have a test for:

struct S {
  void func1() &;
  void func2() const;
};

// Both of these should be false, by my understanding of what "referenceable" means in the standard.
__is_referenceable(decltype(&S::func1));
__is_referenceable(decltype(&S::func2));
cjdb added inline comments.Oct 10 2022, 9:54 AM
clang/lib/Parse/ParseExpr.cpp
1071

Yeah, this feels like a commit split issue. Thanks for catching.

clang/test/SemaCXX/type-traits.cpp
405

I've added that coverage for __is_enum above too.

830

I think the latter two are pointer-to-member functions, which are referenceable. We want to check void(int) const, which is done on the last green line of this file.

aaron.ballman accepted this revision.Oct 10 2022, 10:27 AM

LGTM

clang/test/SemaCXX/type-traits.cpp
830

Ah thank you for showing me we already had the coverage!

This revision was landed with ongoing or failed builds.Oct 10 2022, 5:39 PM
This revision was automatically updated to reflect the committed changes.