tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Ignore the expressions and re-do the tests without all the "result
ignored" expected warnings. Those are expected, given the nature of the
tests.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149831
Files:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/literals.cpp
Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -857,49 +857,59 @@
}
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}}
-
- 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);
+
+ (void)5, (void)6;
+
+ 1 ? 0 : 1;
-/// Ignored comma expressions still have their
-/// expressions evaluated.
-constexpr int Comma(int start) {
- int i = start;
+ 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 {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -536,6 +536,8 @@
template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitSubstNonTypeTemplateParmExpr(
const SubstNonTypeTemplateParmExpr *E) {
+ if (DiscardResult)
+ return this->discard(E->getReplacement());
return this->visit(E->getReplacement());
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits