From 700b7e50f7a7ad3ed2448fae2ac146bba05402e2 Mon Sep 17 00:00:00 2001
From: Richard Smith <richard-llvm@metafoo.co.uk>
Date: Sat, 4 Oct 2014 01:57:39 +0000
Subject: [PATCH] PR20991: ::decltype is not valid.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219043 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Parse/ParseExprCXX.cpp | 3 ++-
 test/Parser/cxx0x-decl.cpp | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
index 8f22f5609e..47fdd826a5 100644
--- a/lib/Parse/ParseExprCXX.cpp
+++ b/lib/Parse/ParseExprCXX.cpp
@@ -242,7 +242,8 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
     *MayBePseudoDestructor = false;
   }
 
-  if (Tok.is(tok::kw_decltype) || Tok.is(tok::annot_decltype)) {
+  if (!HasScopeSpecifier &&
+      (Tok.is(tok::kw_decltype) || Tok.is(tok::annot_decltype))) {
     DeclSpec DS(AttrFactory);
     SourceLocation DeclLoc = Tok.getLocation();
     SourceLocation EndLoc  = ParseDecltypeSpecifier(DS);
diff --git a/test/Parser/cxx0x-decl.cpp b/test/Parser/cxx0x-decl.cpp
index 2cd6825213..994104fc9d 100644
--- a/test/Parser/cxx0x-decl.cpp
+++ b/test/Parser/cxx0x-decl.cpp
@@ -116,6 +116,11 @@ namespace DuplicateSpecifier {
   };
 }
 
+namespace ColonColonDecltype {
+  struct S { struct T {}; };
+  ::decltype(S())::T invalid; // expected-error {{expected unqualified-id}}
+}
+
 struct Base { virtual void f() = 0; virtual void g() = 0; virtual void h() = 0; };
 struct MemberComponentOrder : Base {
   void f() override __asm__("foobar") __attribute__(( )) {}
-- 
2.40.0