[PATCH] D115228: [Clang] Do not check if we are in a discared context in non-immediate contexts
Corentin Jabot via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 7 02:27:04 PST 2021
cor3ntin created this revision.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This fixes in a regression introduced by 6eeda06c1 <https://reviews.llvm.org/rG6eeda06c1d22da2b9fe96a2569a8a0f8e4f36880>.
When deducing the return type of nested function calls, only the
return type of the outermost expression should be ignored.
Instead of assuming all contextes nested in a discared statements
are themselves discarded, only assume that in immediate contexts.
Similarly, only consider contextes immediately in an immediate or
discarded statement as being themselves immediate.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D115228
Files:
clang/include/clang/Sema/Sema.h
clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
Index: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
===================================================================
--- clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -159,4 +159,19 @@
surprise: {}
}
}
+
+namespace deduced_return_type_in_discareded_statement {
+
+ template <typename T>
+ auto a(const T& t) {
+ return t;
+ }
+
+ void f() {
+ if constexpr (false) {
+ a(a(0));
+ }
+ }
+}
+
#endif
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1324,12 +1324,12 @@
bool isImmediateFunctionContext() const {
return Context == ExpressionEvaluationContext::ImmediateFunctionContext ||
- InImmediateFunctionContext;
+ (Context == ExpressionEvaluationContext::DiscardedStatement && InImmediateFunctionContext);
}
bool isDiscardedStatementContext() const {
- return Context == ExpressionEvaluationContext::DiscardedStatement ||
- InDiscardedStatement;
+ return Context == ExpressionEvaluationContext::DiscardedStatement ||
+ (Context == ExpressionEvaluationContext::ImmediateFunctionContext && InDiscardedStatement);
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115228.392318.patch
Type: text/x-patch
Size: 1360 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211207/d739d254/attachment.bin>
More information about the cfe-commits
mailing list