From 8edef7c31d27fc9d5d163660702a8a7730a0d19f Mon Sep 17 00:00:00 2001 From: Sebastian Redl Date: Sat, 24 Jan 2009 23:29:36 +0000 Subject: [PATCH] Make tentative parsing of pointer-to-member decls work, and fix other stuff pointed out by Doug. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62944 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTContext.cpp | 5 +++-- lib/AST/Type.cpp | 2 ++ lib/Parse/ParseTentative.cpp | 10 +++++++--- test/SemaCXX/member-pointer.cpp | 5 +++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 63e4ccc241..2662860af2 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -400,10 +400,11 @@ ASTContext::getTypeInfo(const Type *T) { // pointer size. return getTypeInfo(cast(T)->getPointeeType()); case Type::MemberPointer: { - // Note that this is not only platform- but also ABI-dependent. We follow + // FIXME: This is not only platform- but also ABI-dependent. We follow // the GCC ABI, where pointers to data are one pointer large, pointers to // functions two pointers. But if we want to support ABI compatibility with - // other compilers too, we need to delegate this completely to TargetInfo. + // other compilers too, we need to delegate this completely to TargetInfo + // or some ABI abstraction layer. QualType Pointee = cast(T)->getPointeeType(); unsigned AS = Pointee.getAddressSpace(); Width = Target.getPointerWidth(AS); diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index ebaa011355..7d9be2d72c 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -324,6 +324,8 @@ bool Type::isVariablyModifiedType() const { // correctly. if (const PointerLikeType *PT = getAsPointerLikeType()) return PT->getPointeeType()->isVariablyModifiedType(); + if (const MemberPointerType *PT = getAsMemberPointerType()) + return PT->getPointeeType()->isVariablyModifiedType(); // A function can return a variably modified type // This one isn't completely obvious, but it follows from the diff --git a/lib/Parse/ParseTentative.cpp b/lib/Parse/ParseTentative.cpp index a7c3e38931..e7914cccea 100644 --- a/lib/Parse/ParseTentative.cpp +++ b/lib/Parse/ParseTentative.cpp @@ -357,7 +357,7 @@ bool Parser::isCXXTypeIdInParens() { /// '*' cv-qualifier-seq[opt] /// '&' /// [C++0x] '&&' [TODO] -/// '::'[opt] nested-name-specifier '*' cv-qualifier-seq[opt] [TODO] +/// '::'[opt] nested-name-specifier '*' cv-qualifier-seq[opt] /// /// cv-qualifier-seq: /// cv-qualifier cv-qualifier-seq[opt] @@ -387,8 +387,12 @@ Parser::TPResult Parser::TryParseDeclarator(bool mayBeAbstract, // ptr-operator declarator while (1) { - if (Tok.is(tok::star) || Tok.is(tok::amp) || - (Tok.is(tok::caret) && getLang().Blocks)) { + if (Tok.is(tok::coloncolon) || Tok.is(tok::identifier)) + TryAnnotateCXXScopeToken(); + + if (Tok.is(tok::star) || Tok.is(tok::amp) || + (Tok.is(tok::caret) && getLang().Blocks) || + (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::star))) { // ptr-operator ConsumeToken(); while (Tok.is(tok::kw_const) || diff --git a/test/SemaCXX/member-pointer.cpp b/test/SemaCXX/member-pointer.cpp index dcf70b2681..2568cb59d8 100644 --- a/test/SemaCXX/member-pointer.cpp +++ b/test/SemaCXX/member-pointer.cpp @@ -12,3 +12,8 @@ int B::*pbi; // expected-error {{expected a class or namespace}} int C::*pci; // expected-error {{'pci' does not point into a class}} void A::*pdv; // expected-error {{'pdv' declared as a member pointer to void}} int& A::*pdr; // expected-error {{'pdr' declared as a pointer to a reference}} + +void f() { + // This requires tentative parsing. + int (A::*pf)(int, int); +} -- 2.50.1