r294506 - Don't crash on 'decltype(auto)::'. Rather than treating it as a meaningless

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 8 11:58:48 PST 2017


Author: rsmith
Date: Wed Feb  8 13:58:48 2017
New Revision: 294506

URL: http://llvm.org/viewvc/llvm-project?rev=294506&view=rev
Log:
Don't crash on 'decltype(auto)::'. Rather than treating it as a meaningless
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 '::'.

Modified:
    cfe/trunk/lib/Parse/ParseExprCXX.cpp
    cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=294506&r1=294505&r2=294506&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Wed Feb  8 13:58:48 2017
@@ -216,7 +216,10 @@ bool Parser::ParseOptionalCXXScopeSpecif
     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;
     }

Modified: cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp?rev=294506&r1=294505&r2=294506&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp Wed Feb  8 13:58:48 2017
@@ -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 {




More information about the cfe-commits mailing list