diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -4558,6 +4558,7 @@ AddConst, AddVolatile, RemoveConst, + RemoveVolatile, }; private: diff --git a/clang/include/clang/Basic/Specifiers.h b/clang/include/clang/Basic/Specifiers.h --- a/clang/include/clang/Basic/Specifiers.h +++ b/clang/include/clang/Basic/Specifiers.h @@ -87,6 +87,7 @@ TST_add_cv, // __add_cv extension TST_add_volatile, // __add_volatile extension TST_remove_const, // __remove_const extension + TST_remove_volatile, // __remove_volatile extension TST_auto, // C++11 auto TST_decltype_auto, // C++1y decltype(auto) TST_auto_type, // __auto_type extension diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def --- a/clang/include/clang/Basic/TokenKinds.def +++ b/clang/include/clang/Basic/TokenKinds.def @@ -512,6 +512,7 @@ KEYWORD(__add_cv, KEYCXX) KEYWORD(__add_volatile, KEYCXX) KEYWORD(__remove_const, KEYCXX) +KEYWORD(__remove_volatile, KEYCXX) // Clang-only C++ Type Traits TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX) diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -295,6 +295,7 @@ static const TST TST_add_cv = clang::TST_add_cv; static const TST TST_add_volatile = clang::TST_add_volatile; static const TST TST_remove_const = clang::TST_remove_const; + static const TST TST_remove_volatile = clang::TST_remove_volatile; static const TST TST_auto = clang::TST_auto; static const TST TST_auto_type = clang::TST_auto_type; static const TST TST_unknown_anytype = clang::TST_unknown_anytype; diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -3937,6 +3937,9 @@ case UnaryTransformType::RemoveConst: Out << "3rc"; break; + case UnaryTransformType::RemoveVolatile: + Out << "3rv"; + break; } } diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp --- a/clang/lib/AST/JSONNodeDumper.cpp +++ b/clang/lib/AST/JSONNodeDumper.cpp @@ -677,6 +677,9 @@ case UnaryTransformType::RemoveConst: JOS.attribute("transformedKind", "remove_const"); break; + case UnaryTransformType::RemoveVolatile: + JOS.attribute("transformedKind", "remove_volatile"); + break; } } diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -1122,11 +1122,12 @@ case UnaryTransformType::EnumUnderlyingType: case UnaryTransformType::AddConst: case UnaryTransformType::AddCV: + case UnaryTransformType::AddVolatile: case UnaryTransformType::RemoveConst: - case UnaryTransformType::AddVolatile: { - constexpr std::array Transformation = { - "__underlying_type", "__add_const", "__add_cv", "__add_volatile", - "__remove_const"}; + case UnaryTransformType::RemoveVolatile: { + constexpr std::array Transformation = { + "__underlying_type", "__add_const", "__add_cv", + "__add_volatile", "__remove_const", "__remove_volatile"}; OS << Transformation[T->getUTTKind()] << '('; print(T->getBaseType(), OS, StringRef()); OS << ')'; @@ -1148,6 +1149,7 @@ case UnaryTransformType::AddCV: case UnaryTransformType::AddVolatile: case UnaryTransformType::RemoveConst: + case UnaryTransformType::RemoveVolatile: return; } diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -61,6 +61,7 @@ case tok::kw___add_cv: case tok::kw___add_volatile: case tok::kw___remove_const: + case tok::kw___remove_volatile: case tok::annot_typename: case tok::kw_char8_t: case tok::kw_char16_t: diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1662,6 +1662,7 @@ .Case("__add_cv", true) .Case("__add_volatile", true) .Case("__remove_const", true) + .Case("__remove_volatile", true) .Default(false); } else { return llvm::StringSwitch(II->getName()) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4119,6 +4119,7 @@ case tok::kw___add_cv: case tok::kw___add_volatile: case tok::kw___remove_const: + case tok::kw___remove_volatile: ParseTypeTransformTypeSpecifier(DS); continue; @@ -4232,6 +4233,8 @@ return DeclSpec::TST_add_volatile; case tok::kw___remove_const: return DeclSpec::TST_remove_const; + case tok::kw___remove_volatile: + return DeclSpec::TST_remove_volatile; } __builtin_unreachable(); diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -1534,7 +1534,8 @@ tok::kw___is_trivially_assignable, tok::kw___is_trivially_constructible, tok::kw___is_trivially_copyable, tok::kw___is_union, tok::kw___is_unsigned, tok::kw___is_void, - tok::kw___is_volatile, tok::kw___remove_const)) + tok::kw___is_volatile, tok::kw___remove_const, + tok::kw___remove_volatile)) // GNU libstdc++ 4.2 and libc++ use certain intrinsic names as the // name of struct templates, but some are keywords in GCC >= 4.3 // and Clang. Therefore, when we see the token sequence "struct diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp --- a/clang/lib/Sema/DeclSpec.cpp +++ b/clang/lib/Sema/DeclSpec.cpp @@ -395,6 +395,7 @@ case TST_add_cv: case TST_add_volatile: case TST_remove_const: + case TST_remove_volatile: case TST_typename: case TST_typeofType: { QualType QT = DS.getRepAsType().get(); @@ -586,10 +587,12 @@ return "__add_const"; case DeclSpec::TST_add_cv: return "__add_cv"; - case DeclSpec::TST_remove_const: - return "__remove_const"; case DeclSpec::TST_add_volatile: return "__add_volatile"; + case DeclSpec::TST_remove_const: + return "__remove_const"; + case DeclSpec::TST_remove_volatile: + return "__remove_volatile"; case DeclSpec::TST_unknown_anytype: return "__unknown_anytype"; case DeclSpec::TST_atomic: return "_Atomic"; case DeclSpec::TST_BFloat16: return "__bf16"; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -147,8 +147,9 @@ case tok::kw___underlying_type: case tok::kw___add_const: case tok::kw___add_cv: - case tok::kw___remove_const: case tok::kw___add_volatile: + case tok::kw___remove_const: + case tok::kw___remove_volatile: case tok::kw___auto_type: return true; @@ -5605,8 +5606,9 @@ case DeclSpec::TST_underlyingType: case DeclSpec::TST_add_const: case DeclSpec::TST_add_cv: - case DeclSpec::TST_remove_const: case DeclSpec::TST_add_volatile: + case DeclSpec::TST_remove_const: + case DeclSpec::TST_remove_volatile: case DeclSpec::TST_atomic: { // Grab the type from the parser. TypeSourceInfo *TSI = nullptr; diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp --- a/clang/lib/Sema/SemaTemplateVariadic.cpp +++ b/clang/lib/Sema/SemaTemplateVariadic.cpp @@ -863,8 +863,9 @@ case TST_underlyingType: case TST_add_const: case TST_add_cv: - case TST_remove_const: case TST_add_volatile: + case TST_remove_const: + case TST_remove_volatile: case TST_atomic: { QualType T = DS.getRepAsType().get(); if (!T.isNull() && T->containsUnexpandedParameterPack()) diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1269,6 +1269,8 @@ return UnaryTransformType::AddVolatile; case TST_remove_const: return UnaryTransformType::RemoveConst; + case TST_remove_volatile: + return UnaryTransformType::RemoveVolatile; case TST_underlyingType: return UnaryTransformType::EnumUnderlyingType; default: @@ -1663,6 +1665,7 @@ case DeclSpec::TST_add_cv: case DeclSpec::TST_add_volatile: case DeclSpec::TST_remove_const: + case DeclSpec::TST_remove_volatile: Result = S.GetTypeFromParser(DS.getRepAsType()); assert(!Result.isNull() && "Didn't get a type for the transformation?"); Result = S.BuildUnaryTransformType( @@ -6000,7 +6003,7 @@ void VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { // Make sure it is a unary transform type assert(DS.getTypeSpecType() >= DeclSpec::TST_underlyingType && - DS.getTypeSpecType() <= DeclSpec::TST_remove_const); + DS.getTypeSpecType() <= DeclSpec::TST_remove_volatile); TL.setKWLoc(DS.getTypeSpecTypeLoc()); TL.setParensRange(DS.getTypeofParensRange()); assert(DS.getRepAsType()); @@ -9093,7 +9096,8 @@ case UnaryTransformType::AddConst: case UnaryTransformType::AddCV: case UnaryTransformType::AddVolatile: - case UnaryTransformType::RemoveConst: { + case UnaryTransformType::RemoveConst: + case UnaryTransformType::RemoveVolatile: { SplitQualType Split = BaseType.getSplitUnqualifiedType(); Qualifiers Quals = BaseType.getQualifiers(); if (BaseType->isReferenceType() || BaseType->isFunctionType()) @@ -9111,6 +9115,9 @@ case UnaryTransformType::RemoveConst: Quals.removeConst(); break; + case UnaryTransformType::RemoveVolatile: + Quals.removeVolatile(); + break; } QualType Underlying(Split.Ty, Quals.getAsOpaqueValue()); return Context.getUnaryTransformType(BaseType, Underlying, UKind); diff --git a/clang/test/SemaCXX/remove_cvref.cpp b/clang/test/SemaCXX/remove_cvref.cpp --- a/clang/test/SemaCXX/remove_cvref.cpp +++ b/clang/test/SemaCXX/remove_cvref.cpp @@ -3,6 +3,12 @@ template constexpr bool check_remove_qualifiers() { static_assert(__is_same(__remove_const(const T), T), ""); + static_assert(__is_same(__remove_const(volatile T), volatile T), ""); + static_assert(__is_same(__remove_const(const volatile T), volatile T), ""); + + static_assert(__is_same(__remove_volatile(const T), const T), ""); + static_assert(__is_same(__remove_volatile(volatile T), T), ""); + static_assert(__is_same(__remove_volatile(const volatile T), const T), ""); return true; }