From: Richard Smith Date: Mon, 14 Jan 2013 01:55:13 +0000 (+0000) Subject: *this is const in a trailing-return-type for a constexpr member function. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b19cb116d0909de72dc8242b0a4e6c5ed39d421;p=clang *this is const in a trailing-return-type for a constexpr member function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172375 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index bd79e56b09..1fbe6b3a1a 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -4761,7 +4761,9 @@ void Parser::ParseFunctionDeclarator(Declarator &D, Actions.CurContext->isRecord())); Sema::CXXThisScopeRAII ThisScope(Actions, dyn_cast(Actions.CurContext), - DS.getTypeQualifiers(), + DS.getTypeQualifiers() | + (D.getDeclSpec().isConstexprSpecified() + ? Qualifiers::Const : 0), IsCXX11MemberFunction); // Parse exception-specification[opt]. diff --git a/test/Parser/cxx0x-decl.cpp b/test/Parser/cxx0x-decl.cpp index d74b337b31..1da7dd2833 100644 --- a/test/Parser/cxx0x-decl.cpp +++ b/test/Parser/cxx0x-decl.cpp @@ -41,3 +41,11 @@ struct SS { }; using PR14855 = int S::; // expected-error {{expected ';' after alias declaration}} + +// Ensure that 'this' has a const-qualified type in a trailing return type for +// a constexpr function. +struct ConstexprTrailingReturn { + int n; + constexpr auto f() -> decltype((n)); +}; +constexpr const int &ConstexprTrailingReturn::f() const { return n; }