From: Douglas Gregor Date: Sat, 17 Jan 2009 02:55:50 +0000 (+0000) Subject: Warn about typedefs of enums without any declarator name. Fixes rdar://problem/6503878 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8158f692571ba5eaae19e086b76d19319ac503c5;p=clang Warn about typedefs of enums without any declarator name. Fixes rdar://problem/6503878 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62397 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 040e36b5c4..e1f0685d74 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -599,8 +599,8 @@ DIAG(err_expected_unqualified_id, ERROR, "expected unqualified-id") DIAG(err_no_declarators, ERROR, "declaration does not declare anything") -DIAG(ext_no_declarators, EXTENSION, - "typedef without a name is a Microsoft extension") +DIAG(warn_no_declarators, WARNING, + "typedef requires a name") DIAG(err_func_def_no_params, ERROR, "function definition does not declare parameters") DIAG(err_expected_lparen_after_type, ERROR, diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7346526265..82c8ea099d 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -741,9 +741,9 @@ Sema::DeclTy *Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) { // Permit typedefs without declarators as a Microsoft extension. if (!DS.isMissingDeclaratorOk()) { - if (getLangOptions().Microsoft && - DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { - Diag(DS.getSourceRange().getBegin(), diag::ext_no_declarators) + if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef && + Tag && isa(Tag)) { + Diag(DS.getSourceRange().getBegin(), diag::warn_no_declarators) << DS.getSourceRange(); return Tag; } diff --git a/test/Sema/enum.c b/test/Sema/enum.c index b42036dc02..ea66c27aef 100644 --- a/test/Sema/enum.c +++ b/test/Sema/enum.c @@ -63,3 +63,6 @@ void foo() { enum xpto; // expected-warning{{ISO C forbids forward references to 'enum' types}} enum xpto; // expected-warning{{ISO C forbids forward references to 'enum' types}} } + +// +typedef enum { X = 0 }; // expected-warning{{typedef requires a name}}