diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index f31212e54035..4a6437d34fdb 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -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">; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 3f99c684b892..bb85455ddca9 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -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)); } diff --git a/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp b/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp index 5e91ada66d54..ca19a3d32f17 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateExpr.cpp @@ -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/clang/test/SemaCXX/types_compatible_p.cpp b/clang/test/SemaCXX/types_compatible_p.cpp new file mode 100644 index 000000000000..30b16006c685 --- /dev/null +++ b/clang/test/SemaCXX/types_compatible_p.cpp @@ -0,0 +1,5 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +bool f() { + return __builtin_types_compatible_p(int, const int); // expected-error{{C++}} +} diff --git a/clang/test/SemaTemplate/instantiate-expr-3.cpp b/clang/test/SemaTemplate/instantiate-expr-3.cpp index a17897b085ca..abc2d92c6d78 100644 --- a/clang/test/SemaTemplate/instantiate-expr-3.cpp +++ b/clang/test/SemaTemplate/instantiate-expr-3.cpp @@ -70,18 +70,6 @@ struct StatementExpr0 { template struct StatementExpr0; template struct StatementExpr0; // expected-note{{instantiation}} -// --------------------------------------------------------------------- -// __builtin_types_compatible_p -// --------------------------------------------------------------------- -template -struct TypesCompatible0 { - void f() { - int a[__builtin_types_compatible_p(T, U) == Result? 1 : -1]; - } -}; - -template struct TypesCompatible0; - // --------------------------------------------------------------------- // __builtin_shufflevector // ---------------------------------------------------------------------