From: Alp Toker Date: Wed, 25 Dec 2013 01:47:02 +0000 (+0000) Subject: Don't reserve __builtin_types_compatible_p as a C++ keyword X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a693f7de5d45c718ae9b82310d456c51bcda2422;p=clang Don't reserve __builtin_types_compatible_p as a C++ keyword Even g++ considers this a valid C++ identifier and it should only have been visible in C mode. Also drop the associated low-value diagnostic. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197995 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 3a3c93da12..71d118a2be 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -367,8 +367,6 @@ def warn_redecl_library_builtin : Warning< "incompatible redeclaration of library function %0">, InGroup>; 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++">; def warn_builtin_unknown : Warning<"use of unknown builtin %0">, InGroup, DefaultError; def warn_dyn_class_memaccess : Warning< diff --git a/include/clang/Basic/TokenKinds.def b/include/clang/Basic/TokenKinds.def index a76d86bb2c..54f7853648 100644 --- a/include/clang/Basic/TokenKinds.def +++ b/include/clang/Basic/TokenKinds.def @@ -348,7 +348,7 @@ KEYWORD(__builtin_choose_expr , KEYALL) KEYWORD(__builtin_offsetof , KEYALL) // __builtin_types_compatible_p is a GNU C extension that we handle like a C++ // type trait. -TYPE_TRAIT_2(__builtin_types_compatible_p, TypeCompatible, KEYALL) +TYPE_TRAIT_2(__builtin_types_compatible_p, TypeCompatible, KEYNOCXX) KEYWORD(__builtin_va_arg , KEYALL) KEYWORD(__extension__ , KEYALL) KEYWORD(__imag , KEYALL) diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index a0c123fdaa..2591dbfede 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -3707,16 +3707,7 @@ static bool evaluateTypeTrait(Sema &S, TypeTrait Kind, SourceLocation KWLoc, ExprResult Sema::BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef Args, SourceLocation RParenLoc) { - QualType ResultType = Context.BoolTy; - // __builtin_types_compatible_p is a GNU C extension, not a C++ type trait. - if (Kind == BTT_TypeCompatible) { - ResultType = Context.IntTy; - if (getLangOpts().CPlusPlus) { - Diag(KWLoc, diag::err_types_compatible_p_in_cplusplus) - << SourceRange(KWLoc, RParenLoc); - return ExprError(); - } - } + QualType ResultType = Context.getLogicalOperationType(); bool Dependent = false; for (unsigned I = 0, N = Args.size(); I != N; ++I) { diff --git a/test/SemaCXX/types_compatible_p.cpp b/test/SemaCXX/types_compatible_p.cpp index 4aa9a1cfa9..ebff53f7c0 100644 --- a/test/SemaCXX/types_compatible_p.cpp +++ b/test/SemaCXX/types_compatible_p.cpp @@ -1,5 +1,8 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -x c++ %s +// RUN: %clang_cc1 -fsyntax-only -x c %s -bool f() { - return __builtin_types_compatible_p(int, const int); // expected-error{{C++}} +// Test that GNU C extension __builtin_types_compatible_p() is not available in C++ mode. + +int f() { + return __builtin_types_compatible_p(int, const int); // expected-error{{}} }