Skip to content

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

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

TymianekPL
Copy link

@TymianekPL TymianekPL commented Apr 27, 2025

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:

  • Added the C++23 std::is_implicit_lifetime trait (and std::is_implicit_lifetime_v).

[Fixes #3445]

Signed-off-by: TymianekPL <tymi@tymi.org>
@TymianekPL TymianekPL requested a review from a team as a code owner April 27, 2025 15:55
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Apr 27, 2025
@TymianekPL
Copy link
Author

This is a draft pr.

@TymianekPL TymianekPL marked this pull request as draft April 27, 2025 16:56
Signed-off-by: TymianekPL <tymi@tymi.org>
Signed-off-by: TymianekPL <tymi@tymi.org>
@TymianekPL
Copy link
Author

Feel free to add more tests, this testing suite is definitely incomplete

@TymianekPL
Copy link
Author

@microsoft-github-policy-service agree

@TymianekPL
Copy link
Author

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)

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
Copy link
Contributor

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.

Copy link
Author

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

Copy link
Contributor

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

Copy link
Author

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

@github-project-automation github-project-automation bot moved this from Initial Review to Work In Progress in STL Code Reviews Apr 28, 2025
@StephanTLavavej StephanTLavavej added blocked Something is preventing work on this compiler Compiler work involved cxx23 C++23 feature labels Apr 28, 2025
@StephanTLavavej StephanTLavavej moved this from Work In Progress to Blocked in STL Code Reviews Apr 28, 2025
@StephanTLavavej
Copy link
Member

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?

@TymianekPL
Copy link
Author

@StephanTLavavej any chance MSVC can add an intrinsic for this in 18.0?

TymianekPL added 4 commits May 1, 2025 16:40
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>
Comment on lines +33 to +34
static_assert(!is_implcit_lifetime_v<IncompleteClass[]>);
static_assert(!is_implcit_lifetime_v<IncompleteClass[20]>);
Copy link
Contributor

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.

Suggested change
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()
Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Contributor

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_asserts in the global namespace scope.

Comment on lines +8 to +13
class Class {};
class IncompleteClass;
class UserProvidedDestructorClass
{
~UserProvidedDestructorClass() {}
};
Copy link
Contributor

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 {};
Copy link
Contributor

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.

Suggested change
class IncompleteClass {};

// is_implicit_lifetime_v produces desired results
// compiles under std namespace

// Basics
Copy link
Contributor

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.

@github-project-automation github-project-automation bot moved this from Blocked to Work In Progress in STL Code Reviews May 8, 2025
class Class {};
class IncompleteClass;
class UserProvidedDestructorClass
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format

@StephanTLavavej StephanTLavavej moved this from Work In Progress to Blocked in STL Code Reviews May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Something is preventing work on this compiler Compiler work involved cxx23 C++23 feature
Projects
Status: Blocked
Development

Successfully merging this pull request may close these issues.

P2674R1 is_implicit_lifetime
6 participants