[cfe-commits] r145775 - in /cfe/trunk: docs/LanguageExtensions.html include/clang/Basic/TokenKinds.def include/clang/Basic/TypeTraits.h lib/AST/StmtPrinter.cpp lib/Lex/PPMacroExpansion.cpp lib/Parse/ParseExpr.cpp lib/Parse/ParseExprCXX.cpp lib/Parse/ParseTentative.cpp lib/Sema/SemaExprCXX.cpp test/Lexer/has_feature_type_traits.cpp test/SemaCXX/type-traits.cpp
Douglas Gregor
dgregor at apple.com
Sat Dec 3 10:14:24 PST 2011
Author: dgregor
Date: Sat Dec 3 12:14:24 2011
New Revision: 145775
URL: http://llvm.org/viewvc/llvm-project?rev=145775&view=rev
Log:
Implement support for the __is_final type trait, to determine whether
a class is marked 'final', from Alberto Ganesh Barbati! Fixes
PR11462.
Modified:
cfe/trunk/docs/LanguageExtensions.html
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/include/clang/Basic/TypeTraits.h
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/Lexer/has_feature_type_traits.cpp
cfe/trunk/test/SemaCXX/type-traits.cpp
Modified: cfe/trunk/docs/LanguageExtensions.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.html?rev=145775&r1=145774&r2=145775&view=diff
==============================================================================
--- cfe/trunk/docs/LanguageExtensions.html (original)
+++ cfe/trunk/docs/LanguageExtensions.html Sat Dec 3 12:14:24 2011
@@ -724,6 +724,7 @@
<li><code>__is_polymorphic</code> (GNU, Microsoft)</li>
<li><code>__is_union</code> (GNU, Microsoft)</li>
<li><code>__is_literal(type)</code>: Determines whether the given type is a literal type</li>
+ <li><code>__is_final</code>: Determines whether the given type is declared with a <code>final</code> class-virt-specifier.</li>
<li><code>__underlying_type(type)</code>: Retrieves the underlying type for a given <code>enum</code> type. This trait is required to implement the C++11 standard library.</li>
</ul>
Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=145775&r1=145774&r2=145775&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Sat Dec 3 12:14:24 2011
@@ -353,6 +353,7 @@
KEYWORD(__is_convertible_to , KEYCXX)
KEYWORD(__is_empty , KEYCXX)
KEYWORD(__is_enum , KEYCXX)
+KEYWORD(__is_final , 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
Modified: cfe/trunk/include/clang/Basic/TypeTraits.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TypeTraits.h?rev=145775&r1=145774&r2=145775&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TypeTraits.h (original)
+++ cfe/trunk/include/clang/Basic/TypeTraits.h Sat Dec 3 12:14:24 2011
@@ -35,6 +35,7 @@
UTT_IsConst,
UTT_IsEmpty,
UTT_IsEnum,
+ UTT_IsFinal,
UTT_IsFloatingPoint,
UTT_IsFunction,
UTT_IsFundamental,
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=145775&r1=145774&r2=145775&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Sat Dec 3 12:14:24 2011
@@ -1409,6 +1409,7 @@
case UTT_IsConst: return "__is_const";
case UTT_IsEmpty: return "__is_empty";
case UTT_IsEnum: return "__is_enum";
+ case UTT_IsFinal: return "__is_final";
case UTT_IsFloatingPoint: return "__is_floating_point";
case UTT_IsFunction: return "__is_function";
case UTT_IsFundamental: return "__is_fundamental";
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=145775&r1=145774&r2=145775&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Sat Dec 3 12:14:24 2011
@@ -675,6 +675,7 @@
PP.getIdentifierInfo("__is_empty")->getTokenID()
!= tok::identifier)
.Case("is_enum", LangOpts.CPlusPlus)
+ .Case("is_final", LangOpts.CPlusPlus)
.Case("is_literal", LangOpts.CPlusPlus)
.Case("is_standard_layout", LangOpts.CPlusPlus)
// __is_pod is available only if the horrible
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=145775&r1=145774&r2=145775&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Sat Dec 3 12:14:24 2011
@@ -565,6 +565,7 @@
/// '__is_class'
/// '__is_empty' [TODO]
/// '__is_enum'
+/// '__is_final'
/// '__is_pod'
/// '__is_polymorphic'
/// '__is_trivial'
@@ -1087,6 +1088,7 @@
case tok::kw___is_trivial:
case tok::kw___is_trivially_copyable:
case tok::kw___is_union:
+ case tok::kw___is_final:
case tok::kw___has_trivial_constructor:
case tok::kw___has_trivial_copy:
case tok::kw___has_trivial_assign:
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=145775&r1=145774&r2=145775&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Sat Dec 3 12:14:24 2011
@@ -2241,6 +2241,7 @@
case tok::kw___is_const: return UTT_IsConst;
case tok::kw___is_empty: return UTT_IsEmpty;
case tok::kw___is_enum: return UTT_IsEnum;
+ case tok::kw___is_final: return UTT_IsFinal;
case tok::kw___is_floating_point: return UTT_IsFloatingPoint;
case tok::kw___is_function: return UTT_IsFunction;
case tok::kw___is_fundamental: return UTT_IsFundamental;
Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=145775&r1=145774&r2=145775&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Sat Dec 3 12:14:24 2011
@@ -670,6 +670,7 @@
case tok::kw___is_convertible_to:
case tok::kw___is_empty:
case tok::kw___is_enum:
+ case tok::kw___is_final:
case tok::kw___is_literal:
case tok::kw___is_literal_type:
case tok::kw___is_pod:
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=145775&r1=145774&r2=145775&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sat Dec 3 12:14:24 2011
@@ -2650,6 +2650,9 @@
case UTT_IsAbstract:
// Fall-through
+ // These traits require a complete type.
+ case UTT_IsFinal:
+
// These trait expressions are designed to help implement predicates in
// [meta.unary.prop] despite not being named the same. They are specified
// by both GCC and the Embarcadero C++ compiler, and require the complete
@@ -2775,6 +2778,10 @@
if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
return RD->isAbstract();
return false;
+ case UTT_IsFinal:
+ if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
+ return RD->hasAttr<FinalAttr>();
+ return false;
case UTT_IsSigned:
return T->isSignedIntegerType();
case UTT_IsUnsigned:
Modified: cfe/trunk/test/Lexer/has_feature_type_traits.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/has_feature_type_traits.cpp?rev=145775&r1=145774&r2=145775&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/has_feature_type_traits.cpp (original)
+++ cfe/trunk/test/Lexer/has_feature_type_traits.cpp Sat Dec 3 12:14:24 2011
@@ -70,6 +70,11 @@
#endif
// CHECK: int is_enum();
+#if __has_feature(is_final)
+int is_final();
+#endif
+// CHECK: int is_final();
+
#if __has_feature(is_pod)
int is_pod();
#endif
Modified: cfe/trunk/test/SemaCXX/type-traits.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/type-traits.cpp?rev=145775&r1=145774&r2=145775&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/type-traits.cpp (original)
+++ cfe/trunk/test/SemaCXX/type-traits.cpp Sat Dec 3 12:14:24 2011
@@ -235,6 +235,37 @@
{ int arr[F(__is_enum(HasAnonymousUnion))]; }
}
+struct FinalClass final {
+};
+
+template<typename T>
+struct PotentiallyFinal { };
+
+template<typename T>
+struct PotentiallyFinal<T*> final { };
+
+template<>
+struct PotentiallyFinal<int> final { };
+
+void is_final()
+{
+ { int arr[T(__is_final(FinalClass))]; }
+ { int arr[T(__is_final(PotentiallyFinal<float*>))]; }
+ { int arr[T(__is_final(PotentiallyFinal<int>))]; }
+
+ { int arr[F(__is_final(int))]; }
+ { int arr[F(__is_final(Union))]; }
+ { int arr[F(__is_final(Int))]; }
+ { int arr[F(__is_final(IntAr))]; }
+ { int arr[F(__is_final(UnionAr))]; }
+ { int arr[F(__is_final(Derives))]; }
+ { int arr[F(__is_final(ClassType))]; }
+ { int arr[F(__is_final(cvoid))]; }
+ { int arr[F(__is_final(IntArNB))]; }
+ { int arr[F(__is_final(HasAnonymousUnion))]; }
+ { int arr[F(__is_final(PotentiallyFinal<float>))]; }
+}
+
typedef HasVirt Polymorph;
struct InheritPolymorph : Polymorph {};
More information about the cfe-commits
mailing list