]> granicus.if.org Git - clang/commitdiff
Don't crash on 'decltype(auto)::'. Rather than treating it as a meaningless
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 8 Feb 2017 19:58:48 +0000 (19:58 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 8 Feb 2017 19:58:48 +0000 (19:58 +0000)
nested-name-specifier (as the standard appears to require), treat it as the
type specifier 'decltype(auto)' followed by a nested-name-specifier starting
with '::'.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@294506 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExprCXX.cpp
test/SemaCXX/cxx1y-deduced-return-type.cpp

index 1ba1695800f543935d356728223b5afebaef6c4a..cb42a88e82bb7f1f44ad3134d8d035eaf96a2bac 100644 (file)
@@ -216,7 +216,10 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
     SourceLocation EndLoc  = ParseDecltypeSpecifier(DS);
 
     SourceLocation CCLoc;
-    if (!TryConsumeToken(tok::coloncolon, CCLoc)) {
+    // Work around a standard defect: 'decltype(auto)::' is not a
+    // nested-name-specifier.
+    if (DS.getTypeSpecType() == DeclSpec::TST_decltype_auto ||
+        !TryConsumeToken(tok::coloncolon, CCLoc)) {
       AnnotateExistingDecltypeSpecifier(DS, DeclLoc, EndLoc);
       return false;
     }
index 593ec48b4394cdb7af1b6250bf40bcea50170bcb..a061cf4ddb7f742085b348b78c0063735909ff86 100644 (file)
@@ -385,6 +385,18 @@ namespace MemberTemplatesWithDeduction {
 }
 }
 
+namespace NNS {
+  int n;
+  decltype(auto) i();
+  decltype(n) j();
+  struct X {
+    // We resolve a wording bug here: 'decltype(auto)::' should not be parsed
+    // as a nested-name-specifier.
+    friend decltype(auto) ::NNS::i();
+    friend decltype(n) ::NNS::j(); // expected-error {{not a class}}
+  };
+}
+
 namespace CurrentInstantiation {
   // PR16875
   template<typename T> struct S {