[clang] c7b400f - [clang][Interp] Fix ignoring SubstNonTypeTemplateParmExpr
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 1 01:25:45 PDT 2023
Author: Timm Bäder
Date: 2023-08-01T10:25:16+02:00
New Revision: c7b400f4a8d6a0230f8479945820652b37db4d66
URL: https://github.com/llvm/llvm-project/commit/c7b400f4a8d6a0230f8479945820652b37db4d66
DIFF: https://github.com/llvm/llvm-project/commit/c7b400f4a8d6a0230f8479945820652b37db4d66.diff
LOG: [clang][Interp] Fix ignoring SubstNonTypeTemplateParmExpr
Ignore the expressions and re-do the tests without all the "result
ignored" expected warnings. Those are expected, given the nature of the
tests.
Differential Revision: https://reviews.llvm.org/D149831
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/literals.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 39dd42655436da..1508b0619a19ad 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -476,6 +476,8 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitSubstNonTypeTemplateParmExpr(
const SubstNonTypeTemplateParmExpr *E) {
+ if (DiscardResult)
+ return this->discard(E->getReplacement());
return this->visit(E->getReplacement());
}
diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp
index 6610770a884e21..9f31cd909e2938 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -876,51 +876,62 @@ constexpr int ignoredDecls() {
}
static_assert(ignoredDecls() == 12, "");
-struct A{ int a; };
-constexpr int ignoredExprs() {
- (void)(1 / 2);
- A a;
- a; // expected-warning {{unused}} \
- // ref-warning {{unused}}
- (void)a;
- (a); // expected-warning {{unused}} \
- // ref-warning {{unused}}
-
- (void)5, (void)6;
-
- 1 ? 0 : 1; // expected-warning {{unused}} \
- // ref-warning {{unused}}
- /// Ignored MaterializeTemporaryExpr.
- struct B{ const int &a; };
- (void)B{12};
- return 0;
-}
+namespace DiscardExprs {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-value"
+
+ struct A{ int a; };
+ constexpr int ignoredExprs() {
+ (void)(1 / 2);
+ A a;
+ a;
+ (void)a;
+ (a);
+
+ /// Ignored MaterializeTemporaryExpr.
+ struct B{ const int &a; };
+ (void)B{12};
+
+ (void)5, (void)6;
-/// Ignored comma expressions still have their
-/// expressions evaluated.
-constexpr int Comma(int start) {
- int i = start;
+ 1 ? 0 : 1;
+ return 0;
+ }
+
+ /// Ignored comma expressions still have their
+ /// expressions evaluated.
+ constexpr int Comma(int start) {
+ int i = start;
- (void)i++;
- (void)i++,(void)i++;
+ (void)i++;
+ (void)i++,(void)i++;
+ return i;
+ }
+ constexpr int Value = Comma(5);
+ static_assert(Value == 8, "");
+
+ /// Ignored MemberExprs need to still evaluate the Base
+ /// expr.
+ constexpr A callme(int &i) {
+ ++i;
+ return A{};
+ }
+ constexpr int ignoredMemberExpr() {
+ int i = 0;
+ callme(i).a;
return i;
+ }
+ static_assert(ignoredMemberExpr() == 1, "");
+
+ template <int I>
+ constexpr int foo() {
+ I;
+ return I;
+ }
+ static_assert(foo<3>() == 3, "");
+
+#pragma clang diagnostic pop
}
-constexpr int Value = Comma(5);
-static_assert(Value == 8, "");
-
-/// Ignored MemberExprs need to still evaluate the Base
-/// expr.
-constexpr A callme(int &i) {
- ++i;
- return A{};
-}
-constexpr int ignoredMemberExpr() {
- int i = 0;
- callme(i).a; // ref-warning {{result unused}} \
- // expected-warning {{result unused}}
- return i;
-}
-static_assert(ignoredMemberExpr() == 1, "");
#endif
namespace PredefinedExprs {
More information about the cfe-commits
mailing list