Skip to content

Commit 74ce297

Browse files
committed
Revert "[Clang] Implement Change scope of lambda trailing-return-type"
This reverts commit d708a18 (and typo fix e4bc989). It causes a compilation error for this: ``` struct StringLiteral { template <int N> StringLiteral(const char (&array)[N]) __attribute__((enable_if(N > 0 && N == __builtin_strlen(array) + 1, "invalid string literal"))); }; struct Message { Message(StringLiteral); }; void Func1() { auto x = Message("x"); // Note: this is fine // Note: "xx\0" to force a different type, StringLiteral<3>, otherwise this // successfully builds. auto y = [&](decltype(Message("xx"))) {}; // ^ fails with: repro.cc:18:13: error: reference to local variable 'array' // declared in enclosing function 'StringLiteral::StringLiteral<3>' (void)x; (void)y; } ``` More details posted to D124351.
1 parent 256fa21 commit 74ce297

20 files changed

+460
-972
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ C++20 Feature Support
130130
C++2b Feature Support
131131
^^^^^^^^^^^^^^^^^^^^^
132132

133-
- Implemented `P2036R3: Change scope of lambda trailing-return-type <https://wg21.link/P2036R3>`_
134-
and `P2579R0 Mitigation strategies for P2036 <https://wg21.link/P2579R0>`_.
135-
These proposals modify how variables captured in lambdas can appear in trailing return type
136-
expressions and how their types are deduced therein, in all C++ language versions.
137-
138133
CUDA/HIP Language Changes in Clang
139134
----------------------------------
140135

