[cfe-commits] r155677 - in /cfe/trunk: include/clang/Basic/DiagnosticCommonKinds.td lib/Parse/ParseDecl.cpp lib/Sema/SemaDecl.cpp test/FixIt/fixit.cpp test/Parser/cxx-using-declaration.cpp
David Blaikie
dblaikie at gmail.com
Thu Apr 26 16:54:59 PDT 2012
On Thu, Apr 26, 2012 at 4:36 PM, Kaelyn Uhrain <rikka at google.com> wrote:
> Author: rikka
> Date: Thu Apr 26 18:36:17 2012
> New Revision: 155677
>
> URL: http://llvm.org/viewvc/llvm-project?rev=155677&view=rev
> Log:
> Add note to help explain why a tag such as 'struct' is needed to refer
> to a given type, when the reason is that there is a non-type decl with
> the same name.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
> cfe/trunk/lib/Parse/ParseDecl.cpp
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/FixIt/fixit.cpp
> cfe/trunk/test/Parser/cxx-using-declaration.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=155677&r1=155676&r2=155677&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Thu Apr 26 18:36:17 2012
> @@ -74,6 +74,8 @@
> def warn_module_build : Warning<"building module '%0' from source">,
> InGroup<ModuleBuild>, DefaultIgnore;
> def note_pragma_entered_here : Note<"#pragma entered here">;
> +def note_decl_shadowing_tag_type : Note<
> + "non-type %0 shadowing %1 %0 declared here">;
>
> // Sema && Lex
> def ext_longlong : Extension<
>
> Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=155677&r1=155676&r2=155677&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Apr 26 18:36:17 2012
> @@ -14,6 +14,7 @@
> #include "clang/Parse/Parser.h"
> #include "clang/Parse/ParseDiagnostic.h"
> #include "clang/Basic/OpenCL.h"
> +#include "clang/Sema/Lookup.h"
> #include "clang/Sema/Scope.h"
> #include "clang/Sema/ParsedTemplate.h"
> #include "clang/Sema/PrettyDeclStackTrace.h"
> @@ -1671,9 +1672,20 @@
> }
>
> if (TagName) {
> + IdentifierInfo *TokenName = Tok.getIdentifierInfo();
> + LookupResult R(Actions, TokenName, SourceLocation(),
> + Sema::LookupOrdinaryName);
> +
> Diag(Loc, diag::err_use_of_tag_name_without_tag)
> - << Tok.getIdentifierInfo() << TagName << getLangOpts().CPlusPlus
> - << FixItHint::CreateInsertion(Tok.getLocation(),FixitTagName);
> + << TokenName << TagName << getLangOpts().CPlusPlus
> + << FixItHint::CreateInsertion(Tok.getLocation(), FixitTagName);
> +
> + if (Actions.LookupParsedName(R, getCurScope(), SS)) {
> + for (LookupResult::iterator I = R.begin(), IEnd = R.end();
> + I != IEnd; ++I)
> + Diag((*I)->getLocation(), diag::note_decl_shadowing_tag_type)
> + << TokenName << TagName;
> + }
>
> // Parse this as a tag as if the missing tag were present.
> if (TagKind == tok::kw_enum)
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=155677&r1=155676&r2=155677&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Apr 26 18:36:17 2012
> @@ -564,6 +564,14 @@
> Diag(NameLoc, diag::err_use_of_tag_name_without_tag)
> << Name << TagName << getLangOpts().CPlusPlus
> << FixItHint::CreateInsertion(NameLoc, FixItTagName);
> +
> + LookupResult R(*this, Name, NameLoc, LookupOrdinaryName);
> + if (LookupParsedName(R, S, &SS)) {
> + for (LookupResult::iterator I = R.begin(), IEnd = R.end();
> + I != IEnd; ++I)
> + Diag((*I)->getLocation(), diag::note_decl_shadowing_tag_type)
> + << Name << TagName;
> + }
> break;
> }
>
>
> Modified: cfe/trunk/test/FixIt/fixit.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit.cpp?rev=155677&r1=155676&r2=155677&view=diff
> ==============================================================================
> --- cfe/trunk/test/FixIt/fixit.cpp (original)
> +++ cfe/trunk/test/FixIt/fixit.cpp Thu Apr 26 18:36:17 2012
> @@ -211,7 +211,7 @@
> public:
> enum Bar { X, Y };
> void SetBar(Bar bar);
> - Bar Bar();
> + Bar Bar(); // expected-note 2 {{non-type 'Bar' shadowing enum 'Bar' declared here}}
> private:
> Bar bar_; // expected-error {{must use 'enum' tag to refer to type 'Bar' in this scope}}
> };
>
> Modified: cfe/trunk/test/Parser/cxx-using-declaration.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-using-declaration.cpp?rev=155677&r1=155676&r2=155677&view=diff
> ==============================================================================
> --- cfe/trunk/test/Parser/cxx-using-declaration.cpp (original)
> +++ cfe/trunk/test/Parser/cxx-using-declaration.cpp Thu Apr 26 18:36:17 2012
> @@ -43,3 +43,19 @@
> // Should have some errors here. Waiting for implementation.
> void X(int);
> struct X *x;
> +
> +
> +namespace ShadowedTagNotes {
> +
> +namespace foo {
> + class Bar {};
> +}
> +
> +void Bar(int); // expected-note{{non-type 'Bar' shadowing class 'Bar' declared here}}
To me this sort of reads strangely - "non-type 'Bar' shadowing (class
'Bar' declared here)" rather than "non-type 'Bar' shadowing (class
'Bar') declared here" - but perhaps I'm being pedantic. "class 'Bar'
shadows non-type 'Bar' declared here" feels more clear to me, but does
still suffer from the same ambiguity...
- David
> +using foo::Bar;
> +
> +void ambiguity() {
> + const Bar *x; // expected-error{{must use 'class' tag to refer to type 'Bar' in this scope}}
> +}
> +
> +} // namespace ShadowedTagNotes
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list