[cfe-commits] r155163 - in /cfe/trunk: lib/Parse/ParseTentative.cpp test/FixIt/fixit.cpp
Kaelyn Uhrain
rikka at google.com
Thu Apr 19 17:34:33 PDT 2012
On Thu, Apr 19, 2012 at 4:54 PM, David Blaikie <dblaikie at gmail.com> wrote:
> On Thu, Apr 19, 2012 at 4:17 PM, Kaelyn Uhrain <rikka at google.com> wrote:
> > Author: rikka
> > Date: Thu Apr 19 18:17:45 2012
> > New Revision: 155163
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=155163&view=rev
> > Log:
> > In Parser::isCXXDeclarationSpecifier, consider a non-type identifier
> > followed by an identifier as declaration specificer (except for ObjC).
> > This allows e.g. an out-of-line C++ member function definitions to be
> > recognized as functions and not as variable declarations if the type
> > name for the first parameter is not recognized as a type--say, when there
> > is a function name shadowing an enum type name and the parameter is
> > missing the "enum" keyword needed to distinguish the two.
> >
> > Note that returning TPResult::Error() instead of TPResult::True()
> > appears to have the same end result, while TPResult::Ambiguous()
> > results in a crash.
> >
> > Modified:
> > cfe/trunk/lib/Parse/ParseTentative.cpp
> > cfe/trunk/test/FixIt/fixit.cpp
> >
> > Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=155163&r1=155162&r2=155163&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
> > +++ cfe/trunk/lib/Parse/ParseTentative.cpp Thu Apr 19 18:17:45 2012
> > @@ -931,8 +931,12 @@
> > // recurse to handle whatever we get.
> > if (TryAnnotateTypeOrScopeToken())
> > return TPResult::Error();
> > - if (Tok.is(tok::identifier))
> > - return TPResult::False();
> > + if (Tok.is(tok::identifier)) {
> > + const Token &Next = NextToken();
> > + bool NotObjC = !(getLangOpts().ObjC1 || getLangOpts().ObjC2);
> > + return (NotObjC && Next.is(tok::identifier)) ?
> > + TPResult::True() : TPResult::False();
> > + }
> > return isCXXDeclarationSpecifier(BracedCastResult);
> >
> > case tok::coloncolon: { // ::foo::bar
> >
> > Modified: cfe/trunk/test/FixIt/fixit.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit.cpp?rev=155163&r1=155162&r2=155163&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/test/FixIt/fixit.cpp (original)
> > +++ cfe/trunk/test/FixIt/fixit.cpp Thu Apr 19 18:17:45 2012
> > @@ -204,3 +204,15 @@
> > template<typename> typename Bar, // expected-error {{template
> template parameter requires 'class' after the parameter list}}
> > template<typename> struct Baz> // expected-error {{template
> template parameter requires 'class' after the parameter list}}
> > void func();
> > +
> > +
> > +namespace ShadowedTagType {
> > +class Foo {
> > + public:
> > + enum Bar { X, Y };
> > + void SetBar(Bar bar);
> > + Bar Bar();
> > + private:
> > + Bar bar_; // expected-error {{must use 'enum' tag to refer to type
> 'Bar' in this scope}}
> > +};
> > +void Foo::SetBar(Bar bar) { bar_ = bar; } // expected-error {{must use
> 'enum' tag to refer to type 'Bar' in this scope}}
>
> I assume "void Foo::SetBar(Bar) { }" still confuses clang into
> thinking this is a variable definition?
>
That is correct, since it is a bit harder to detect (especially if the
return type is not void or if there is more than one parameter).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120419/4581ab9b/attachment.html>
More information about the cfe-commits
mailing list