clang/include/clang/AST/DeclCXX.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,11 +1092,6 @@ class CXXRecordDecl : public RecordDecl {
10921092

10931093
unsigned capture_size() const { return getLambdaData().NumCaptures; }
10941094

1095-
const LambdaCapture *getCapture(unsigned I) const {
1096-
assert(isLambda() && I < capture_size() && "invalid index for capture");
1097-
return captures_begin() + I;
1098-
}
1099-
11001095
using conversion_iterator = UnresolvedSetIterator;
11011096

11021097
conversion_iterator conversion_begin() const {
@@ -1831,20 +1826,6 @@ class CXXRecordDecl : public RecordDecl {
18311826
return getLambdaData().MethodTyInfo;
18321827
}
18331828

1834-
void setLambdaTypeInfo(TypeSourceInfo *TS) {
1835-
assert(DefinitionData && DefinitionData->IsLambda &&
1836-
"setting lambda property of non-lambda class");
1837-
auto &DL = static_cast<LambdaDefinitionData &>(*DefinitionData);
1838-
DL.MethodTyInfo = TS;
1839-
}
1840-
1841-
void setLambdaIsGeneric(bool IsGeneric) {
1842-
assert(DefinitionData && DefinitionData->IsLambda &&
1843-
"setting lambda property of non-lambda class");
1844-
auto &DL = static_cast<LambdaDefinitionData &>(*DefinitionData);
1845-
DL.IsGenericLambda = IsGeneric;
1846-
}
1847-
18481829
// Determine whether this type is an Interface Like type for
18491830
// __interface inheritance purposes.
18501831
bool isInterfaceLike() const;

clang/include/clang/Sema/Scope.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ class Scope {
145145
/// This is a scope of some OpenMP directive with
146146
/// order clause which specifies concurrent
147147
OpenMPOrderClauseScope = 0x4000000,
148-
/// This is the scope for a lambda, after the lambda introducer.
149-
/// Lambdas need two FunctionPrototypeScope scopes (because there is a
150-
/// template scope in between), the outer scope does not increase the
151-
/// depth of recursion.
152-
LambdaScope = 0x8000000,
153148
};
154149

155150
private:

clang/include/clang/Sema/ScopeInfo.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -838,11 +838,6 @@ class LambdaScopeInfo final :
838838
/// The lambda's compiler-generated \c operator().
839839
CXXMethodDecl *CallOperator = nullptr;
840840

841-
/// Indicate that we parsed the parameter list
842-
/// at which point the mutability of the lambda
843-
/// is known.
844-
bool AfterParameterList = true;
845-
846841
/// Source range covering the lambda introducer [...].
847842
SourceRange IntroducerRange;
848843

@@ -854,9 +849,8 @@ class LambdaScopeInfo final :
854849
/// explicit captures.
855850
unsigned NumExplicitCaptures = 0;
856851

857-
/// Whether this is a mutable lambda. Until the mutable keyword is parsed,
858-
/// we assume the lambda is mutable.
859-
bool Mutable = true;
852+
/// Whether this is a mutable lambda.
853+
bool Mutable = false;
860854

861855
/// Whether the (empty) parameter list is explicit.
862856
bool ExplicitParams = false;

clang/include/clang/Sema/Sema.h

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7103,21 +7103,15 @@ class Sema final {
71037103
std::nullopt);
71047104

71057105
/// Endow the lambda scope info with the relevant properties.
7106-
void buildLambdaScope(sema::LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator,
7106+
void buildLambdaScope(sema::LambdaScopeInfo *LSI,
7107+
CXXMethodDecl *CallOperator,
71077108
SourceRange IntroducerRange,
71087109
LambdaCaptureDefault CaptureDefault,
7109-
SourceLocation CaptureDefaultLoc, bool ExplicitParams,
7110+
SourceLocation CaptureDefaultLoc,
7111+
bool ExplicitParams,
7112+
bool ExplicitResultType,
71107113
bool Mutable);
71117114

7112-
CXXMethodDecl *CreateLambdaCallOperator(SourceRange IntroducerRange,
7113-
CXXRecordDecl *Class);
7114-
void CompleteLambdaCallOperator(
7115-
CXXMethodDecl *Method, SourceLocation LambdaLoc,
7116-
SourceLocation CallOperatorLoc, Expr *TrailingRequiresClause,
7117-
TypeSourceInfo *MethodTyInfo, ConstexprSpecKind ConstexprKind,
7118-
StorageClass SC, ArrayRef<ParmVarDecl *> Params,
7119-
bool HasExplicitResultType);
7120-
71217115
/// Perform initialization analysis of the init-capture and perform
71227116
/// any implicit conversions such as an lvalue-to-rvalue conversion if
71237117
/// not being used to initialize a reference.
@@ -7138,9 +7132,11 @@ class Sema final {
71387132
///
71397133
/// CodeGen handles emission of lambda captures, ignoring these dummy
71407134
/// variables appropriately.
7141-
VarDecl *createLambdaInitCaptureVarDecl(
7142-
SourceLocation Loc, QualType InitCaptureType, SourceLocation EllipsisLoc,
7143-
IdentifierInfo *Id, unsigned InitStyle, Expr *Init, DeclContext *DeclCtx);
7135+
VarDecl *createLambdaInitCaptureVarDecl(SourceLocation Loc,
7136+
QualType InitCaptureType,
7137+
SourceLocation EllipsisLoc,
7138+
IdentifierInfo *Id,
7139+
unsigned InitStyle, Expr *Init);
71447140

71457141
/// Add an init-capture to a lambda scope.
71467142
void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var,
@@ -7150,38 +7146,28 @@ class Sema final {
71507146
/// given lambda.
71517147
void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI);
71527148

7153-
/// Deduce a block or lambda's return type based on the return
7154-
/// statements present in the body.
7155-
void deduceClosureReturnType(sema::CapturingScopeInfo &CSI);
7156-
7157-
/// Once the Lambdas capture are known, we can start to create the closure,
7158-
/// call operator method, and keep track of the captures.
7159-
/// We do the capture lookup here, but they are not actually captured until
7160-
/// after we know what the qualifiers of the call operator are.
7161-
void ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
7162-
Scope *CurContext);
7163-
7164-
/// This is called after parsing the explicit template parameter list
7149+
/// \brief This is called after parsing the explicit template parameter list
71657150
/// on a lambda (if it exists) in C++2a.
7166-
void ActOnLambdaExplicitTemplateParameterList(LambdaIntroducer &Intro,
7167-
SourceLocation LAngleLoc,
7151+
void ActOnLambdaExplicitTemplateParameterList(SourceLocation LAngleLoc,
71687152
ArrayRef<NamedDecl *> TParams,
71697153
SourceLocation RAngleLoc,
71707154
ExprResult RequiresClause);
71717155

7172-
void ActOnLambdaClosureQualifiers(LambdaIntroducer &Intro,
7173-
SourceLocation MutableLoc);
7156+
/// Introduce the lambda parameters into scope.
7157+
void addLambdaParameters(
7158+
ArrayRef<LambdaIntroducer::LambdaCapture> Captures,
7159+
CXXMethodDecl *CallOperator, Scope *CurScope);
71747160

7175-
void ActOnLambdaClosureParameters(
7176-
Scope *LambdaScope,
7177-
MutableArrayRef<DeclaratorChunk::ParamInfo> ParamInfo);
7161+
/// Deduce a block or lambda's return type based on the return
7162+
/// statements present in the body.
7163+
void deduceClosureReturnType(sema::CapturingScopeInfo &CSI);
71787164

71797165
/// ActOnStartOfLambdaDefinition - This is called just before we start
71807166
/// parsing the body of a lambda; it analyzes the explicit captures and
71817167
/// arguments, and sets up various data-structures for the body of the
71827168
/// lambda.
71837169
void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
7184-
Declarator &ParamInfo, const DeclSpec &DS);
7170+
Declarator &ParamInfo, Scope *CurScope);
71857171

71867172
/// ActOnLambdaError - If there is an error parsing a lambda, this callback
71877173
/// is invoked to pop the information about the lambda.
@@ -7276,13 +7262,6 @@ class Sema final {
72767262
LocalInstantiationScope &Scope,
72777263
const MultiLevelTemplateArgumentList &TemplateArgs);
72787264

7279-
/// Introduce the instantiated captures of the lambda into the local
7280-
/// instantiation scope.
7281-
bool addInstantiatedCapturesToScope(
7282-
FunctionDecl *Function, const FunctionDecl *PatternDecl,
7283-
LocalInstantiationScope &Scope,
7284-
const MultiLevelTemplateArgumentList &TemplateArgs);
7285-
72867265
/// used by SetupConstraintCheckingTemplateArgumentsAndScope to recursively(in
72877266
/// the case of lambdas) set up the LocalInstantiationScope of the current
72887267
/// function.

0 commit comments

Comments
 (0)