This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7b400f4a8d6: [clang][Interp] Fix ignoring 
SubstNonTypeTemplateParmExpr (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D149831?vs=519400&id=545960#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149831/new/

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
@@ -876,51 +876,62 @@
 }
 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 {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -476,6 +476,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
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to