[cfe-commits] r124276 - in /cfe/trunk: include/clang/Sema/DeclSpec.h lib/Parse/ParseDecl.cpp lib/Parse/ParseExpr.cpp lib/Sema/DeclSpec.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaType.cpp test/CXX/dcl.decl/p4-0x.cpp
Douglas Gregor
dgregor at apple.com
Tue Jan 25 19:43:54 PST 2011
Author: dgregor
Date: Tue Jan 25 21:43:54 2011
New Revision: 124276
URL: http://llvm.org/viewvc/llvm-project?rev=124276&view=rev
Log:
Rvalue references for *this: parse ref-qualifiers.
Added:
cfe/trunk/test/CXX/dcl.decl/p4-0x.cpp (with props)
Modified:
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=124276&r1=124275&r2=124276&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Sema/DeclSpec.h Tue Jan 25 21:43:54 2011
@@ -898,6 +898,10 @@
/// contains the location of the ellipsis.
unsigned isVariadic : 1;
+ /// \brief Whether the ref-qualifier (if any) is an lvalue reference.
+ /// Otherwise, it's an rvalue reference.
+ unsigned RefQualifierIsLValueRef : 1;
+
/// The type qualifiers: const/volatile/restrict.
/// The qualifier bitmask values are the same as in QualType.
unsigned TypeQuals : 3;
@@ -922,6 +926,11 @@
/// the function has one.
unsigned NumExceptions;
+ /// \brief The location of the ref-qualifier, if any.
+ ///
+ /// If this is an invalid location, there is no ref-qualifier.
+ unsigned RefQualifierLoc;
+
/// ThrowLoc - When hasExceptionSpec is true, the location of the throw
/// keyword introducing the spec.
unsigned ThrowLoc;
@@ -970,6 +979,15 @@
SourceLocation getThrowLoc() const {
return SourceLocation::getFromRawEncoding(ThrowLoc);
}
+
+ /// \brief Retrieve the location of the ref-qualifier, if any.
+ SourceLocation getRefQualifierLoc() const {
+ return SourceLocation::getFromRawEncoding(RefQualifierLoc);
+ }
+
+ /// \brief Determine whether this function declaration contains a
+ /// ref-qualifier.
+ bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); }
};
struct BlockPointerTypeInfo : TypeInfoCommon {
@@ -1084,7 +1102,10 @@
bool hasProto, bool isVariadic,
SourceLocation EllipsisLoc,
ParamInfo *ArgInfo, unsigned NumArgs,
- unsigned TypeQuals, bool hasExceptionSpec,
+ unsigned TypeQuals,
+ bool RefQualifierIsLvalueRef,
+ SourceLocation RefQualifierLoc,
+ bool hasExceptionSpec,
SourceLocation ThrowLoc,
bool hasAnyExceptionSpec,
ParsedType *Exceptions,
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=124276&r1=124275&r2=124276&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Jan 25 21:43:54 2011
@@ -3064,8 +3064,8 @@
/// '=' assignment-expression
/// [GNU] declaration-specifiers abstract-declarator[opt] attributes
///
-/// For C++, after the parameter-list, it also parses "cv-qualifier-seq[opt]"
-/// and "exception-specification[opt]".
+/// For C++, after the parameter-list, it also parses "cv-qualifier-seq[opt]",
+/// C++0x "ref-qualifier[opt]" and "exception-specification[opt]".
///
void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
ParsedAttributes &attrs,
@@ -3085,6 +3085,8 @@
// cv-qualifier-seq[opt].
DeclSpec DS;
+ SourceLocation RefQualifierLoc;
+ bool RefQualifierIsLValueRef = true;
bool hasExceptionSpec = false;
SourceLocation ThrowLoc;
bool hasAnyExceptionSpec = false;
@@ -3097,6 +3099,16 @@
if (!DS.getSourceRange().getEnd().isInvalid())
EndLoc = DS.getSourceRange().getEnd();
+ // Parse ref-qualifier[opt]
+ if (Tok.is(tok::amp) || Tok.is(tok::ampamp)) {
+ if (!getLang().CPlusPlus0x)
+ Diag(Tok, diag::ext_rvalue_reference);
+
+ RefQualifierIsLValueRef = Tok.is(tok::amp);
+ RefQualifierLoc = ConsumeToken();
+ EndLoc = RefQualifierLoc;
+ }
+
// Parse exception-specification[opt].
if (Tok.is(tok::kw_throw)) {
hasExceptionSpec = true;
@@ -3121,6 +3133,8 @@
SourceLocation(),
/*arglist*/ 0, 0,
DS.getTypeQualifiers(),
+ RefQualifierIsLValueRef,
+ RefQualifierLoc,
hasExceptionSpec, ThrowLoc,
hasAnyExceptionSpec,
Exceptions.data(),
@@ -3320,6 +3334,8 @@
SourceLocation EndLoc = RParenLoc;
DeclSpec DS;
+ SourceLocation RefQualifierLoc;
+ bool RefQualifierIsLValueRef = true;
bool hasExceptionSpec = false;
SourceLocation ThrowLoc;
bool hasAnyExceptionSpec = false;
@@ -3334,6 +3350,16 @@
if (!DS.getSourceRange().getEnd().isInvalid())
EndLoc = DS.getSourceRange().getEnd();
+ // Parse ref-qualifier[opt]
+ if (Tok.is(tok::amp) || Tok.is(tok::ampamp)) {
+ if (!getLang().CPlusPlus0x)
+ Diag(Tok, diag::ext_rvalue_reference);
+
+ RefQualifierIsLValueRef = Tok.is(tok::amp);
+ RefQualifierLoc = ConsumeToken();
+ EndLoc = RefQualifierLoc;
+ }
+
// Parse exception-specification[opt].
if (Tok.is(tok::kw_throw)) {
hasExceptionSpec = true;
@@ -3362,6 +3388,8 @@
EllipsisLoc,
ParamInfo.data(), ParamInfo.size(),
DS.getTypeQualifiers(),
+ RefQualifierIsLValueRef,
+ RefQualifierLoc,
hasExceptionSpec, ThrowLoc,
hasAnyExceptionSpec,
Exceptions.data(),
@@ -3443,6 +3471,7 @@
SourceLocation(),
&ParamInfo[0], ParamInfo.size(),
/*TypeQuals*/0,
+ true, SourceLocation(),
/*exception*/false,
SourceLocation(), false, 0, 0, 0,
LParenLoc, RLoc, D),
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=124276&r1=124275&r2=124276&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Tue Jan 25 21:43:54 2011
@@ -1859,6 +1859,7 @@
true, false,
SourceLocation(),
0, 0, 0,
+ true, SourceLocation(),
false, SourceLocation(),
false, 0, 0, 0,
CaretLoc, CaretLoc,
Modified: cfe/trunk/lib/Sema/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/DeclSpec.cpp?rev=124276&r1=124275&r2=124276&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/DeclSpec.cpp (original)
+++ cfe/trunk/lib/Sema/DeclSpec.cpp Tue Jan 25 21:43:54 2011
@@ -52,6 +52,8 @@
ParamInfo *ArgInfo,
unsigned NumArgs,
unsigned TypeQuals,
+ bool RefQualifierIsLvalueRef,
+ SourceLocation RefQualifierLoc,
bool hasExceptionSpec,
SourceLocation ThrowLoc,
bool hasAnyExceptionSpec,
@@ -74,6 +76,8 @@
I.Fun.TypeQuals = TypeQuals;
I.Fun.NumArgs = NumArgs;
I.Fun.ArgInfo = 0;
+ I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef;
+ I.Fun.RefQualifierLoc = RefQualifierLoc.getRawEncoding();
I.Fun.hasExceptionSpec = hasExceptionSpec;
I.Fun.ThrowLoc = ThrowLoc.getRawEncoding();
I.Fun.hasAnyExceptionSpec = hasAnyExceptionSpec;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=124276&r1=124275&r2=124276&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jan 25 21:43:54 2011
@@ -5539,7 +5539,8 @@
Declarator D(DS, Declarator::BlockContext);
D.AddTypeInfo(DeclaratorChunk::getFunction(ParsedAttributes(),
false, false, SourceLocation(), 0,
- 0, 0, false, SourceLocation(),
+ 0, 0, true, SourceLocation(),
+ false, SourceLocation(),
false, 0,0,0, Loc, Loc, D),
SourceLocation());
D.SetIdentifier(&II, Loc);
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=124276&r1=124275&r2=124276&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Jan 25 21:43:54 2011
@@ -520,6 +520,7 @@
/*variadic*/ false, SourceLocation(),
/*args*/ 0, 0,
/*type quals*/ 0,
+ /*ref-qualifier*/true, SourceLocation(),
/*EH*/ false, SourceLocation(), false, 0, 0, 0,
/*parens*/ loc, loc,
declarator));
Added: cfe/trunk/test/CXX/dcl.decl/p4-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/p4-0x.cpp?rev=124276&view=auto
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/p4-0x.cpp (added)
+++ cfe/trunk/test/CXX/dcl.decl/p4-0x.cpp Tue Jan 25 21:43:54 2011
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
+
+struct X {
+ void f() &;
+ void g() &&;
+};
+
+void (X::*pmf)() & = &X::f;
Propchange: cfe/trunk/test/CXX/dcl.decl/p4-0x.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/CXX/dcl.decl/p4-0x.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/CXX/dcl.decl/p4-0x.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list