-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add is_implicit_lifetime
trait (for Clang)
#5445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: TymianekPL <tymi@tymi.org>
This is a draft pr. |
Signed-off-by: TymianekPL <tymi@tymi.org>
Feel free to add more tests, this testing suite is definitely incomplete |
@microsoft-github-policy-service agree |
Right.. we use Clang 19.. yeah that PR is going to be opened for quite a while (until this repo gets upgraded to Clang 20) |
tests/std/tests/P2674R1_is_implicit_lifetime/test.compile.pass.cpp
Outdated
Show resolved
Hide resolved
static_assert(!std::is_implcit_lifetime_v<const volatile void>); | ||
static_assert(!std::is_implcit_lifetime_v<long&>); | ||
static_assert(!std::is_implcit_lifetime_v<long&&>); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should test classes and array of classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, but I know I need more tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also fix that typo, 'implcit' isn't a word
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm uhh right right, how did I not see that heh
This will be unblocked when VS updates to Clang 20 (which I would expect in an 18.0 Preview but don't know when it will happen). In your PR description, can you add the magic words "Fixes #3445." to properly link your PR to our tracking issue? |
@StephanTLavavej any chance MSVC can add an intrinsic for this in 18.0? |
Signed-off-by: TymianekPL <tymi@tymi.org>
Signed-off-by: TymianekPL <tymi@tymi.org>
Signed-off-by: TymianekPL <tymi@tymi.org>
Signed-off-by: TymianekPL <tymi@tymi.org>
static_assert(!is_implcit_lifetime_v<IncompleteClass[]>); | ||
static_assert(!is_implcit_lifetime_v<IncompleteClass[20]>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All array types are implicit-lifetime types (ditto below). Also, typo and clang-format.
static_assert(!is_implcit_lifetime_v<IncompleteClass[]>); | |
static_assert(!is_implcit_lifetime_v<IncompleteClass[20]>); | |
static_assert(is_implicit_lifetime_v<IncompleteClass[]>); | |
static_assert(is_implicit_lifetime_v<IncompleteClass[20]>); |
|
||
using namespace std; | ||
|
||
int main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we conventionally don't define the main
function in a *.compile.pass.cpp
, indicating that no run-time test is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do I name it though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case I don't even think we need to write a function. It's possibly simpler to just place these static_assert
s in the global namespace scope.
class Class {}; | ||
class IncompleteClass; | ||
class UserProvidedDestructorClass | ||
{ | ||
~UserProvidedDestructorClass() {} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it's better to change Class
and UserProvidedDestructorClass
to TrivialClass
and AggregateClassWithUserProvidedDestructor
. Also it seems clearer to use struct
as the class-key.
#endif | ||
} | ||
|
||
class IncompleteClass {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to define the class.
class IncompleteClass {}; |
// is_implicit_lifetime_v produces desired results | ||
// compiles under std namespace | ||
|
||
// Basics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's perhaps better to test is_implicit_lifetime
(the class template) in some way.
class Class {}; | ||
class IncompleteClass; | ||
class UserProvidedDestructorClass | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format
Clang has added the
std::is_implicit_lifetime
trait in LLVM20, and this is an implementation for MSVC STL for Clang. Since MSVC core compiler does not support the builtin yet, I will not include the MSVC version in this PR (unless something changes throughout the lifetime of this PR).Changes:
std::is_implicit_lifetime
trait (andstd::is_implicit_lifetime_v
).[Fixes #3445]