[clang] Suppress noreturn warning if last statement in a function is a throw (PR #145166)

Samarth Narang via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 27 07:20:33 PDT 2025


================
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wreturn-type -verify %s
+// expected-no-diagnostics
+
+namespace std {
+  class string {
+  public:
+    string(const char*); // constructor for runtime_error
+  };
+  class runtime_error {
+  public:
+    runtime_error(const string &); 
+  };
+}
+
+void throwError(const std::string& msg) {
+  throw std::runtime_error(msg);
+}
+
+int ensureZero(const int i) {
+  if (i == 0) return 0;
+  throwError("ERROR"); // no-warning
+}
+
+int alwaysThrows() {
----------------
snarang181 wrote:

Added a template-based test.

https://github.com/llvm/llvm-project/pull/145166


More information about the cfe-commits mailing list