From: John McCall Date: Tue, 25 Sep 2012 07:32:49 +0000 (+0000) Subject: Add the Microsoft __is_interface_class type trait. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ea30e2f8667668173cf7433c3c80cf603bd922a4;p=clang Add the Microsoft __is_interface_class type trait. Patch by Andy Gibbs! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164591 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/LanguageExtensions.html b/docs/LanguageExtensions.html index 21ac627712..8c0e5b7ffc 100644 --- a/docs/LanguageExtensions.html +++ b/docs/LanguageExtensions.html @@ -1007,6 +1007,7 @@ struct is_convertible_to {
  • __is_convertible_to (Microsoft)
  • __is_empty (GNU, Microsoft)
  • __is_enum (GNU, Microsoft)
  • +
  • __is_interface_class (Microsoft)
  • __is_pod (GNU, Microsoft)
  • __is_polymorphic (GNU, Microsoft)
  • __is_union (GNU, Microsoft)
  • diff --git a/include/clang/Basic/TokenKinds.def b/include/clang/Basic/TokenKinds.def index 0cc773355b..9b61403f45 100644 --- a/include/clang/Basic/TokenKinds.def +++ b/include/clang/Basic/TokenKinds.def @@ -365,6 +365,7 @@ KEYWORD(__is_convertible_to , KEYCXX) KEYWORD(__is_empty , KEYCXX) KEYWORD(__is_enum , KEYCXX) KEYWORD(__is_final , KEYCXX) +KEYWORD(__is_interface_class , KEYCXX) // Tentative name - there's no implementation of std::is_literal_type yet. KEYWORD(__is_literal , KEYCXX) // Name for GCC 4.6 compatibility - people have already written libraries using diff --git a/include/clang/Basic/TypeTraits.h b/include/clang/Basic/TypeTraits.h index 0a5a8643a3..882b52d489 100644 --- a/include/clang/Basic/TypeTraits.h +++ b/include/clang/Basic/TypeTraits.h @@ -41,6 +41,7 @@ namespace clang { UTT_IsFunction, UTT_IsFundamental, UTT_IsIntegral, + UTT_IsInterfaceClass, UTT_IsLiteral, UTT_IsLvalueReference, UTT_IsMemberFunctionPointer, diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 22b90dfa2c..3a9f236f31 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -1556,6 +1556,7 @@ static const char *getTypeTraitName(UnaryTypeTrait UTT) { case UTT_IsFunction: return "__is_function"; case UTT_IsFundamental: return "__is_fundamental"; case UTT_IsIntegral: return "__is_integral"; + case UTT_IsInterfaceClass: return "__is_interface_class"; case UTT_IsLiteral: return "__is_literal"; case UTT_IsLvalueReference: return "__is_lvalue_reference"; case UTT_IsMemberFunctionPointer: return "__is_member_function_pointer"; diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 9b95641f46..37cdd14407 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -1208,6 +1208,7 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, case tok::kw___is_class: case tok::kw___is_empty: case tok::kw___is_enum: + case tok::kw___is_interface_class: case tok::kw___is_literal: case tok::kw___is_arithmetic: case tok::kw___is_integral: diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index e02cb7a026..3039368cf7 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -2457,6 +2457,7 @@ static UnaryTypeTrait UnaryTypeTraitFromTokKind(tok::TokenKind kind) { case tok::kw___is_function: return UTT_IsFunction; case tok::kw___is_fundamental: return UTT_IsFundamental; case tok::kw___is_integral: return UTT_IsIntegral; + case tok::kw___is_interface_class: return UTT_IsInterfaceClass; case tok::kw___is_lvalue_reference: return UTT_IsLvalueReference; case tok::kw___is_member_function_pointer: return UTT_IsMemberFunctionPointer; case tok::kw___is_member_object_pointer: return UTT_IsMemberObjectPointer; diff --git a/lib/Parse/ParseTentative.cpp b/lib/Parse/ParseTentative.cpp index 01ab0e4eea..40c4eee199 100644 --- a/lib/Parse/ParseTentative.cpp +++ b/lib/Parse/ParseTentative.cpp @@ -782,6 +782,7 @@ Parser::isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind) { case tok::kw___is_convertible_to: case tok::kw___is_empty: case tok::kw___is_enum: + case tok::kw___is_interface_class: case tok::kw___is_final: case tok::kw___is_literal: case tok::kw___is_literal_type: diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index ca4702d17e..763ef28919 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -2927,6 +2927,7 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, case UTT_IsEmpty: case UTT_IsPolymorphic: case UTT_IsAbstract: + case UTT_IsInterfaceClass: // Fall-through // These traits require a complete type. @@ -3057,6 +3058,10 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, UnaryTypeTrait UTT, if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl()) return RD->isAbstract(); return false; + case UTT_IsInterfaceClass: + if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl()) + return RD->isInterface(); + return false; case UTT_IsFinal: if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl()) return RD->hasAttr(); diff --git a/test/SemaCXX/ms-interface.cpp b/test/SemaCXX/ms-interface.cpp index 62ae25482f..3625f7027a 100644 --- a/test/SemaCXX/ms-interface.cpp +++ b/test/SemaCXX/ms-interface.cpp @@ -59,6 +59,10 @@ struct S { }; class C { }; __interface I { }; +static_assert(!__is_interface_class(S), "oops"); +static_assert(!__is_interface_class(C), "oops"); +static_assert(__is_interface_class(I), "oops"); + // expected-error@55 {{interface type cannot inherit from 'struct S'}} // expected-note@+1 {{in instantiation of template class 'I6' requested here}} struct S1 : I6 {