Sema: provide an extension warning for enable_if

Clang implements an enable_if attribute as an extension.  Hook up `-Wpedantic`
to issue an extension usage warning when __enable_if__ is used.

llvm-svn: 261192
This commit is contained in:
Saleem Abdulrasool 2016-02-18 06:49:31 +00:00
parent bc24cb5fb5
commit 046ba5b66f
3 changed files with 54 additions and 0 deletions

View 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<

View 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);

View File

@ -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