]> granicus.if.org Git - clang/commitdiff
Ban the use of __builtin_types_compatible_p in C++; g++ doesn't support it,
authorDouglas Gregor <dgregor@apple.com>
Tue, 19 May 2009 22:28:02 +0000 (22:28 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 19 May 2009 22:28:02 +0000 (22:28 +0000)
and it isn't clear exactly what it's supposed to mean. Thanks Eli!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72142 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
lib/Sema/SemaTemplateInstantiateExpr.cpp
test/SemaCXX/types_compatible_p.cpp [new file with mode: 0644]
test/SemaTemplate/instantiate-expr-3.cpp

index f31212e54035023002b37bf68c7f6687e9a82f0b..4a6437d34fdbf30f0d6bda359d754820dc41c189 100644 (file)
@@ -110,6 +110,8 @@ def err_implicit_decl_requires_stdio : Error<
 def warn_redecl_library_builtin : Warning<
   "incompatible redeclaration of library function %0">;
 def err_builtin_definition : Error<"definition of builtin function %0">;
+def err_types_compatible_p_in_cplusplus : Error<
+  "__builtin_types_compatible_p is not valid in C++">;
 
 /// parser diagnostics
 def ext_typedef_without_a_name : ExtWarn<"typedef requires a name">;
index 3f99c684b8921925d851c5792a05b8be05810d67..bb85455ddca9f26520ee41921db729fb077ae527 100644 (file)
@@ -5022,6 +5022,12 @@ Sema::OwningExprResult Sema::ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
 
   assert((!argT1.isNull() && !argT2.isNull()) && "Missing type argument(s)");
 
+  if (getLangOptions().CPlusPlus) {
+    Diag(BuiltinLoc, diag::err_types_compatible_p_in_cplusplus)
+      << SourceRange(BuiltinLoc, RPLoc);
+    return ExprError();
+  }
+
   return Owned(new (Context) TypesCompatibleExpr(Context.IntTy, BuiltinLoc,
                                                  argT1, argT2, RPLoc));
 }
index 5e91ada66d547313b52a1c1211674c2dd25648dd..ca19a3d32f17027d70cd8288af1e86f7489238bc 100644 (file)
@@ -469,22 +469,8 @@ Sema::OwningExprResult TemplateExprInstantiator::VisitStmtExpr(StmtExpr *E) {
 
 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());
+  assert(false && "__builtin_types_compatible_p is not legal in C++");
+  return SemaRef.ExprError();
 }
 
 Sema::OwningExprResult 
diff --git a/test/SemaCXX/types_compatible_p.cpp b/test/SemaCXX/types_compatible_p.cpp
new file mode 100644 (file)
index 0000000..30b1600
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+bool f() {
+  return __builtin_types_compatible_p(int, const int); // expected-error{{C++}}
+}
index a17897b085ca7ee2f5159803150155614f8bc9cf..abc2d92c6d787fe47c6257b9faac9163ec39c126 100644 (file)
@@ -70,18 +70,6 @@ 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>;
-
 // ---------------------------------------------------------------------
 // __builtin_shufflevector
 // ---------------------------------------------------------------------