Skip to content

Commit cdaecf0

Browse files
committed
Added TypeTraitsDiags.def to support typetraits and start using it in StdNameToTypeTrait
1 parent 2401565 commit cdaecf0

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

clang/include/clang/Basic/TokenKinds.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
#define TRANSFORM_TYPE_TRAIT_DEF(K, Trait) KEYWORD(__##Trait, KEYCXX)
6969
#endif
7070

71+
#ifndef TYPE_TRAIT_DIAG
72+
#define TYPE_TRAIT_DIAG(Trait, N)
73+
#endif
74+
7175
#ifndef ALIAS
7276
#define ALIAS(X,Y,Z)
7377
#endif
@@ -542,6 +546,7 @@ TYPE_TRAIT_2(__is_layout_compatible, IsLayoutCompatible, KEYCXX)
542546
TYPE_TRAIT_2(__is_pointer_interconvertible_base_of, IsPointerInterconvertibleBaseOf, KEYCXX)
543547

544548
#include "clang/Basic/TransformTypeTraits.def"
549+
#include "clang/Basic/TypeTraitsDiags.def"
545550

546551
// Clang-only C++ Type Traits
547552
TYPE_TRAIT_1(__is_trivially_equality_comparable, IsTriviallyEqualityComparable, KEYCXX)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//==--- TypeTraitsDiags.def - type trait transformations --------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines type traits' for diagnostic.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
TYPE_TRAIT_DIAG(is_trivially_copyable, IsTriviallyCopyable)
14+
TYPE_TRAIT_DIAG(is_trivially_relocatable, IsCppTriviallyRelocatable)
15+
16+
#undef TYPE_TRAIT_DIAG

clang/lib/Sema/SemaTypeTraits.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,11 +1921,11 @@ ExprResult Sema::BuildExpressionTrait(ExpressionTrait ET, SourceLocation KWLoc,
19211921
}
19221922

19231923
static std::optional<TypeTrait> StdNameToTypeTrait(StringRef Name) {
1924-
return llvm::StringSwitch<std::optional<TypeTrait>>(Name)
1925-
.Case("is_trivially_relocatable",
1926-
TypeTrait::UTT_IsCppTriviallyRelocatable)
1927-
.Case("is_trivially_copyable", TypeTrait::UTT_IsTriviallyCopyable)
1928-
.Default(std::nullopt);
1924+
#define TYPE_TRAIT_DIAG(Spelling, Name) Case(#Spelling, TypeTrait::UTT_##Name).
1925+
return llvm::StringSwitch<std::optional<TypeTrait>>(Name).
1926+
#include "clang/Basic/TokenKinds.def"
1927+
Default(std::nullopt);
1928+
#undef TYPE_TRAIT_DIAG
19291929
}
19301930

19311931
using ExtractedTypeTraitInfo =

0 commit comments

Comments
 (0)