From 0bba2d11d08e7cf6c9e475cb6736395a10a95872 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 18 Jan 2013 18:41:42 +0000 Subject: [PATCH] Fix parsing of class specifiers before '\n' 'operator'. r159549 / r159164 regressed clang to reject struct s {}; struct s operator++(struct s a) { return a; } This fixes the regression. Richard, pleas check if this looks right. llvm-svn: 172834 --- clang/lib/Parse/ParseDeclCXX.cpp | 1 + clang/test/Parser/cxx-decl.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index cc3318501aea..9aa3a8b2afcf 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -964,6 +964,7 @@ bool Parser::isValidAfterTypeSpecifier(bool CouldBeBitfield) { case tok::annot_template_id: // struct foo {...} a ::b; case tok::l_paren: // struct foo {...} ( x); case tok::comma: // __builtin_offsetof(struct foo{...} , + case tok::kw_operator: // struct foo operator++() {...} return true; case tok::colon: return CouldBeBitfield; // enum E { ... } : 2; diff --git a/clang/test/Parser/cxx-decl.cpp b/clang/test/Parser/cxx-decl.cpp index 5a4c9da0f602..aa775c8c7627 100644 --- a/clang/test/Parser/cxx-decl.cpp +++ b/clang/test/Parser/cxx-decl.cpp @@ -132,6 +132,24 @@ struct S { typedef S() : n(1), m(2) { } // expected-error {{function definition declared 'typedef'}} }; + +namespace TestIsValidAfterTypeSpecifier { +struct s {}; + +namespace a { +struct s operator++(struct s a) +{ return a; } +} + +namespace b { +// The newline after s should make no difference. +struct s +operator++(struct s a) +{ return a; } +} + +} + // PR8380 extern "" // expected-error {{unknown linkage language}} test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} \