Skip to content

Commit 5ef6c00

Browse files
committed
Refine the implementation of hiding __is_deducible type trait.
Apply approach 3.
1 parent 552156f commit 5ef6c00

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

clang/include/clang/Basic/TokenKinds.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,9 @@ TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
537537
TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
538538
TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
539539
TYPE_TRAIT_2(__reference_constructs_from_temporary, ReferenceConstructsFromTemporary, KEYCXX)
540+
// IsDeducible is only used internally by clang for CTAD implementation and
541+
// is not exposed to users.
542+
TYPE_TRAIT_2(/*EmptySpellingName*/, IsDeducible, KEYCXX)
540543

541544
// Embarcadero Expression Traits
542545
EXPRESSION_TRAIT(__is_lvalue_expr, IsLValueExpr, KEYCXX)

clang/include/clang/Basic/TypeTraits.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ enum TypeTrait {
2626
#include "clang/Basic/TokenKinds.def"
2727
,
2828
#define TYPE_TRAIT_2(Spelling, Name, Key) BTT_##Name,
29-
// IsDeducible is only used internally by clang for CTAD implementation and
30-
// is not exposed to users.
31-
TYPE_TRAIT_2(/**/, IsDeducible, KEYCXX)
3229
#include "clang/Basic/TokenKinds.def"
33-
// +1 for the IsDeducible enumerator.
34-
BTT_Last = UTT_Last + 1 // BTT_Last == last BTT_XX in the enum.
30+
BTT_Last = UTT_Last
3531

3632
#define TYPE_TRAIT_2(Spelling, Name, Key) +1
3733
#include "clang/Basic/TokenKinds.def"

clang/lib/Basic/TypeTraits.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313
#include "clang/Basic/TypeTraits.h"
1414
#include "llvm/Support/ErrorHandling.h"
1515
#include <cassert>
16+
#include <cstring>
1617
using namespace clang;
1718

1819
static constexpr const char *TypeTraitNames[] = {
1920
#define TYPE_TRAIT_1(Spelling, Name, Key) #Name,
2021
#include "clang/Basic/TokenKinds.def"
2122
#define TYPE_TRAIT_2(Spelling, Name, Key) #Name,
22-
// IsDeducible is only used internally by clang for CTAD implementation and
23-
// is not exposed to users.
24-
TYPE_TRAIT_2(/**/, IsDeducible, KEYCXX)
2523
#include "clang/Basic/TokenKinds.def"
2624
#define TYPE_TRAIT_N(Spelling, Name, Key) #Name,
2725
#include "clang/Basic/TokenKinds.def"
@@ -31,9 +29,6 @@ static constexpr const char *TypeTraitSpellings[] = {
3129
#define TYPE_TRAIT_1(Spelling, Name, Key) #Spelling,
3230
#include "clang/Basic/TokenKinds.def"
3331
#define TYPE_TRAIT_2(Spelling, Name, Key) #Spelling,
34-
// __is_deducible is only used internally by clang for CTAD implementation
35-
// and is not exposed to users.
36-
TYPE_TRAIT_2(__is_deducible, /**/, KEYCXX)
3732
#include "clang/Basic/TokenKinds.def"
3833
#define TYPE_TRAIT_N(Spelling, Name, Key) #Spelling,
3934
#include "clang/Basic/TokenKinds.def"
@@ -65,9 +60,6 @@ static constexpr const unsigned TypeTraitArities[] = {
6560
#define TYPE_TRAIT_1(Spelling, Name, Key) 1,
6661
#include "clang/Basic/TokenKinds.def"
6762
#define TYPE_TRAIT_2(Spelling, Name, Key) 2,
68-
// IsDeducible is only used internally by clang for CTAD implementation and
69-
// is not exposed to users.
70-
TYPE_TRAIT_2(/**/, IsDeducible, KEYCXX)
7163
#include "clang/Basic/TokenKinds.def"
7264
#define TYPE_TRAIT_N(Spelling, Name, Key) 0,
7365
#include "clang/Basic/TokenKinds.def"
@@ -90,6 +82,15 @@ const char *clang::getTraitName(UnaryExprOrTypeTrait T) {
9082

9183
const char *clang::getTraitSpelling(TypeTrait T) {
9284
assert(T <= TT_Last && "invalid enum value!");
85+
if (T == BTT_IsDeducible) {
86+
// The __is_deducible is an internal-only type trait. To hide it from
87+
// external users, we define it with an empty spelling name, preventing the
88+
// clang parser from recognizing its token kind.
89+
// However, other components such as the AST dump still require the real
90+
// type trait name. Therefore, we return the real name when needed.
91+
assert(std::strlen(TypeTraitSpellings[T]) == 0);
92+
return "__is_deducible";
93+
}
9394
return TypeTraitSpellings[T];
9495
}
9596

0 commit comments

Comments
 (0)