]> granicus.if.org Git - clang/commitdiff
Template instantiation for __builtin_types_compatible_p.
authorDouglas Gregor <dgregor@apple.com>
Tue, 19 May 2009 20:55:31 +0000 (20:55 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 19 May 2009 20:55:31 +0000 (20:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72134 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/Sema/SemaTemplateInstantiateExpr.cpp
test/SemaTemplate/instantiate-expr-3.cpp

index 0c5f63b5099d35c56d9458fa6a855021b3115cc7..5692ec880c7a8345080484a6cda68964c2a82ac4 100644 (file)
@@ -1616,7 +1616,7 @@ public:
   virtual child_iterator child_end();
 };
 
-/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
+/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p.
 /// This AST node represents a function that returns 1 if two *types* (not
 /// expressions) are compatible. The result of this built-in function can be
 /// used in integer constant expressions.
index 7cf403c282ad69dd8f23e4b68269904afc99c75f..fde31102340b88ad45259193604450fb16d5ff68 100644 (file)
@@ -56,6 +56,7 @@ namespace {
     OwningExprResult VisitConditionalOperator(ConditionalOperator *E);
     // FIXME: AddrLabelExpr
     OwningExprResult VisitStmtExpr(StmtExpr *E);
+    OwningExprResult VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
     OwningExprResult VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
     OwningExprResult VisitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *E);
     OwningExprResult VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
@@ -465,6 +466,26 @@ Sema::OwningExprResult TemplateExprInstantiator::VisitStmtExpr(StmtExpr *E) {
                                E->getRParenLoc());
 }
 
+Sema::OwningExprResult 
+TemplateExprInstantiator::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
+  QualType Type1 = SemaRef.InstantiateType(E->getArgType1(), TemplateArgs,
+                                           /*FIXME:*/ E->getBuiltinLoc(),
+                                           DeclarationName());
+  if (Type1.isNull())
+    return SemaRef.ExprError();
+
+  QualType Type2 = SemaRef.InstantiateType(E->getArgType2(), TemplateArgs,
+                                           /*FIXME:*/ E->getBuiltinLoc(),
+                                           DeclarationName());
+  if (Type2.isNull())
+    return SemaRef.ExprError();
+
+  return SemaRef.ActOnTypesCompatibleExpr(E->getBuiltinLoc(),
+                                          Type1.getAsOpaquePtr(),
+                                          Type2.getAsOpaquePtr(),
+                                          E->getRParenLoc());
+}
+
 Sema::OwningExprResult 
 TemplateExprInstantiator::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
   bool isSizeOf = E->isSizeOf();
index d098f27860c0b277730dd57610b27cd7fbad00bc..bc1097c5aa826640fef749fdb5e2363e5ea64061 100644 (file)
@@ -69,3 +69,15 @@ struct StatementExpr0 {
 
 template struct StatementExpr0<int>;
 template struct StatementExpr0<N1::X>; // expected-note{{instantiation}}
+
+// ---------------------------------------------------------------------
+// __builtin_types_compatible_p
+// ---------------------------------------------------------------------
+template<typename T, typename U, bool Result>
+struct TypesCompatible0 {
+  void f() {
+    int a[__builtin_types_compatible_p(T, U) == Result? 1 : -1];
+  }
+};
+
+template struct TypesCompatible0<int, const int, true>;