Skip to content

Commit fd1194f

Browse files
committed
[Clang][C++26] Remove the notion of replaceability.
In Kona, WG21 decided to revert trivial relocation (P2786). Given that the notion of replaceability that was introduced at the same time does not appear to be used by clang 21 users, and is less likely to come back, it is easier to fully remove wholesale. Subsequent patches will deal with relocation.
1 parent af27159 commit fd1194f

18 files changed

+58
-562
lines changed

clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ static const llvm::StringSet<> ValueTraits = {
8383
"is_pointer_interconvertible_base_of",
8484
"is_polymorphic",
8585
"is_reference",
86-
"is_replaceable",
8786
"is_rvalue_reference",
8887
"is_same",
8988
"is_scalar",

clang/docs/LanguageExtensions.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,8 +2044,6 @@ The following type trait primitives are supported by Clang. Those traits marked
20442044
is trivially relocatable, as defined by the C++26 standard [meta.unary.prop].
20452045
Note that when relocating the caller code should ensure that if the object is polymorphic,
20462046
the dynamic type is of the most derived type. Padding bytes should not be copied.
2047-
* ``__builtin_is_replaceable`` (C++): Returns true if an object
2048-
is replaceable, as defined by the C++26 standard [meta.unary.prop].
20492047
* ``__is_trivially_equality_comparable`` (Clang): Returns true if comparing two
20502048
objects of the provided type is known to be equivalent to comparing their
20512049
object representations. Note that types containing padding bytes are never

clang/include/clang/AST/ASTContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
666666
public:
667667
struct CXXRecordDeclRelocationInfo {
668668
unsigned IsRelocatable;
669-
unsigned IsReplaceable;
670669
};
671670
std::optional<CXXRecordDeclRelocationInfo>
672671
getRelocationInfoForCXXRecord(const CXXRecordDecl *) const;

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,14 +1952,6 @@ def TriviallyRelocatable : InheritableAttr {
19521952
let Documentation = [InternalOnly];
19531953
}
19541954

1955-
def Replaceable : InheritableAttr {
1956-
let Spellings = [CustomKeyword<"replaceable_if_eligible">];
1957-
let SemaHandler = 0;
1958-
// Omitted from docs, since this is language syntax, not an attribute, as far
1959-
// as users are concerned.
1960-
let Documentation = [InternalOnly];
1961-
}
1962-
19631955
def MinSize : InheritableAttr {
19641956
let Spellings = [Clang<"minsize">];
19651957
let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,23 +1077,24 @@ def ext_ms_abstract_keyword : ExtWarn<
10771077
"'abstract' keyword is a Microsoft extension">,
10781078
InGroup<MicrosoftAbstract>;
10791079

1080-
def ext_relocatable_keyword : ExtWarn<
1081-
"'%select{trivially_relocatable_if_eligible|replaceable_if_eligible}0' "
1082-
"keyword is a C++2c extension">,
1083-
InGroup<CXX26>;
1084-
def warn_relocatable_keyword : Warning<
1085-
"'%select{trivially_relocatable|replaceable}0_if_eligible' "
1086-
"keyword is incompatible with standards before C++2c">,
1087-
DefaultIgnore, InGroup<CXXPre26Compat>;
1080+
def ext_relocatable_keyword
1081+
: ExtWarn<
1082+
"'trivially_relocatable_if_eligible' keyword is a C++2c extension">,
1083+
InGroup<CXX26>;
1084+
def warn_relocatable_keyword
1085+
: Warning<"'trivially_relocatable_if_eligible' keyword is incompatible "
1086+
"with standards before C++2c">,
1087+
DefaultIgnore,
1088+
InGroup<CXXPre26Compat>;
10881089

10891090
def err_access_specifier_interface : Error<
10901091
"interface types cannot specify '%select{private|protected}0' access">;
10911092

10921093
def err_duplicate_class_virt_specifier : Error<
10931094
"class already marked '%0'">;
10941095

1095-
def err_duplicate_class_relocation_specifier : Error<
1096-
"class already marked '%select{trivially_relocatable_if_eligible|replaceable_if_eligible}0'">;
1096+
def err_duplicate_class_relocation_specifier
1097+
: Error<"class already marked 'trivially_relocatable_if_eligible'">;
10971098

10981099
def err_duplicate_virt_specifier : Error<
10991100
"class member already marked '%0'">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,6 @@ def err_user_defined_msg_constexpr : Error<
17701770
def note_unsatisfied_trait
17711771
: Note<"%0 is not %enum_select<TraitName>{"
17721772
"%TriviallyRelocatable{trivially relocatable}|"
1773-
"%Replaceable{replaceable}|"
17741773
"%TriviallyCopyable{trivially copyable}|"
17751774
"%Empty{empty}|"
17761775
"%StandardLayout{standard-layout}|"
@@ -1792,8 +1791,6 @@ def note_unsatisfied_trait_reason
17921791
"class type}|"
17931792
"%NTRBase{has a non-trivially-relocatable base %1}|"
17941793
"%NTRField{has a non-trivially-relocatable member %1 of type %2}|"
1795-
"%NonReplaceableBase{has a non-replaceable base %1}|"
1796-
"%NonReplaceableField{has a non-replaceable member %1 of type %2}|"
17971794
"%NTCBase{has a non-trivially-copyable base %1}|"
17981795
"%NTCField{has a non-trivially-copyable member %1 of type %2}|"
17991796
"%NonEmptyMember{has a non-static data member %1 of type %2}|"

clang/include/clang/Basic/TokenKinds.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,6 @@ TYPE_TRAIT_2(/*EmptySpellingName*/, IsDeducible, KEYCXX)
564564
TYPE_TRAIT_1(__builtin_is_cpp_trivially_relocatable, IsCppTriviallyRelocatable, KEYCXX)
565565
TYPE_TRAIT_1(__is_trivially_relocatable, IsTriviallyRelocatable, KEYCXX)
566566
TYPE_TRAIT_1(__is_bitwise_cloneable, IsBitwiseCloneable, KEYALL)
567-
TYPE_TRAIT_1(__builtin_is_replaceable, IsReplaceable, KEYCXX)
568567
TYPE_TRAIT_1(__builtin_structured_binding_size, StructuredBindingSize, KEYCXX)
569568

570569

clang/include/clang/Parse/Parser.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,7 +2835,6 @@ class Parser : public CodeCompletionHandler {
28352835
mutable IdentifierInfo *Ident_GNU_final;
28362836
mutable IdentifierInfo *Ident_override;
28372837
mutable IdentifierInfo *Ident_trivially_relocatable_if_eligible;
2838-
mutable IdentifierInfo *Ident_replaceable_if_eligible;
28392838

28402839
/// Representation of a class that has been parsed, including
28412840
/// any member function declarations or definitions that need to be
@@ -3129,7 +3128,7 @@ class Parser : public CodeCompletionHandler {
31293128

31303129
/// isClassCompatibleKeyword - Determine whether the next token is a C++11
31313130
/// 'final', a C++26 'trivially_relocatable_if_eligible',
3132-
/// 'replaceable_if_eligible', or Microsoft 'sealed' or 'abstract' contextual
3131+
/// or Microsoft 'sealed' or 'abstract' contextual
31333132
/// keyword.
31343133
bool isClassCompatibleKeyword() const;
31353134

@@ -3603,12 +3602,8 @@ class Parser : public CodeCompletionHandler {
36033602
bool isCXX2CTriviallyRelocatableKeyword() const;
36043603
void ParseCXX2CTriviallyRelocatableSpecifier(SourceLocation &TRS);
36053604

3606-
bool isCXX2CReplaceableKeyword(Token Tok) const;
3607-
bool isCXX2CReplaceableKeyword() const;
3608-
void ParseCXX2CReplaceableSpecifier(SourceLocation &MRS);
3609-
36103605
/// 'final', a C++26 'trivially_relocatable_if_eligible',
3611-
/// 'replaceable_if_eligible', or Microsoft 'sealed' or 'abstract' contextual
3606+
/// or Microsoft 'sealed' or 'abstract' contextual
36123607
/// keyword.
36133608
bool isClassCompatibleKeyword(Token Tok) const;
36143609

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4366,7 +4366,6 @@ class Sema final : public SemaBase {
43664366
bool IsFinalSpelledSealed,
43674367
bool IsAbstract,
43684368
SourceLocation TriviallyRelocatable,
4369-
SourceLocation Replaceable,
43704369
SourceLocation LBraceLoc);
43714370

43724371
/// ActOnTagFinishDefinition - Invoked once we have finished parsing
@@ -4375,7 +4374,7 @@ class Sema final : public SemaBase {
43754374
SourceRange BraceRange);
43764375

43774376
ASTContext::CXXRecordDeclRelocationInfo
4378-
CheckCXX2CRelocatableAndReplaceable(const clang::CXXRecordDecl *D);
4377+
CheckCXX2CRelocatable(const clang::CXXRecordDecl *D);
43794378

43804379
void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context);
43814380

@@ -8733,12 +8732,6 @@ class Sema final : public SemaBase {
87338732
bool IsCXXTriviallyRelocatableType(QualType T);
87348733
bool IsCXXTriviallyRelocatableType(const CXXRecordDecl &RD);
87358734

8736-
//// Determines if a type is replaceable
8737-
/// according to the C++26 rules.
8738-
// FIXME: This is in Sema because it requires
8739-
// overload resolution, can we move to ASTContext?
8740-
bool IsCXXReplaceableType(QualType T);
8741-
87428735
/// Check the operands of ?: under C++ semantics.
87438736
///
87448737
/// See C++ [expr.cond]. Note that LHS is never null, even for the GNU x ?: y

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,40 +2498,13 @@ void Parser::ParseCXX2CTriviallyRelocatableSpecifier(SourceLocation &TRS) {
24982498

24992499
Diag(Tok.getLocation(), getLangOpts().CPlusPlus26
25002500
? diag::warn_relocatable_keyword
2501-
: diag::ext_relocatable_keyword)
2502-
<< /*relocatable*/ 0;
2501+
: diag::ext_relocatable_keyword);
25032502

25042503
TRS = ConsumeToken();
25052504
}
25062505

2507-
bool Parser::isCXX2CReplaceableKeyword(Token Tok) const {
2508-
if (!getLangOpts().CPlusPlus || Tok.isNot(tok::identifier))
2509-
return false;
2510-
if (!Ident_replaceable_if_eligible)
2511-
Ident_replaceable_if_eligible =
2512-
&PP.getIdentifierTable().get("replaceable_if_eligible");
2513-
IdentifierInfo *II = Tok.getIdentifierInfo();
2514-
return II == Ident_replaceable_if_eligible;
2515-
}
2516-
2517-
bool Parser::isCXX2CReplaceableKeyword() const {
2518-
return isCXX2CReplaceableKeyword(Tok);
2519-
}
2520-
2521-
void Parser::ParseCXX2CReplaceableSpecifier(SourceLocation &MRS) {
2522-
assert(isCXX2CReplaceableKeyword() &&
2523-
"expected a replaceable_if_eligible specifier");
2524-
2525-
Diag(Tok.getLocation(), getLangOpts().CPlusPlus26
2526-
? diag::warn_relocatable_keyword
2527-
: diag::ext_relocatable_keyword)
2528-
<< /*replaceable*/ 1;
2529-
2530-
MRS = ConsumeToken();
2531-
}
2532-
25332506
bool Parser::isClassCompatibleKeyword(Token Tok) const {
2534-
if (isCXX2CTriviallyRelocatableKeyword(Tok) || isCXX2CReplaceableKeyword(Tok))
2507+
if (isCXX2CTriviallyRelocatableKeyword(Tok))
25352508
return true;
25362509
VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(Tok);
25372510
return Specifier == VirtSpecifiers::VS_Final ||
@@ -3587,7 +3560,6 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
35873560
bool IsFinalSpelledSealed = false;
35883561
bool IsAbstract = false;
35893562
SourceLocation TriviallyRelocatable;
3590-
SourceLocation Replaceable;
35913563

35923564
// Parse the optional 'final' keyword.
35933565
if (getLangOpts().CPlusPlus && Tok.is(tok::identifier)) {
@@ -3599,23 +3571,12 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
35993571
auto Skipped = Tok;
36003572
ConsumeToken();
36013573
Diag(Skipped, diag::err_duplicate_class_relocation_specifier)
3602-
<< /*trivial_relocatable*/ 0 << TriviallyRelocatable;
3574+
<< TriviallyRelocatable;
36033575
} else {
36043576
ParseCXX2CTriviallyRelocatableSpecifier(TriviallyRelocatable);
36053577
}
36063578
continue;
36073579
}
3608-
if (isCXX2CReplaceableKeyword(Tok)) {
3609-
if (Replaceable.isValid()) {
3610-
auto Skipped = Tok;
3611-
ConsumeToken();
3612-
Diag(Skipped, diag::err_duplicate_class_relocation_specifier)
3613-
<< /*replaceable*/ 1 << Replaceable;
3614-
} else {
3615-
ParseCXX2CReplaceableSpecifier(Replaceable);
3616-
}
3617-
continue;
3618-
}
36193580
break;
36203581
}
36213582
if (isCXX11FinalKeyword()) {
@@ -3654,7 +3615,7 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
36543615
Diag(FinalLoc, diag::ext_warn_gnu_final);
36553616
}
36563617
assert((FinalLoc.isValid() || AbstractLoc.isValid() ||
3657-
TriviallyRelocatable.isValid() || Replaceable.isValid()) &&
3618+
TriviallyRelocatable.isValid()) &&
36583619
"not a class definition");
36593620

36603621
// Parse any C++11 attributes after 'final' keyword.
@@ -3729,7 +3690,7 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
37293690
if (TagDecl)
37303691
Actions.ActOnStartCXXMemberDeclarations(
37313692
getCurScope(), TagDecl, FinalLoc, IsFinalSpelledSealed, IsAbstract,
3732-
TriviallyRelocatable, Replaceable, T.getOpenLocation());
3693+
TriviallyRelocatable, T.getOpenLocation());
37333694

37343695
// C++ 11p3: Members of a class defined with the keyword class are private
37353696
// by default. Members of a class defined with the keywords struct or union

0 commit comments

Comments
 (0)