r197995 - Don't reserve __builtin_types_compatible_p as a C++ keyword

Alp Toker alp at nuanti.com
Tue Dec 24 17:47:02 PST 2013


Author: alp
Date: Tue Dec 24 19:47:02 2013
New Revision: 197995

URL: http://llvm.org/viewvc/llvm-project?rev=197995&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/include/clang/Basic/TokenKinds.def
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaCXX/types_compatible_p.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=197995&r1=197994&r2=197995&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Dec 24 19:47:02 2013
@@ -367,8 +367,6 @@ def warn_redecl_library_builtin : Warnin
   "incompatible redeclaration of library function %0">,
   InGroup<DiagGroup<"incompatible-library-redeclaration">>;
 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<ImplicitFunctionDeclare>, DefaultError;
 def warn_dyn_class_memaccess : Warning<

Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=197995&r1=197994&r2=197995&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Tue Dec 24 19:47:02 2013
@@ -348,7 +348,7 @@ KEYWORD(__builtin_choose_expr       , KE
 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)

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=197995&r1=197994&r2=197995&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Dec 24 19:47:02 2013
@@ -3707,16 +3707,7 @@ static bool evaluateTypeTrait(Sema &S, T
 ExprResult Sema::BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, 
                                 ArrayRef<TypeSourceInfo *> 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) {

Modified: cfe/trunk/test/SemaCXX/types_compatible_p.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/types_compatible_p.cpp?rev=197995&r1=197994&r2=197995&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/types_compatible_p.cpp (original)
+++ cfe/trunk/test/SemaCXX/types_compatible_p.cpp Tue Dec 24 19:47:02 2013
@@ -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{{}}
 }





More information about the cfe-commits mailing list