-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
4252d7d
Add is_implicit_lifetime trait for Clang
TymianekPL 28f5f81
Add test
TymianekPL 58464a7
Add feature-test macro
TymianekPL b5b56f7
move the macro, remove redundant inline keyword
TymianekPL 2162504
Update yvals_core.h
TymianekPL 824c116
Add using namespace std and remove VLA test from the P2674 test suite
TymianekPL 9bd93c2
Update type_traits
TymianekPL 613f407
Update yvals_core.h
TymianekPL 747f4e8
More test passes
TymianekPL f2fd537
Remove explicit std resolution path
TymianekPL a7ff2f9
Add feature-test test
TymianekPL 72d311e
Move implementation comment for P2674R1 in yvals_core.h
TymianekPL 003fe2b
Merge branch 'microsoft:main' into main
TymianekPL 51f5433
[is_implicit_lifetime/test] Fix typos, remove main, rename classes, f…
TymianekPL 011f349
small typo on the test_implicit_lifetime entity
TymianekPL 6b51bf8
format
TymianekPL b063780
remove weird whitespace from yvals core
TymianekPL dbd9381
clang-format (test/P2674)
TymianekPL 95d7688
clang-format in VSO_0157762_feature_test_macros
TymianekPL 38db02e
remove new-lines from VSO_0157752
TymianekPL 7814e55
remove new-lines from P2674R1_is_implicit_lifetime
TymianekPL 27a43ca
missing )
TymianekPL 685978e
remove whitespace (why is it being added??)
TymianekPL b2190d2
Add the missing exclamation mark near fp is_implicit_lifetime test
TymianekPL 2618826
new-lines. again?!
TymianekPL 3b93665
fix the test P2674R1_is_implicit_lifetime
TymianekPL f4465f6
Merge branch 'main' into gh5445
StephanTLavavej 608cb3b
Clean up paper title.
StephanTLavavej 8d522a2
Sort feature-test macro, cite followup issues for MSVC and EDG.
StephanTLavavej 8b7d0ea
Sort feature-test macro test, cite followup issues for MSVC and EDG.
StephanTLavavej 0470bad
Add new test to test.lst.
StephanTLavavej 507a971
This is a C++23 feature, not C++20.
StephanTLavavej 5b87a91
Apply no_specializations attributes, follow Standard order, add/fix c…
StephanTLavavej e82c354
Test review, part 1: Minor nitpicks.
StephanTLavavej 8e7f749
Test review, part 2: Consistently test cv-qualifiers.
StephanTLavavej a8a20cb
Test review, part 3: More scalars, more unbounded arrays, more refere…
StephanTLavavej 8212b8a
Test review, part 4: Expand test coverage of class types, finding a C…
StephanTLavavej 379791e
Update libcxx/expected_results.txt.
StephanTLavavej 6092e93
Make non-aggregates noncopyable to avoid interference from copy ctors.
StephanTLavavej bd0d861
Cite LLVM-160627.
StephanTLavavej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
RUNALL_INCLUDE ..\usual_latest_matrix.lst |
180 changes: 180 additions & 0 deletions
180
tests/std/tests/P2674R1_is_implicit_lifetime/test.compile.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <cstddef> | ||
#include <string> | ||
#include <type_traits> | ||
using namespace std; | ||
|
||
TymianekPL marked this conversation as resolved.
Show resolved
Hide resolved
|
||
enum UnscopedEnum { Enumerator }; | ||
enum class ScopedEnum { Enumerator2 }; | ||
class IncompleteClass; | ||
struct TrivialClass {}; | ||
struct DefaultedDestructorClass { | ||
~DefaultedDestructorClass() = default; | ||
}; | ||
struct DeletedDestructorClass { | ||
~DeletedDestructorClass() = delete; | ||
}; | ||
struct UserProvidedDestructorClass { | ||
~UserProvidedDestructorClass() {} | ||
}; | ||
struct StringAggregateWithImplicitlyDeclaredDestructor { | ||
string juliette_andromeda_meow; | ||
string clarissa_melpomene_meow; | ||
}; | ||
struct StringAggregateWithUserProvidedDestructor { | ||
string chaos_engine_one; | ||
string chaos_engine_two; | ||
~StringAggregateWithUserProvidedDestructor() {} | ||
}; | ||
|
||
class NonAggregateWithTrivialCtorAndTrivialDtor { | ||
public: | ||
NonAggregateWithTrivialCtorAndTrivialDtor() = default; | ||
~NonAggregateWithTrivialCtorAndTrivialDtor() = default; | ||
|
||
NonAggregateWithTrivialCtorAndTrivialDtor(const NonAggregateWithTrivialCtorAndTrivialDtor&) = delete; | ||
NonAggregateWithTrivialCtorAndTrivialDtor& operator=(const NonAggregateWithTrivialCtorAndTrivialDtor&) = delete; | ||
|
||
void set_num(int x) { | ||
num = x; | ||
} | ||
int get_num() const { | ||
return num; | ||
} | ||
|
||
private: | ||
int num; | ||
}; | ||
|
||
class NonAggregateWithNonTrivialCtor { | ||
public: | ||
NonAggregateWithNonTrivialCtor() = default; | ||
~NonAggregateWithNonTrivialCtor() = default; | ||
|
||
NonAggregateWithNonTrivialCtor(const NonAggregateWithNonTrivialCtor&) = delete; | ||
NonAggregateWithNonTrivialCtor& operator=(const NonAggregateWithNonTrivialCtor&) = delete; | ||
|
||
void set_num(int x) { | ||
num = x; | ||
} | ||
int get_num() const { | ||
return num; | ||
} | ||
|
||
private: | ||
int num{0}; // default member initializer => non-trivial default constructor, N5014 [class.default.ctor]/3.2 | ||
}; | ||
|
||
class NonAggregateWithUserProvidedCtor { | ||
public: | ||
NonAggregateWithUserProvidedCtor() {} | ||
~NonAggregateWithUserProvidedCtor() = default; | ||
|
||
NonAggregateWithUserProvidedCtor(const NonAggregateWithUserProvidedCtor&) = delete; | ||
NonAggregateWithUserProvidedCtor& operator=(const NonAggregateWithUserProvidedCtor&) = delete; | ||
|
||
void set_num(int x) { | ||
num = x; | ||
} | ||
int get_num() const { | ||
return num; | ||
} | ||
|
||
private: | ||
int num; | ||
}; | ||
|
||
class NonAggregateWithDeletedDtor { | ||
public: | ||
NonAggregateWithDeletedDtor() = default; | ||
~NonAggregateWithDeletedDtor() = delete; | ||
|
||
NonAggregateWithDeletedDtor(const NonAggregateWithDeletedDtor&) = delete; | ||
NonAggregateWithDeletedDtor& operator=(const NonAggregateWithDeletedDtor&) = delete; | ||
|
||
void set_num(int x) { | ||
num = x; | ||
} | ||
int get_num() const { | ||
return num; | ||
} | ||
|
||
private: | ||
int num; | ||
}; | ||
|
||
class NonAggregateWithUserProvidedDtor { | ||
public: | ||
NonAggregateWithUserProvidedDtor() = default; | ||
~NonAggregateWithUserProvidedDtor() {} | ||
|
||
NonAggregateWithUserProvidedDtor(const NonAggregateWithUserProvidedDtor&) = delete; | ||
NonAggregateWithUserProvidedDtor& operator=(const NonAggregateWithUserProvidedDtor&) = delete; | ||
|
||
void set_num(int x) { | ||
num = x; | ||
} | ||
int get_num() const { | ||
return num; | ||
} | ||
|
||
private: | ||
int num; | ||
}; | ||
|
||
#ifdef __cpp_lib_is_implicit_lifetime | ||
template <bool Val, typename T> | ||
constexpr bool test_implicit_lifetime = is_implicit_lifetime_v<T> == Val && is_implicit_lifetime<T>::value == Val; | ||
template <bool Val, typename T> | ||
constexpr bool test_implicit_lifetime_cv = test_implicit_lifetime<Val, T> // | ||
&& test_implicit_lifetime<Val, const T> // | ||
&& test_implicit_lifetime<Val, volatile T> // | ||
&& test_implicit_lifetime<Val, const volatile T>; | ||
|
||
// Scalar types, N5014 [basic.types.general]/9 | ||
static_assert(test_implicit_lifetime_cv<true, int>); | ||
static_assert(test_implicit_lifetime_cv<true, UnscopedEnum>); | ||
static_assert(test_implicit_lifetime_cv<true, ScopedEnum>); | ||
static_assert(test_implicit_lifetime_cv<true, void*>); | ||
static_assert(test_implicit_lifetime_cv<true, int*>); | ||
static_assert(test_implicit_lifetime_cv<true, void (*)()>); | ||
static_assert(test_implicit_lifetime_cv<true, int TrivialClass::*>); | ||
static_assert(test_implicit_lifetime_cv<true, int (TrivialClass::*)(int)>); | ||
static_assert(test_implicit_lifetime_cv<true, nullptr_t>); | ||
|
||
// Implicit-lifetime class types, N5014 [class.prop]/16: | ||
// "A class S is an implicit-lifetime class if | ||
// - it is an aggregate whose destructor is not user-provided or | ||
// - it has at least one trivial eligible constructor and a trivial, non-deleted destructor." | ||
static_assert(test_implicit_lifetime_cv<true, TrivialClass>); | ||
static_assert(test_implicit_lifetime_cv<true, DefaultedDestructorClass>); | ||
static_assert(test_implicit_lifetime_cv<true, DeletedDestructorClass>); | ||
static_assert(test_implicit_lifetime_cv<false, UserProvidedDestructorClass>); | ||
static_assert(test_implicit_lifetime_cv<true, StringAggregateWithImplicitlyDeclaredDestructor>); | ||
static_assert(test_implicit_lifetime_cv<false, StringAggregateWithUserProvidedDestructor>); | ||
static_assert(test_implicit_lifetime_cv<true, NonAggregateWithTrivialCtorAndTrivialDtor>); | ||
#ifndef __clang__ // TRANSITION, LLVM-160610 | ||
static_assert(test_implicit_lifetime_cv<false, NonAggregateWithNonTrivialCtor>); | ||
static_assert(test_implicit_lifetime_cv<false, NonAggregateWithUserProvidedCtor>); | ||
#endif // ^^^ no workaround ^^^ | ||
static_assert(test_implicit_lifetime_cv<false, NonAggregateWithDeletedDtor>); | ||
static_assert(test_implicit_lifetime_cv<false, NonAggregateWithUserProvidedDtor>); | ||
|
||
// Arrays | ||
static_assert(test_implicit_lifetime_cv<true, int[]>); | ||
static_assert(test_implicit_lifetime_cv<true, int[2]>); | ||
static_assert(test_implicit_lifetime_cv<true, TrivialClass[]>); | ||
static_assert(test_implicit_lifetime_cv<true, TrivialClass[10]>); | ||
static_assert(test_implicit_lifetime_cv<true, UserProvidedDestructorClass[]>); | ||
static_assert(test_implicit_lifetime_cv<true, UserProvidedDestructorClass[12]>); | ||
static_assert(test_implicit_lifetime_cv<true, IncompleteClass[]>); | ||
static_assert(test_implicit_lifetime_cv<true, IncompleteClass[20]>); | ||
|
||
static_assert(test_implicit_lifetime_cv<false, void>); | ||
static_assert(test_implicit_lifetime<false, long&>); | ||
static_assert(test_implicit_lifetime<false, long&&>); | ||
static_assert(test_implicit_lifetime<false, const long&>); | ||
static_assert(test_implicit_lifetime<false, const long&&>); | ||
#endif // ^^^ defined(__cpp_lib_is_implicit_lifetime) ^^^ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.