From: Kaelyn Uhrain Date: Mon, 16 Dec 2013 19:19:13 +0000 (+0000) Subject: Maybe add new warning for shadowing simple tag types X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fed1c6f1e753551a3c21cd50447e3b25c7fba04c;p=clang Maybe add new warning for shadowing simple tag types git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197408 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 807389cb02..82b10ed138 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -3662,6 +3662,10 @@ def err_redefinition_different_type : Error< "redefinition of %0 with a different type%diff{: $ vs $|}1,2">; def err_redefinition_different_kind : Error< "redefinition of %0 as different kind of symbol">; +def warn_declaration_shadows_tag_type : Warning< + "declaration of %0 shadows %1 %0; '%1' tag will be needed to refer to the %1">, + InGroup, DefaultIgnore; +def note_shadowed_tag_type_declaration : Note<"%1 %0 declared here">; def warn_forward_class_redefinition : Warning< "redefinition of forward class %0 of a typedef name of an object type is ignored">, InGroup>; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 6eb8955dbc..c4325c6d70 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4398,8 +4398,14 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D, // tag type. Note that this does does not apply if we're declaring a // typedef (C++ [dcl.typedef]p4). if (Previous.isSingleTagDecl() && - D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef) + D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef) { + TagDecl *TD = Previous.getAsSingle(); + Diag(D.getIdentifierLoc(), diag::warn_declaration_shadows_tag_type) + << Name << TD->getKindName(); + Diag(TD->getLocation(), diag::note_shadowed_tag_type_declaration) + << Name << TD->getKindName(); Previous.clear(); + } // Check that there are no default arguments other than in the parameters // of a function declaration (C++ only).