[cfe-commits] r67495 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseDecl.cpp test/Parser/cxx-reference.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Sun Mar 22 17:00:23 PDT 2009
Author: cornedbee
Date: Sun Mar 22 19:00:23 2009
New Revision: 67495
URL: http://llvm.org/viewvc/llvm-project?rev=67495&view=rev
Log:
Recognize rvalue references in C++03, but complain about them. This leads to far better error recovery.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/test/Parser/cxx-reference.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=67495&r1=67494&r2=67495&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Sun Mar 22 19:00:23 2009
@@ -121,6 +121,8 @@
"'%0' qualifier may not be applied to a reference">;
def err_illegal_decl_reference_to_reference : Error<
"%0 declared as a reference to a reference">;
+def err_rvalue_reference : Error<
+ "rvalue references are only allowed in C++0x">;
def err_argument_required_after_attribute : Error<
"argument required after attribute">;
def err_missing_param : Error<"expected parameter declarator">;
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=67495&r1=67494&r2=67495&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sun Mar 22 19:00:23 2009
@@ -1660,7 +1660,8 @@
tok::TokenKind Kind = Tok.getKind();
// Not a pointer, C++ reference, or block.
if (Kind != tok::star && (Kind != tok::amp || !getLang().CPlusPlus) &&
- (Kind != tok::ampamp || !getLang().CPlusPlus0x) &&
+ // We parse rvalue refs in C++03, because otherwise the errors are scary.
+ (Kind != tok::ampamp || !getLang().CPlusPlus) &&
(Kind != tok::caret || !getLang().Blocks)) {
if (DirectDeclParser)
(this->*DirectDeclParser)(D);
@@ -1669,7 +1670,7 @@
// Otherwise, '*' -> pointer, '^' -> block, '&' -> lvalue reference,
// '&&' -> rvalue reference
- SourceLocation Loc = ConsumeToken(); // Eat the *, ^ or &.
+ SourceLocation Loc = ConsumeToken(); // Eat the *, ^, & or &&.
D.SetRangeEnd(Loc);
if (Kind == tok::star || (Kind == tok::caret && getLang().Blocks)) {
@@ -1695,6 +1696,11 @@
// Is a reference
DeclSpec DS;
+ // Complain about rvalue references in C++03, but then go on and build
+ // the declarator.
+ if (Kind == tok::ampamp && !getLang().CPlusPlus0x)
+ Diag(Loc, diag::err_rvalue_reference);
+
// C++ 8.3.2p1: cv-qualified references are ill-formed except when the
// cv-qualifiers are introduced through the use of a typedef or of a
// template type argument, in which case the cv-qualifiers are ignored.
Modified: cfe/trunk/test/Parser/cxx-reference.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-reference.cpp?rev=67495&r1=67494&r2=67495&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-reference.cpp (original)
+++ cfe/trunk/test/Parser/cxx-reference.cpp Sun Mar 22 19:00:23 2009
@@ -17,3 +17,5 @@
int & volatile Y = val; // expected-error {{'volatile' qualifier may not be applied to a reference}}
int & const volatile Z = val; /* expected-error {{'const' qualifier may not be applied}} \
expected-error {{'volatile' qualifier may not be applied}} */
+
+typedef int && RV; // expected-error {{rvalue references are only allowed in C++0x}}
More information about the cfe-commits
mailing list