From bb6cfd425256f3d1fef0874834820784dc67a852 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 8 Feb 2017 19:58:48 +0000 Subject: [PATCH] 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 '::'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@294506 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseExprCXX.cpp | 5 ++++- test/SemaCXX/cxx1y-deduced-return-type.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 1ba1695800..cb42a88e82 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -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; } diff --git a/test/SemaCXX/cxx1y-deduced-return-type.cpp b/test/SemaCXX/cxx1y-deduced-return-type.cpp index 593ec48b43..a061cf4ddb 100644 --- a/test/SemaCXX/cxx1y-deduced-return-type.cpp +++ b/test/SemaCXX/cxx1y-deduced-return-type.cpp @@ -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 struct S { -- 2.40.0