diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 1ba1695800f543935d356728223b5afebaef6c4a..cb42a88e82bb7f1f44ad3134d8d035eaf96a2bac 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 593ec48b4394cdb7af1b6250bf40bcea50170bcb..a061cf4ddb7f742085b348b78c0063735909ff86 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<typename T> struct S {