]> granicus.if.org Git - clang/commitdiff
Sema: provide an extension warning for enable_if
authorSaleem Abdulrasool <compnerd@compnerd.org>
Thu, 18 Feb 2016 06:49:31 +0000 (06:49 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Thu, 18 Feb 2016 06:49:31 +0000 (06:49 +0000)
Clang implements an enable_if attribute as an extension.  Hook up `-Wpedantic`
to issue an extension usage warning when __enable_if__ is used.

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

include/clang/Basic/DiagnosticCommonKinds.td
lib/Sema/SemaDeclAttr.cpp
test/Sema/enable_if-ext.c [new file with mode: 0644]

index ccc271a69f912e335004d4f9521b97f7e1150cd7..837fc6126e8622734e717171fdcc731190807307 100644 (file)
@@ -157,6 +157,8 @@ def ext_old_implicitly_unsigned_long_cxx : ExtWarn<
   "this literal will %select{have type 'long long'|be ill-formed}0 "
   "in C++11 onwards">,
   InGroup<CXX11Compat>;
+def ext_clang_enable_if : Extension<"'enable_if' is a clang extension">,
+                          InGroup<GccCompat>;
 
 // SEH
 def err_seh_expected_handler : Error<
index bfb82ac1388100c6ee305f6568fcbf3f11e96514..d2db4b92849925896e56981bae57e171345be7da 100644 (file)
@@ -804,6 +804,8 @@ static void handleLocksExcludedAttr(Sema &S, Decl *D,
 }
 
 static void handleEnableIfAttr(Sema &S, Decl *D, const AttributeList &Attr) {
+  S.Diag(Attr.getLoc(), diag::ext_clang_enable_if);
+
   Expr *Cond = Attr.getArgAsExpr(0);
   if (!Cond->isTypeDependent()) {
     ExprResult Converted = S.PerformContextuallyConvertToBool(Cond);
diff --git a/test/Sema/enable_if-ext.c b/test/Sema/enable_if-ext.c
new file mode 100644 (file)
index 0000000..1e605d4
--- /dev/null
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only %s -include %s -verify
+// RUN: %clang_cc1 -Wpedantic -fsyntax-only %s -include %s -verify -DWARN_PEDANTIC
+
+#ifndef enable_if_ext_included
+#define enable_if_ext_included
+
+#if !defined(WARN_PEDANTIC)
+// expected-no-diagnostics
+#endif
+
+__attribute__ (( enable_if(1, "") ))
+#if defined(WARN_PEDANTIC)
+// expected-warning@-2 {{'enable_if' is a clang extension}}
+#endif
+void f() { }
+
+__attribute__ (( __enable_if__(1, "") ))
+#if defined(WARN_PEDANTIC)
+// expected-warning@-2 {{'enable_if' is a clang extension}}
+#endif
+void g() { }
+
+__attribute__ (( enable_if(0, "") ))
+#if defined(WARN_PEDANTIC)
+// expected-warning@-2 {{'enable_if' is a clang extension}}
+#endif
+void h() { }
+
+__attribute__ (( __enable_if__(0, "") ))
+#if defined(WARN_PEDANTIC)
+// expected-warning@-2 {{'enable_if' is a clang extension}}
+#endif
+void i() { }
+
+#pragma clang system_header
+
+__attribute__ (( enable_if(1, "") ))
+void j() { }
+
+__attribute__ (( __enable_if__(1, "") ))
+void k() { }
+
+__attribute__ (( enable_if(0, "") ))
+void l() { }
+
+__attribute__ (( __enable_if__(0, "") ))
+void m() { }
+
+#endif
+