Skip to content

Commit

Permalink
[clang][Interp] Fix ignoring SubstNonTypeTemplateParmExpr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tbaederr committed Aug 1, 2023
1 parent 6081f56 commit c7b400f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 41 deletions.
2 changes: 2 additions & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
93 changes: 52 additions & 41 deletions clang/test/AST/Interp/literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c7b400f

Please sign in to comment.